【发布时间】:2017-04-28 17:46:33
【问题描述】:
我正在使用 ncurses 构建自己的终端。我的主窗口包含 5 个其他窗口。我放置在下面的窗口是提示面板。我希望在此处输入文本,并且我希望能够在其中输入文本。我已使用 wmove 定位光标,但光标仍位于窗口的左上角。同样,当我输入文本时,一切都会发生变化。
这是我的代码的一部分;
WINDOW *mainwin, *date_time, *alarm, *colour, *output, *prompt_win;
/* Initialize ncurses */
mainwin = initscr();
if (!mainwin) {
fprintf(stderr, "Error initialising ncurses.\n");
exit(EXIT_FAILURE);
}
/* Make our child window, and add a border and some text to it. */
date_time = subwin(mainwin, 5, 35, 0, 0);
box(date_time, 0, 0);
alarm = subwin(mainwin, 5, 35, 0, 35);
box(alarm, 0, 0);
colour = subwin(mainwin, 5, 5, 0, 70);
box(colour, 0, 0);
output = subwin(mainwin, 10, 75, 5, 0);
box(output, 0, 0);
prompt_win = subwin(mainwin, 7, 75, 15, 0);
box(prompt_win, 0, 0);
pid_t pid = fork();
if (pid < 0) {
perror("Error: Fork Failed");
} else if (pid == 0) {
/* Alarm & date */
pid_t child_pid = getpid();
pid_t pid2 = fork();
if (pid2 < 0) {
perror("Error: Fork Failed");
} else if (pid2 == 0) {
/* Date */
pid_t child_pid2 = getpid();
while (1) {
wnoutrefresh(date_time);
getTime(date_time);
/* doupdate() */
}
} else {
/* Alarm */
wnoutrefresh(alarm);
wnoutrefresh(colour);
/* doupdate() */
}
/* _exit(0); */
} else {
/* Output & prompt */
/* Display and enter text */
/* prints "OK>" */
mvwprintw(prompt_win,curse_loc,1,prompt_arr[0]);
wnoutrefresh(prompt_win);
/* gets input */
getstr(buffer[curse_loc]);
strcpy(current_cmd,buffer[curse_loc]);
refresh();
while (strcmp(current_cmd,"exit")) {
wmove(prompt_win, curse_loc, sizeof(prompt_arr));
refresh();
mvwin(prompt_win, curse_loc, curse_loc);
wnoutrefresh(prompt_win);
curse_loc++;
/* again displays "OK>" */
mvwprintw(prompt_win, curse_loc, 1, prompt_arr[0]);
/* gets input */
getstr(buffer[curse_loc]);
strcpy(current_cmd, buffer[curse_loc]);
doupdate();
}
endwin();
delwin(prompt_win);
delwin(output);
delwin(colour);
delwin(alarm);
delwin(date_time);
delwin(mainwin);
refresh();
}
【问题讨论】: