From 59e34977da858d3c3e92f4f948726a18f0edaea7 Mon Sep 17 00:00:00 2001 From: "jazz (gitea)" Date: Mon, 9 Mar 2026 12:32:22 -0500 Subject: [PATCH] oops --- src/display.cc | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/display.cc diff --git a/src/display.cc b/src/display.cc new file mode 100644 index 0000000..6b7e889 --- /dev/null +++ b/src/display.cc @@ -0,0 +1,51 @@ +#include + +#include + +#include "chat.h" + +void +clear_rows(int s, int e) +{ + /* preserve cursor location */ + int x_bef; + int y_bef; + + getyx(stdscr, y_bef, x_bef); + + for (int i = s; i < e; i++) { + move(i, 0); + clrtoeol(); + } + + move(y_bef, x_bef); +} + +int +file_disp(std::string p, int lnstart, int lncount) +{ + std::ifstream f(p); + + if (!f) + return 1; + + int i = 0; + int ln_no = 0; + std::string ln; + + clear_rows(0, lncount + 1); /* clear chat window */ + + while (getline(f, ln) && i <= ln_no + lnstart + 1) { + if (i >= lnstart) { + move(ln_no, 0); + printw("%s", ln.c_str()); + ln_no++; + } + i++; + } + + move(CURSOR_DEFAULT_POSITION_Y, CURSOR_DEFAULT_POSITION_X); + refresh(); + return 0; +} +