forked from scott/threaded_network_chat
refactor: move display-related functions to display.cc
This commit is contained in:
@@ -2,7 +2,7 @@ CXX = g++
|
||||
CXXFLAGS = -pthread -Wall -Wextra -O2 -std=c++17
|
||||
LDFLAGS = -lcurses
|
||||
TARGET = ct
|
||||
CXX_SRCS = main.cc net.cc
|
||||
CXX_SRCS = main.cc net.cc file.cc display.cc
|
||||
CXX_OBJS = $(CXX_SRCS:.cc=.o)
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include <netinet/in.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#define CURSOR_DEFAULT_POSITION_X 2
|
||||
#define CURSOR_DEFAULT_POSITION_Y 12
|
||||
#define LOG_LENGTH 10
|
||||
|
||||
typedef struct __wclient_args_t wclient_args_t;
|
||||
|
||||
48
src/main.cc
48
src/main.cc
@@ -24,9 +24,6 @@ chatmode_t mode = NO_MODE;
|
||||
// const int LOG_LENGTH = 10;
|
||||
int line_position = 0;
|
||||
|
||||
const int CURSOR_DEFAULT_POSITION_X = 2;
|
||||
const int CURSOR_DEFAULT_POSITION_Y = 12;
|
||||
|
||||
struct timeval time_start;
|
||||
struct timeval time_end;
|
||||
int bytes_read;
|
||||
@@ -127,48 +124,3 @@ panic_no_server_sock:
|
||||
fprintf(stderr, "Fatal: Could not establish server socket!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
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