#include #include #include "disp.h" #include "public.h" // clears ncurses rows in a specific region only void clearRows(int startingRow, int endingRow) { // preserve the cursor location int yBefore, xBefore; getyx(stdscr, yBefore, xBefore); for (int i = startingRow; i < endingRow; i++) { move(i, 0); clrtoeol(); // clear to end of line } // restore original cursor location move(yBefore, xBefore); } // display a file using ncurses int displayFile(string path, int startLineNum = 0, int numLines = 10) { ifstream file(path); if (!file) { return 1; } else { clearRows(0, numLines + 1); // clear the chat area int lineNum = 0; string line; // print each line directly to the screen int num = 0; while (getline(file, line) && num <= numLines + startLineNum + 1) // while there is file content and the // line number isn't too high { if (num >= startLineNum) { move(lineNum, 0); printw("%s", line.c_str()); lineNum++; // increment the row number after // printing each line } num++; } move(DEFAULT_CUR_Y, DEFAULT_CUR_X); refresh(); return 0; } }