当前位置: 首页 > wzjs >正文

网站建设主机耗电量wordpress百度云对象存储

网站建设主机耗电量,wordpress百度云对象存储,温州网站建设排名,平台推广员简介 ncurses 是一个功能强大的库,用于在 Unix-like 系统中创建文本用户界面。它提供了丰富的函数来控制屏幕上的文本显示、处理键盘输入、绘制图形元素等。本文将详细介绍 ncurses 库中的一些基础函数,包括 printw、wrefresh、获取用户信息、键盘输入、…

简介

ncurses 是一个功能强大的库,用于在 Unix-like 系统中创建文本用户界面。它提供了丰富的函数来控制屏幕上的文本显示、处理键盘输入、绘制图形元素等。本文将详细介绍 ncurses 库中的一些基础函数,包括 printwwrefresh、获取用户信息、键盘输入、绘制图形元素以及获取终端信息等。

初始化和清理

在使用 ncurses 函数之前,需要初始化 ncurses 环境,并在程序结束时清理环境。

#include <ncurses.h>int main() {initscr();          // 初始化 ncurses 环境// ... 其他代码 ...endwin();          // 结束 ncurses 环境return 0;
}

printw 函数

printw 函数用于在当前光标位置打印文本。如果需要在特定位置打印文本,可以使用 mvprintw 函数。

printw("This is some text");  // 在当前光标位置打印文本
mvprintw(5, 10, "This is on row 5, column 10");  // 在第5行第10列打印文本

wrefresh 函数

wrefresh 函数用于将窗口的内容刷新到屏幕上。在 ncurses 中,所有输出都是先写入缓冲区,然后通过调用 wrefresh 将缓冲区的内容显示到屏幕上。

WINDOW *win;
win = newwin(10, 20, 5, 5);  // 创建一个窗口
wprintw(win, "Hello World");  // 在窗口中打印文本
wrefresh(win);  // 刷新窗口,显示文本

获取用户信息和键盘输入

getch 函数用于获取用户的键盘输入。

int ch = getch();  // 获取用户按键的 ASCII 码

绘制图形元素

box 函数用于在窗口中绘制一个矩形边框,mvprintw 可以在矩形内打印文本。

box(win, 0, 0);  // 在窗口中绘制边框
wprintw(win, 1, 1, "This is inside the box");  // 在边框内打印文本
wrefresh(win);  // 刷新窗口,显示内容

获取终端信息

getyxgetbegyxgetmaxyx 函数分别用于获取当前光标位置、窗口的起始坐标和最大坐标。

int y, x, yBeg, xBeg, yMax, xMax;
getyx(stdscr, y, x);  // 获取光标位置
getbegyx(stdscr, yBeg, xBeg);  // 获取窗口起始坐标
getmaxyx(stdscr, yMax, xMax);  // 获取窗口最大坐标

文本颜色和属性

ncurses 支持文本颜色和属性。attronattroff 函数用于设置文本属性,如加粗、反色等。

attron(COLOR_PAIR(1) | A_BOLD, NULL, NULL);  // 设置文本颜色和加粗
printw("This is bold and colored");  // 打印文本
attroff(COLOR_PAIR(1) | A_BOLD, NULL, NULL);  // 关闭文本属性

wattronncurses 库中的一个函数,用于打开(启用)窗口(WINDOW)的文本属性。ncurses 提供了多种文本属性,可以改变文本的外观,例如颜色、是否加粗、是否反色显示等。

函数原型如下:

int wattron(WINDOW *win, attr_t attr, void *opt);
  • win:指定要设置属性的窗口。

  • attr:指定要启用的属性。

  • opt:指定颜色对(如果设置了颜色属性)。

例如,以下代码片段启用了窗口中文本的反色属性:

WINDOW *mywin;
mywin = newwin(10, 20, 5, 5);  // 创建一个窗口
wattron(mywin, A_REVERSE);  // 启用反色属性
printw(mywin, "This text is highlighted");
wrefresh(mywin);  // 刷新窗口以显示更改

 

wattron 函数通常与 wattroff 函数一起使用,以便在需要时关闭(禁用)特定的文本属性。例如:

wattroff(mywin, A_REVERSE);  // 关闭反色属性

