我正在使用ncurses为我的应用程序创建一个简单的TUI。 我得到了创建和打印到窗口的基础知识,但我输入有问题。
但是当我开始输入时,光标移动到终端窗口的左上角。
如何在键入时将其保留到位?
这是我的代码:
#include <ncurses.h>
WINDOW *win;
int startx, starty, width, height;
int cport;
WINDOW *makewin(int h, int w, int y, int x)
{
WINDOW *lwin;
lwin = newwin(h, w, y, x);
box(lwin, 0 , 0);
wrefresh(lwin);
return lwin;
}
void dewin(WINDOW *lwin)
{
wborder(lwin, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
wrefresh(lwin);
delwin(lwin);
}
void getPort(){
win = makewin(height, width, starty, startx);
wbkgd(win, COLOR_PAIR(1));
mvwprintw(win, 0, 8, "Port Settings");
mvwprintw(win, 2, 4, "Set port server should");
mvwprintw(win, 3, 4, "listen to: ");
wrefresh(win);
scanw("%d", &cport);
}
int main()
{
initscr();
cbreak();
keypad(stdscr, TRUE);
start_color();
init_pair(1,COLOR_WHITE, COLOR_BLACK);
init_pair(2,COLOR_WHITE, COLOR_BLUE);
bkgd(COLOR_PAIR(2));
refresh();
height = 6;
width = 30;
starty = (LINES - height) / 2;
startx = (COLS - width) / 2;
getPort();
getch();
dewin(win);
endwin();
return 0;
}