From e6e43fc9f02a7ada631f9d145d626a587b620148 Mon Sep 17 00:00:00 2001 From: Max <51083570+DRdrProfessor@users.noreply.github.com> Date: Sun, 28 Jan 2024 23:38:39 +0100 Subject: [PATCH] Working on ncurses TUI --- src/net/include/netex.h | 2 ++ src/net/netex.c | 2 +- src/server/srv_tui.c | 20 +++++++++++++++----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/net/include/netex.h b/src/net/include/netex.h index d2a6323..083ab2e 100644 --- a/src/net/include/netex.h +++ b/src/net/include/netex.h @@ -10,6 +10,8 @@ #define WARN(msg, args...) printw("[Warning]: " msg "\n", ##args); refresh() #define ERROR(msg, args...) printw("[ERROR]: " msg "\n", ##args); refresh() +#define GET_PERC(num, perc) num * perc / 100 + typedef enum socket_ipv { IPv4, diff --git a/src/net/netex.c b/src/net/netex.c index 20e2dab..3772020 100644 --- a/src/net/netex.c +++ b/src/net/netex.c @@ -21,7 +21,7 @@ void netex_init(void) if (has_colors() && can_change_color()) { start_color(); - //PRINT_LINE("%i colors available, %i color pairs available.", COLORS, COLOR_PAIRS); + PRINT_LINE("%i colors available, %i color pairs available.", COLORS, COLOR_PAIRS); //TODO: Make color pairs } // OpenSSL diff --git a/src/server/srv_tui.c b/src/server/srv_tui.c index 8232d86..66e0cb7 100644 --- a/src/server/srv_tui.c +++ b/src/server/srv_tui.c @@ -4,26 +4,34 @@ #include +#include "netex.h" #include "server.h" // INFO // https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/ // +#define PAIR_BG_WIN_COLOR 2 + WINDOW *info_win, *log_win; int setup_windows(void) { + // Color pairs + init_pair(PAIR_BG_WIN_COLOR, COLOR_GREEN, COLOR_BLACK); + + // Windows int ymax,xmax; getmaxyx(stdscr, ymax, xmax); - info_win = newwin(15, xmax-1, 1, 1); - /*int half_scr = xmax * 100 / 50; = add 50 percent of num -> 100 + 50% = 150 - half_scr = xmax * 50 / 100; = get 50 percent of num -> 100 - 50% = 50 - */ - log_win = newwin(ymax-16, xmax * 50 / 100, 16, 1); + info_win = newwin(GET_PERC(ymax, 20), xmax-1, 1, 0); + log_win = newwin(ymax-16, GET_PERC(xmax, 50), GET_PERC(ymax, 20) + 1, 0); refresh(); + wattron(info_win, COLOR_PAIR(PAIR_BG_WIN_COLOR)); box(info_win, 0, 0); + wattroff(info_win, COLOR_PAIR(PAIR_BG_WIN_COLOR)); + wattron(log_win, COLOR_PAIR(PAIR_BG_WIN_COLOR)); box(log_win, 0, 0); + wattroff(log_win, COLOR_PAIR(PAIR_BG_WIN_COLOR)); mvwprintw(info_win, 0, 1, " Info window "); mvwprintw(log_win, 0, 1, " Log window "); for (int i = 0; i != 15; i++) @@ -32,9 +40,11 @@ int setup_windows(void) } wrefresh(info_win); wrefresh(log_win); + return 0; } void calculate_wind_sizes(void) { + //TODO: calculate the size of the windows on the screen, called when first start and on screen resize. } \ No newline at end of file