ncurses 与 panel
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的更多相关文章
- 从头开始构建LINUX [LFS 脚本]
脚本共享在这 http://pan.baidu.com/s/1nt6yiH7 version-check.sh : 这个是检查HOST机器的软件依赖情况 host-dep.sh:针对ubuntu10_ ...
- [原]打造Python开发环境之Python环境
人生苦短,我用Python 一.升级到python2.7 开发环境的系统是centos 6.0, 默认的python版本是2.6.6, 由于线上环境是python2.7,为了防止版本差异产生的问题,所 ...
- 重新安装python
1. 在上次进行安装python的时候,很多东西不能用,例如后退键,删除键,都是不能在命令行中使用,主要原因是在编译python的时候,相关的安装包没有进行安装,从而导致出现乱码,在编译最新版本的py ...
- LFS7.4编译笔记(2)
上一篇我们已经搭建好了临时系统,这一篇我们就开始正式构建我们的最终LFS系统. 首先切换到root,准备虚拟内核文件系统并挂载: su - export LFS=/mnt/lfs mkdir -pv ...
- CentOS6下编译安装Python2.7.6方法
关于在CentOS6下编译安装Python2.7.6的方法非常的多了,小编以前也介绍过相关的文章了,下面一聚教程小编再来为各位介绍一下吧,希望文章能帮助到各位. CentOS下面Python在升级 ...
- 2、CentOS下编译安装Python2.7.6(转)
CentOS系统下面Python在升级到2.7.6的时候,没有找到安装包直接安装,只能通过源代码编译的方式来安装Python 2.7.6版本.这篇是编译和安装Python2.7.6的过程记录. Cen ...
- Python编译安装遇到的问题
1.python在make时候报错 Python build finished, but the necessary bits to build these modules were not foun ...
- lfs(systemd版本)学习笔记-第3页
我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! lfs(systemd)学习笔记-第2页 的地址:https://www.cnblogs.com/renren-study-no ...
- lfs(systemv版本)学习笔记-第3页
我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! lfs(systemv版本)学习笔记-第2页的地址:https://www.cnblogs.com/renren-study-n ...
- 从零开始构建Linux
目的:深入了解以Linux内核为基础的系统是如何组成,运行,以构建一个最基础的,纯净的系统. LFS构建步骤宿主机准备- linux操作系统安装- 使用独立硬盘,创建分区- 配置用户和组- 下载所有需 ...
随机推荐
- Solution -「洛谷 P4451」「国家集训队」整数的 lqp 拆分
Description Link. 求 \[\sum\prod_{i=1}^{m}F_{a_{i}},(m>0,a_{1},\cdots a_{m}>0,\sum a_{i}=n) \] ...
- Eclipse OSGI配置文件说明
- Java笔记(细碎小知识点)1
1.Dos命令:dir:打出当前目录结构:md:创建文件夹:cd+文件夹地址:跳转到当前目录下的对应文件夹:cd..:跳转到上一目录:rd+文件夹:删除文件夹中东西:del+文件(或 "*. ...
- 教学法学期末考试MOOC01
期末考试 返回 期末考试试卷为客观题,总分为100分,占课程成绩的40%.其中包含16道单选题,2道多选题.共18道题.单选题每道5分,多选题每道10分,限时90分钟完成. 倒计时: 01:13:4 ...
- 导出所有容器id号
#!/bin/bash a=`docker ps|awk 'NR>1{print $1}'` FORMAT="%-12s\t,\t%-12s\t,\t%-12s\n" pri ...
- OpenCv4.6.0交叉编译ARM(aarch64)平台库
1.下载交叉编译工具:gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu 2.opencv官网下载opencv4.6.0源码,opencv官网下载ope ...
- 动态规划的状态设计 | bot 讲课の补题
sto james1badcreeper orz. 好厉害的题,但是怎么有人补了三天才补完呢? CF1810G The Maximum Prefix 线性 dp,怎么有 bot 说题目难度在 *240 ...
- selenium 知网爬虫之根据【关键词】获取文献信息
哈喽大家好,我是咸鱼 之前咸鱼写过几篇关于知网爬虫的文章,后台反响都很不错.虽然但是,咸鱼还是忍不住想诉苦一下 有些小伙伴文章甚至代码看都没看完,就问我 "为什么只能爬这么多条文献信息?&q ...
- Linux-管道、环境变量、常用命令
目录 管道 概念 要点 与文件重定向的区别 环境变量 概念 查看 常用命令 查看系统状况 权限 文件查找 用户相关 工具 管道 概念 管道的作用类似于文件重定向,可以将前一个命令的stout做为下一个 ...
- Docker从了解到部署应用的详细教程
一.Docker基础知识 1.Docker (1)Docker可以让开发者打包他们的应用以及依赖包到一个轻量级.可以移植的容器中,然后发布到任何的linux机器上,可以实现虚拟化: (2)Docker ...