refactor: move display-related functions to display.cc

This commit is contained in:
2026-03-09 12:32:02 -05:00
parent 08b7809c34
commit 0f66b7f4c2
3 changed files with 3 additions and 49 deletions

View File

@@ -2,7 +2,7 @@ CXX = g++
CXXFLAGS = -pthread -Wall -Wextra -O2 -std=c++17 CXXFLAGS = -pthread -Wall -Wextra -O2 -std=c++17
LDFLAGS = -lcurses LDFLAGS = -lcurses
TARGET = ct TARGET = ct
CXX_SRCS = main.cc net.cc CXX_SRCS = main.cc net.cc file.cc display.cc
CXX_OBJS = $(CXX_SRCS:.cc=.o) CXX_OBJS = $(CXX_SRCS:.cc=.o)
all: $(TARGET) all: $(TARGET)

View File

@@ -6,6 +6,8 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <pthread.h> #include <pthread.h>
#define CURSOR_DEFAULT_POSITION_X 2
#define CURSOR_DEFAULT_POSITION_Y 12
#define LOG_LENGTH 10 #define LOG_LENGTH 10
typedef struct __wclient_args_t wclient_args_t; typedef struct __wclient_args_t wclient_args_t;

View File

@@ -24,9 +24,6 @@ chatmode_t mode = NO_MODE;
// const int LOG_LENGTH = 10; // const int LOG_LENGTH = 10;
int line_position = 0; 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_start;
struct timeval time_end; struct timeval time_end;
int bytes_read; int bytes_read;
@@ -127,48 +124,3 @@ panic_no_server_sock:
fprintf(stderr, "Fatal: Could not establish server socket!\n"); fprintf(stderr, "Fatal: Could not establish server socket!\n");
return 1; 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;
}