From 0f66b7f4c2d5119b18a9137ea3b58a8aad3a6172 Mon Sep 17 00:00:00 2001 From: "jazz (gitea)" Date: Mon, 9 Mar 2026 12:32:02 -0500 Subject: [PATCH] refactor: move display-related functions to display.cc --- src/Makefile | 2 +- src/chat.h | 2 ++ src/main.cc | 48 ------------------------------------------------ 3 files changed, 3 insertions(+), 49 deletions(-) diff --git a/src/Makefile b/src/Makefile index 781b146..21d4721 100644 --- a/src/Makefile +++ b/src/Makefile @@ -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) diff --git a/src/chat.h b/src/chat.h index 4d1decf..fc9c412 100644 --- a/src/chat.h +++ b/src/chat.h @@ -6,6 +6,8 @@ #include #include +#define CURSOR_DEFAULT_POSITION_X 2 +#define CURSOR_DEFAULT_POSITION_Y 12 #define LOG_LENGTH 10 typedef struct __wclient_args_t wclient_args_t; diff --git a/src/main.cc b/src/main.cc index b1a279f..774c4c4 100644 --- a/src/main.cc +++ b/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; -}