I am running a program which makes use of the ncurses library to display windows in the terminal containing data being updated and inserted into its corresponding window from my main source file.
I have a separate file with its own header file which contains printf statements I would like to convert to ncurse functions. And display within the windows I created.
ncurses required some setup and made use of some small functions so im unsure how to use it within both files. I tried including it within my header file and linking to both my source files however I get multiple defenitions, first defined here errors.
Setup for ncurse windows within my main file:
/* Window defintion constants*/
#define PROTOPORT 36795 /* default protocol port number, booknumber */
#define QLEN 6 /* size of request queue */
#define MAXSIZE 256
#define NUMWINS 7
#define RES_BUF_SIZE 80
WINDOW *w[NUMWINS];
WINDOW *sw[NUMWINS];
WINDOW wh[NUMWINS];
void update_win(int i) {
touchwin(w[i]);
wrefresh(sw[i]);
}
/* add string to a window */
void wAddstr(int z, char c[255]);
void GUIshutdown(char * response) {
wmove(sw[4], 0, 0);
wclrtoeol(sw[4]);
wprintw(sw[4], "All finished. Press Enter to terminate the program.");
update_win(4);
wgetstr(sw[4], response);
/* End screen updating */
endwin();
echo();
}
//////////
int main(int argc, char *argv[]) {
/***********************************************/
/* setup ncurses for multiple windows */
/***********************************************/
setlocale(LC_ALL, ""); // this has to do with the character set to use
initscr();
cbreak();
noecho();
nonl();
intrflush(stdscr, FALSE);
keypad(stdscr, TRUE);
/* Clear screen before starting */
clear();
w[0] = newwin(0,0,0,0);
if (LINES != 43 || COLS != 132) {
move(0, 0);
addstr("Piggy3 requires a screen size of 132 columns and 43 rows");
move(1, 0);
addstr("Set screen size to 132 by 43 and try again");
move(2, 0);
addstr("Press enter to terminate program");
mvprintw(3,0,"%dx%d\n", COLS, LINES);
refresh();
getstr(response); // Pause so we can see the screen
endwin();
exit(EXIT_FAILURE);
}
/* create the 7 windows and the seven subwindows*/
for (a = 0; a < NUMWINS; a++) {
w[a] = newwin(WPOS[a][0], WPOS[a][1], WPOS[a][2], WPOS[a][3]);
sw[a] = subwin(w[a], WPOS[a][0] - 2, WPOS[a][1] - 2, WPOS[a][2] + 1, WPOS[a][3] + 1);
scrollok(sw[a], TRUE); // allows window to be automatically scrolled
wborder(w[a], 0, 0, 0, 0, 0, 0, 0, 0);
touchwin(w[a]);
wrefresh(w[a]);
wrefresh(sw[a]);
}
/***********************************************/
/* Windows */
/***********************************************/
/*
* Notes:
* sw[0] = upper left window,
* sw[1] = upper right window,
* sw[2] = bottom left window,
* sw[3] = bottom right window
* sw[4] = bottom command window
* sw[5] = bottom inputs window
* sw[6] = bottom errors menu.
*/
wmove(sw[0], 0, 0);
wprintw(sw[0], "This is the window where the data flowing from left to right ");
wprintw(sw[0], "will be displayed. Notice now we don't need to worry about when we reach the last ");
wprintw(sw[0], " position in the subwindow, we will just wrap around down to the next line of the subwindow");
wprintw(sw[0], " and can never mess up the border that is in the parent window");
wprintw(sw[inLeft], " Data coming from the left, head piggy\n");
wmove(sw[1], 4, 0);
waddstr(sw[1], "Data leaving right side");
wmove(sw[2], 4, 0);
waddstr(sw[2], "Data leaving the left side");
wmove(sw[3], 4, 0);
waddstr(sw[3], "Data arriving from the right");
wmove(sw[4], 0, 0);
waddstr(sw[4], "Commands: ");
wmove(sw[5], 0, 0);
waddstr(sw[5], "Data Entry: ");
wmove(sw[6], 0, 0);
waddstr(sw[6], "Errors: ");
for (int a = 0; a < NUMWINS; a++){
update_win(a);
}
wmove(sw[4], 0, 0);
wprintw(sw[4], "Press Enter to see the output in the upper left window scroll");
wgetstr(sw[4], response); // Pause so we can see the screen
wmove(sw[4], 0, 0);
wclrtoeol(sw[4]); // clears current line without clobbering borders
update_win(4);
}