ncurses 与 panel

一下是ncurses使用面板库panel的一个demo程序。

#include <ncurses.h>
#include <panel.h>
#include <string.h> void init_wins(WINDOW **wins, int n);
void win_show(WINDOW *win, char *label, int label_color);
void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color); int main()
{
WINDOW *my_wins[3];
PANEL *my_panels[3];
PANEL *top;
int ch;
int new_x;
int new_y;
int widht;
int height;
int panel_c;
enum {
set_size,
move_,
none_
} status = none_; /*初始化curses */
initscr();
start_color();
raw();
noecho();
keypad(stdscr, TRUE);
curs_set(0); /* 初始化所有的颜色*/
init_pair(1, COLOR_RED, COLOR_WHITE);
init_pair(2, COLOR_GREEN, COLOR_BLACK);
init_pair(3, COLOR_BLUE, COLOR_BLACK);
init_pair(4, COLOR_CYAN, COLOR_BLACK);
init_wins(my_wins, 3); my_panels[0] = new_panel(my_wins[0]);
my_panels[1] = new_panel(my_wins[1]);
my_panels[2] = new_panel(my_wins[2]); set_panel_userptr(my_panels[0],my_panels[1]);
set_panel_userptr(my_panels[1],my_panels[2]);
set_panel_userptr(my_panels[2],my_panels[0]); update_panels();
attron(COLOR_PAIR(4));
attroff(COLOR_PAIR(4));
doupdate(); top = my_panels[2];
panel_c = 2;
mvprintw(LINES-2, 0, "Use tab to browse through the windows (F1 to Exit) [%d]", panel_c + 1);
while((ch = getch()) != KEY_F(1))
{
switch(ch) {
case '\t':
if (status == none_) {
bool is_hide;
top = (PANEL *) panel_userptr(top);
is_hide = panel_hidden(top);
if (panel_c == 2)
panel_c = 0;
else
panel_c ++;
mvprintw(LINES-2, 0, "Use tab to browse through the windows (F1 to Exit) [%d]", panel_c + 1);
if (is_hide)
printw(" [hide] ");
else {
top_panel(top);
printw(" [show] ");
}
}
break;
case 'm': {
WINDOW *win = panel_window(top);
getbegyx(win, new_y, new_x);
status = move_;
mvprintw(LINES-2, 0, "Moveing Windows (ENTER to Exit) [%d] ", panel_c + 1);
break;
}
case 'r': {
WINDOW *win = panel_window(top);
getbegyx(win, new_y, new_x);
getmaxyx(win, height, widht);
status = set_size;
mvprintw(LINES-2, 0, "Set Windows Size (ENTER to Exit) [%d] %d %d ", panel_c + 1, height, widht);
break;
}
case 's':
if (status == none_)
show_panel(top);
break;
case 'h':
if (status == none_) {
if (panel_hidden(top))
show_panel(top);
else
hide_panel(top);
}
break;
case KEY_RIGHT:
if (status == move_)
new_x ++;
else
widht ++;
break;
case KEY_LEFT:
if (status == move_)
new_x --;
else
widht --;
break;
case KEY_UP:
if (status == move_)
new_y --;
else
height --;
break;
case KEY_DOWN:
if (status == move_)
new_y ++;
else
height ++;
break;
case 10:
status = none_;
mvprintw(LINES-2, 0, "Use tab to browse through the windows (F1 to Exit) [%d]\n", panel_c + 1);
break;
default:
mvprintw(LINES-3, 0, "ch = %d\n", ch);
break;
}
if (status == move_)
move_panel(top, new_y, new_x);
else if (status == set_size) {
char label[80] = {};
WINDOW *old = panel_window(top);
WINDOW *win = newwin(height, widht, new_y, new_x);
replace_panel(my_panels[panel_c], win);
delwin(old); sprintf(label, "Window Number %d", panel_c + 1);
win_show(win, label, panel_c + 1);
}
update_panels();
doupdate();
}
endwin();
return 0;
} // 初始化三个窗体并放入数组wins中
void init_wins(WINDOW *wins[], int n) {
char label[80] = {};
int x = 10;
int y = 2; for(int i = 0; i < n; i++) {
wins[i] = newwin(10, 40, y, x);
sprintf(label, "Window Number %d", i + 1); // 设置窗体名字
win_show(wins[i], label, i + 1); // 绘制窗体内的内容
y += 3;
x += 7;
}
} void win_show(WINDOW *win, char *label, int label_color) {
int startx;
int starty;
int height;
int width; getbegyx(win, starty, startx);
getmaxyx(win, height, width);
box(win, 0, 0);
mvwhline(win, 2, 1, '-', width-2); // 画一条线
print_in_middle(win, 1, 0, width, label, COLOR_PAIR(label_color)); // 在中间显示文字
} void print_in_middle(WINDOW *win, int y, int startx, int width, char *string, chtype color) {
int x; if(win == NULL)
win = stdscr;
if(y == 0)
getyx(win, y, x);
x = startx + (width - strlen(string)) / 2; wattron(win, color);
mvwprintw(win, y, x, "%s", string);
wattroff(win, color);
refresh();
}

tab切换窗体,按m改变窗体位置,按r设定窗体大小。按h显示或隐藏窗体。

