forked from scott/threaded_network_chat
oops
This commit is contained in:
51
src/display.cc
Normal file
51
src/display.cc
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include <curses.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user