我的 ncurses noecho() 不起作用
my ncurses noecho() doesn't work
出于某种原因,我的 noecho()
初始化无法正常工作,直到我输入两次。第一次按 h
时,我在屏幕上看到一个 'h'
字符。但是,下一个按下的键不会出现在屏幕上。如何防止显示所有输入?
#include <ncurses.h>
int main(){
initscr(); /* Start curses mode */
raw(); /* prevents use of signals from ctl + c
noecho(); /* suppress echo */
mvprintw(10,10,"Hello World!!"); /* Print */
refresh(); /* print it on real screen */
while(true){
char ch = getch(); /* wait for input */
if(ch == 'q')
break;
else if(ch == 'h'){
mvprintw(10,10,"Test");
}
else{
attroff(A_BOLD);
}
}
endwin(); /* end curses mode */
return 0;
}
注释未结束,编译器忽略noecho
:
raw(); /* prevents use of signals from ctl + c
noecho(); /* suppress echo */
如果你使用gcc的警告,你可以看到这个:
foo.c:3:5: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
foo.c: In function ‘main’:
foo.c:6:37: warning: "/*" within comment [-Wcomment]
foo.c:12:23: warning: conversion to ‘char’ from ‘int’ may alter its value [-Wconversion]
出于某种原因,我的 noecho()
初始化无法正常工作,直到我输入两次。第一次按 h
时,我在屏幕上看到一个 'h'
字符。但是,下一个按下的键不会出现在屏幕上。如何防止显示所有输入?
#include <ncurses.h>
int main(){
initscr(); /* Start curses mode */
raw(); /* prevents use of signals from ctl + c
noecho(); /* suppress echo */
mvprintw(10,10,"Hello World!!"); /* Print */
refresh(); /* print it on real screen */
while(true){
char ch = getch(); /* wait for input */
if(ch == 'q')
break;
else if(ch == 'h'){
mvprintw(10,10,"Test");
}
else{
attroff(A_BOLD);
}
}
endwin(); /* end curses mode */
return 0;
}
注释未结束,编译器忽略noecho
:
raw(); /* prevents use of signals from ctl + c
noecho(); /* suppress echo */
如果你使用gcc的警告,你可以看到这个:
foo.c:3:5: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
foo.c: In function ‘main’:
foo.c:6:37: warning: "/*" within comment [-Wcomment]
foo.c:12:23: warning: conversion to ‘char’ from ‘int’ may alter its value [-Wconversion]