Working on ncurses TUI

This commit is contained in:
Max 2024-01-28 23:38:39 +01:00
parent 47f5ce53d6
commit e6e43fc9f0
3 changed files with 18 additions and 6 deletions

View File

@ -10,6 +10,8 @@
#define WARN(msg, args...) printw("[Warning]: " msg "\n", ##args); refresh() #define WARN(msg, args...) printw("[Warning]: " msg "\n", ##args); refresh()
#define ERROR(msg, args...) printw("[ERROR]: " 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 typedef enum socket_ipv
{ {
IPv4, IPv4,

View File

@ -21,7 +21,7 @@ void netex_init(void)
if (has_colors() && can_change_color()) if (has_colors() && can_change_color())
{ {
start_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 //TODO: Make color pairs
} }
// OpenSSL // OpenSSL

View File

@ -4,26 +4,34 @@
#include <ncurses.h> #include <ncurses.h>
#include "netex.h"
#include "server.h" #include "server.h"
// INFO // INFO
// https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/ // https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/
// //
#define PAIR_BG_WIN_COLOR 2
WINDOW *info_win, *log_win; WINDOW *info_win, *log_win;
int setup_windows(void) int setup_windows(void)
{ {
// Color pairs
init_pair(PAIR_BG_WIN_COLOR, COLOR_GREEN, COLOR_BLACK);
// Windows
int ymax,xmax; int ymax,xmax;
getmaxyx(stdscr, ymax, xmax); getmaxyx(stdscr, ymax, xmax);
info_win = newwin(15, xmax-1, 1, 1); info_win = newwin(GET_PERC(ymax, 20), xmax-1, 1, 0);
/*int half_scr = xmax * 100 / 50; = add 50 percent of num -> 100 + 50% = 150 log_win = newwin(ymax-16, GET_PERC(xmax, 50), GET_PERC(ymax, 20) + 1, 0);
half_scr = xmax * 50 / 100; = get 50 percent of num -> 100 - 50% = 50
*/
log_win = newwin(ymax-16, xmax * 50 / 100, 16, 1);
refresh(); refresh();
wattron(info_win, COLOR_PAIR(PAIR_BG_WIN_COLOR));
box(info_win, 0, 0); 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); box(log_win, 0, 0);
wattroff(log_win, COLOR_PAIR(PAIR_BG_WIN_COLOR));
mvwprintw(info_win, 0, 1, " Info window "); mvwprintw(info_win, 0, 1, " Info window ");
mvwprintw(log_win, 0, 1, " Log window "); mvwprintw(log_win, 0, 1, " Log window ");
for (int i = 0; i != 15; i++) for (int i = 0; i != 15; i++)
@ -32,9 +40,11 @@ int setup_windows(void)
} }
wrefresh(info_win); wrefresh(info_win);
wrefresh(log_win); wrefresh(log_win);
return 0; return 0;
} }
void calculate_wind_sizes(void) void calculate_wind_sizes(void)
{ {
//TODO: calculate the size of the windows on the screen, called when first start and on screen resize. //TODO: calculate the size of the windows on the screen, called when first start and on screen resize.
} }