ncurses 与 panel的更多相关文章

  1. 从头开始构建LINUX [LFS 脚本]

    脚本共享在这 http://pan.baidu.com/s/1nt6yiH7 version-check.sh : 这个是检查HOST机器的软件依赖情况 host-dep.sh:针对ubuntu10_ ...

  2. [原]打造Python开发环境之Python环境

    人生苦短,我用Python 一.升级到python2.7 开发环境的系统是centos 6.0, 默认的python版本是2.6.6, 由于线上环境是python2.7,为了防止版本差异产生的问题,所 ...

  3. 重新安装python

    1. 在上次进行安装python的时候,很多东西不能用,例如后退键,删除键,都是不能在命令行中使用,主要原因是在编译python的时候,相关的安装包没有进行安装,从而导致出现乱码,在编译最新版本的py ...

  4. LFS7.4编译笔记(2)

    上一篇我们已经搭建好了临时系统,这一篇我们就开始正式构建我们的最终LFS系统. 首先切换到root,准备虚拟内核文件系统并挂载: su - export LFS=/mnt/lfs mkdir -pv ...

  5. CentOS6下编译安装Python2.7.6方法

    关于在CentOS6下编译安装Python2.7.6的方法非常的多了,小编以前也介绍过相关的文章了,下面一聚教程小编再来为各位介绍一下吧,希望文章能帮助到各位.   CentOS下面Python在升级 ...

  6. 2、CentOS下编译安装Python2.7.6(转)

    CentOS系统下面Python在升级到2.7.6的时候,没有找到安装包直接安装,只能通过源代码编译的方式来安装Python 2.7.6版本.这篇是编译和安装Python2.7.6的过程记录. Cen ...

  7. Python编译安装遇到的问题

    1.python在make时候报错 Python build finished, but the necessary bits to build these modules were not foun ...

  8. lfs(systemd版本)学习笔记-第3页

    我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! lfs(systemd)学习笔记-第2页 的地址:https://www.cnblogs.com/renren-study-no ...

  9. lfs(systemv版本)学习笔记-第3页

    我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! lfs(systemv版本)学习笔记-第2页的地址:https://www.cnblogs.com/renren-study-n ...

  10. 从零开始构建Linux

    目的:深入了解以Linux内核为基础的系统是如何组成,运行,以构建一个最基础的,纯净的系统. LFS构建步骤宿主机准备- linux操作系统安装- 使用独立硬盘,创建分区- 配置用户和组- 下载所有需 ...

随机推荐

  1. Python 潮流周刊#21:如何提升及测量 Python 代码的性能?

    你好,我是猫哥.这里每周分享优质的 Python.AI 及通用技术内容,大部分为英文.标题取自其中三则分享,不代表全部内容都是该主题,特此声明. 本周刊由 Python猫 出品,精心筛选国内外的 25 ...

  2. Oracle的差异增量备份和累积增量备份

    在rman增量备份中,有差异增量和累积增量的概念. 差异增量:是备份上级及同级备份以来所有变化的数据块,差异增量是默认增量备份方式累积增量:是备份上级备份以来所有变化的块 累积增量是备份上级备份以来所 ...

  3. Batch Normalization 批量归一化的运算过程

    Batch Normalization 批量归一化 具体的运算过程: 假设经过卷积计算过后得到的feature map的尺寸为 2*3*2*2. 其中2代表的是batch的大小,3代表的是通道chan ...

  4. 唱衰这么多年,PHP 仍然还是你大爷!

    PHP 是个庞然大物. 尽管有人不断宣称 PHP "即将消亡". 但无法改变的事实是:互联网依然大量依赖 PHP.本文将通过大量的数据和事实告诉你为何 PHP 仍然在统治着互联网, ...

  5. 使用Docker buildx 为 .NET 构建多平台镜像

    .NET 团队有一篇博客 改进多平台容器支持, 详细介绍了.NET 7 以上的平台可以轻松的使用Docker buildx 工具构建多平台的镜像. buildx 是 Docker 官方提供的一个构建工 ...

  6. MMKV源码解读与理解

    概述 通过 mmap 技术实现的高性能通用 key-value 组件.同时选用 protobuf 协议,进一步压缩数据存储. 标准 protobuf 不提供增量更新的能力,每次写入都必须全量写入.考虑 ...

  7. QMainWindow无法显示,使用show()不显示窗口(QT)

    当使用 MainWindow w: w.show(); 不显示窗口时 变更为: MainWindow *w=new MainWindow(); w->show();

  8. BFF层提升业务性能实际解决方案,以及nodeJs和KOA框架介绍

    本文干货满满,介绍了用BFF层(Back-end For Front-end)中间层提升性能的整体解决方案和思路,涉及前期技术调研,聚合业务分析,聚合方法,验收,最后向同学们普及node.koa基础知 ...

  9. 搓一个Pythonic list

      总所周知,Python语言当中的list是可以存储不同类型的元素的,对应到现代C++当中,可以用std::variant或者std::any实现类似的功能.而Python官方的实现当中用到了二级指 ...

  10. 如何优雅使用 vuex

    大纲 本文内容更多的是讲讲使用 vuex 的一些心得想法,所以大概会讲述下面这些点: Q1:我为什么会想使用 vuex 来管理数据状态交互? Q2:使用 vuex 框架有哪些缺点或者说副作用? Q3: ...