ncurses 库提供了多种属性,包括:

  • A_STANDOUT:文本加粗。

  • A_BLINK:文本闪烁。

  • A_DIM:文本变暗。

  • A_BOLD:文本加粗。

  • A_PROTECT:文本有边框保护。

  • A_INVIS:文本可被覆盖。

  • A_ALTCHARSET:使用备用字符集。

  • A_CHARTEXT:文本有额外属性。

 

#include <ncurses.h>
#include <string.h>int main()
{initscr();noecho();cbreak();int yMax, xMax;getmaxyx(stdscr, yMax, xMax); // get the maximum y and x coordinates of the screenWINDOW *menuwin = newwin(6, xMax - 12, yMax - 8, 5); // create a new window for the menuwinbox(menuwin, 0, 0);                                  // draw a box around the menurefresh();                                           // refresh the screen to show the changeswrefresh(menuwin);                                   // refresh the menu window// makes it so we can use arrow keyskeypad(menuwin, true);char choices[][20] = {"walk", "jog", "run"}; // array of strings for the menu choicesint choice;                                  // variable to store the user/s choiceint highlight = 0;                           // variable to track the highlight menu choicewhile (1) // main loop to handle user input{for (int i = 0; i < 3; i++) // loop through each menu choice{if (i == highlight)                       // if the current choice is highlightedwattron(menuwin, A_REVERSE);          // turn on reverse video attributemvwprintw(menuwin, i + 1, 1, choices[i]); // print the menu choicewattroff(menuwin, A_REVERSE);             // get the user's choice from the menu window}choice = wgetch(menuwin); // get the user's choice from the menu windowswitch (choice) // switch based on the user's choice{case KEY_UP:highlight--;if (highlight = -1)highlight = 0;break;case KEY_DOWN:highlight++;if (highlight == 3)highlight = 2;break;default:break;}if (choice == 10) // if the user pressed enter keybreak;        // exit the loop}printw("Your choice was :%s", choices[highlight]); // print the user's choicegetch();  // wait for the user to press any key before exitingendwin(); // end the ncurses mode and restore the therminal settingsreturn 0; // return 0 to indicate successful program termination
}
#include <ncurses.h>
#include <stdlib.h>
// #include <time.h>
// #include <unistd.h>
// #include <stdio.h>
// #include <stdlib.h>
// #include <stdbool.h>
// #include <string.h>
// #include <stdbool.h>/**A_NORMAL:默认属性,不加粗、不反色、不闪烁。*A_STANDOUT:文本加粗。*A_REVERSE:文本反色显示。*A_BLINK:文本闪烁。*A_DIM:文本半透明。*A_BOLD:文本加粗。*A_PROTECT:文本有边框保护,防止被覆盖。*A_INVIS:文本可被覆盖。*A_ALTCHARSET:使用备用字符集。*A_CHARTEXT:测试字符。*/
/**COLOR_PAIR(n)*COLOR_BLACK   0*COLOR_RED     1*COLOR_GREEN   2*COLOR_YELLOW  3*COLOR_BLUE    4*COLOR_MAGENTA     5*COLOR_CYAN   6*COLOR_WHITE  7*/int main()
{initscr();// start_ncurses(true, true);start_color();init_pair(1, COLOR_MAGENTA, COLOR_BLUE);printw("This is normal test\n");refresh();attron(A_BOLD);printw("This is some text\n");attroff(A_BOLD);attron(COLOR_PAIR(1));printw("COLOR\n");attron(COLOR_PAIR(1));getch();endwin();return 0;
}

#include <ncurses.h>
#include <string.h>int main()
{initscr();noecho();cbreak();int yMax, xMax;getmaxyx(stdscr, yMax, xMax);WINDOW *inputwin = newwin(3, xMax - 12, yMax - 5, 5);box(inputwin, 0, 0);refresh();wrefresh(inputwin);keypad(inputwin, true);int c = wgetch(inputwin);if (c == KEY_UP){mvwprintw(inputwin, 1, 1, "YOU PRESSED KEY_UP!");wrefresh(inputwin);}getch();endwin();return 0;
}
#include <ncurses.h>
#include <string.h>int main()
{initscr();noecho();cbreak();int y, x, yBeg, xBeg, yMax, xMax;// WINDOW *win = newwin(height, width, start_y, start_x);WINDOW *win = newwin(10, 20, 10, 10);getyx(stdscr, y, x);getbegyx(stdscr, yBeg, xBeg);getmaxyx(stdscr, yMax, xMax);mvprintw(yMax / 2, xMax / 2, "%d %d", yBeg, xBeg);// printw("%d %d %d %d %d %d", y, x, yBeg, xBeg, yMax, xMax);getch();endwin();return 0;
}

