initial commit

This commit is contained in:
2026-03-12 15:56:28 -05:00
commit 5e41e88961
18 changed files with 770 additions and 0 deletions

55
disp.cc Normal file
View File

@@ -0,0 +1,55 @@
#include <fstream>
#include <curses.h>
#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;
}
}