I am using ncurses to build my own terminal. My main window contains 5 other windows. The window which I have positioned below, is the prompt panel. I would like text to be entered there and as well I want the ability to input text in there. I have positioned the cursor using wmove but the cursor remains at the top left part of the window. As well, when I enter text, everything shifts.
This is part of my code;
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();
}