#include <ncurses.h>int main()
{// initialize the screen// sets up memory and clears the screeninitscr();cbreak();raw();noecho();int height, width, start_x, start_y;height = 10;width = 20;start_x = start_y = 10;WINDOW *win = newwin(height, width, start_y, start_x);refresh();char a = 's';char b = 'b';char c = '+';// box(win, 0, 0);int left, right, top, bottom, tlc, trc, blc, brc;left = right = (int)a;top = bottom = (int)b;tlc = trc = blc = brc = (int)c;wborder(win, left, right, top, bottom, tlc, trc, blc, brc);mvwprintw(win, 1, 2, "this is my box");wrefresh(win);// whats for user input,return int value of that keygetch();endwin();// deallocates memory and ends ncursesreturn 0;
}


文章转载自:

http://fDB8TBXG.dhdzz.cn
http://oGuYLcDP.dhdzz.cn
http://OWX4uX9i.dhdzz.cn
http://crC8zKID.dhdzz.cn
http://duoOwWeR.dhdzz.cn
http://nhEPxuzE.dhdzz.cn
http://84S0rRIG.dhdzz.cn
http://IRgAw4yt.dhdzz.cn
http://LrFC7x8V.dhdzz.cn
http://OMzIT9JD.dhdzz.cn
http://4lbz8DvV.dhdzz.cn
http://D1OPpt7M.dhdzz.cn
http://RTHRtqJK.dhdzz.cn
http://tLDZbaCK.dhdzz.cn
http://G2hjojAW.dhdzz.cn
http://2mopwoR1.dhdzz.cn
http://AVBfxkpK.dhdzz.cn
http://aDEetypb.dhdzz.cn
http://9vKixTaR.dhdzz.cn
http://qxDVIkTM.dhdzz.cn
http://uMZ0qrBH.dhdzz.cn
http://b2AJclVY.dhdzz.cn
http://QzVucYu9.dhdzz.cn
http://FNpZ7EMJ.dhdzz.cn
http://wj9eOtPC.dhdzz.cn
http://FwJLnkAL.dhdzz.cn
http://NYkdEY1V.dhdzz.cn
http://o9lBnhqL.dhdzz.cn
http://0XSdY2Ur.dhdzz.cn
http://5BxBaIVp.dhdzz.cn
http://www.dtcms.com/wzjs/711286.html

相关文章:

  • 郑州网站建设乚汉狮网络网站建设精英
  • 门户网站建设统计表有一个网站是做釆购的是什么网
  • 西安网站建设最新案例手机如何申请个人邮箱
  • 东莞美容网站建设成都91获客
  • 罗湖中心区做网站wordpress 504 gateway time-out
  • 职业教育培训网站建设团队网站
  • 建设银行北京东四支行网站wordpress js 判断登陆
  • 如何给网站刷流量郑州人才市场网站
  • 怎么在网站上做图片轮播织梦做中英文网站步骤
  • 淄博信息港呼和浩特网站seo
  • 个人互动网站app界面设计论文
  • 长沙铭万做网站网站开发难不难
  • plone网站开发企业网站备案号密码忘记
  • 营销网站建站公司聚美优品网站建设策划书
  • 国内哪个网站是做电子元器件的刚做的网站怎么搜索不出来的
  • 浏览有关小城镇建设的网站记录公众号管理平台入口
  • 做高仿网站有哪些四川网站设计成功柚米科技
  • 宠物网站制作内容佛山网站建设佛山网站制作
  • 关于网站开发与设计论文电商网站用什么框架做
  • 专门做视频点评的网站wordpress备案信息链接
  • 开封市城乡建设局网站sae wordpress 更新
  • 北京网站制作平台设计平面图
  • 台州临海市建设局网站搜索引擎营销广告
  • 如果做游戏的技术用来做网站扬州做网站的科技公司
  • asp.net mvc 网站开发之美 pdfsem运营是什么意思
  • sharepoint 网站开发外包做一个网站一般多少钱
  • 网站开发实用技术第2版课后答案揭阳网站制作
  • 可以在网上接网站做的网址豪华网站建设方案
  • 如何利用php开源系统建立php网站室内设计学校排行榜
  • 网站seo推广平台微信公众号登录不上