mirror of
https://github.com/hmaxnl/netex.git
synced 2025-01-18 15:34:20 +01:00
Reworking UI & starting on logging
This commit is contained in:
parent
11226d1495
commit
c0fe13476e
|
@ -15,5 +15,6 @@ target_link_directories(netex PUBLIC ${CURSES_INCLUDE_DIR})
|
|||
target_include_directories(netex PRIVATE ${CMAKE_SOURCE_DIR}/src/net/include)
|
||||
|
||||
add_subdirectory(include)
|
||||
add_subdirectory(logging)
|
||||
add_subdirectory(str)
|
||||
add_subdirectory(tui)
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
|
||||
target_sources(netex PUBLIC
|
||||
"config.h"
|
||||
"log.h"
|
||||
"net.h"
|
||||
"netex.h"
|
||||
"nx_tui.h"
|
||||
"nx_curses.h"
|
||||
"sockets.h"
|
||||
"strutil.h")
|
6
src/net/include/log.h
Normal file
6
src/net/include/log.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#ifndef LOG_H
|
||||
#define LOG_H
|
||||
|
||||
|
||||
|
||||
#endif //LOG_H
|
|
@ -2,14 +2,13 @@
|
|||
#define NETEX_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ncurses.h>
|
||||
|
||||
|
||||
#define PRINT(msg, args...) printw(msg, ##args); refresh()
|
||||
#define PRINT_LINE(msg, args...) printw(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 GET_PERC(num, perc) num * perc / 100
|
||||
|
||||
typedef enum socket_ipv
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef NX_TUI_H
|
||||
#define NX_TUI_H
|
||||
|
||||
#include <ncurses.h>
|
||||
|
||||
/// Color pairs
|
||||
|
||||
#define DEF_COLOR_PAIR 1
|
||||
|
@ -10,9 +12,12 @@
|
|||
|
||||
|
||||
int setup_curses(void);
|
||||
|
||||
WINDOW* create_base_window_box(const char* title, const int nlines, const int ncols, const int begin_y, const int begin_x);
|
||||
|
||||
void shutdown_curses(void);
|
||||
|
||||
typedef struct scr_size
|
||||
{
|
||||
int y;
|
||||
int x;
|
||||
}SCR_SIZE;
|
||||
|
||||
#endif //NX_TUI_H
|
2
src/net/logging/CMakeLists.txt
Normal file
2
src/net/logging/CMakeLists.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
target_sources(netex PUBLIC
|
||||
"log.c")
|
2
src/net/logging/log.c
Normal file
2
src/net/logging/log.c
Normal file
|
@ -0,0 +1,2 @@
|
|||
#include "netex.h"
|
||||
#include "log.h"
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#include "netex.h"
|
||||
#include "config.h"
|
||||
#include "nx_tui.h"
|
||||
#include "nx_curses.h"
|
||||
|
||||
#define PORT_NUM_LENGHT 6
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "netex.h"
|
||||
#include "nx_tui.h"
|
||||
#include "nx_curses.h"
|
||||
|
||||
int setup_curses(void)
|
||||
{
|
||||
|
@ -12,21 +12,10 @@ int setup_curses(void)
|
|||
|
||||
init_pair(DEF_COLOR_PAIR, COLOR_WHITE, COLOR_BLACK);
|
||||
init_pair(DEF_WIN_COLOR, COLOR_GREEN, COLOR_BLACK);
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
WINDOW* create_base_window_box(const char* title, const int nlines, const int ncols, const int begin_y, const int begin_x)
|
||||
{
|
||||
WINDOW* win = newwin(nlines, ncols, begin_y, begin_x);
|
||||
if (win == NULL)
|
||||
return NULL;
|
||||
box(win, 0, 0);
|
||||
mvwprintw(win, 0, 1, title);
|
||||
return win;
|
||||
}
|
||||
|
||||
void shutdown_curses(void)
|
||||
{
|
||||
endwin();
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
add_executable(netex_svr
|
||||
"main.c"
|
||||
"server.c"
|
||||
"srv_tui.c"
|
||||
"srv_tui.h"
|
||||
"srv_ui.c"
|
||||
"server.h")
|
||||
|
||||
target_include_directories(netex_svr PRIVATE ${CMAKE_SOURCE_DIR}/src/net/include)
|
||||
target_link_libraries(netex_svr netex)
|
||||
|
||||
add_subdirectory(tui)
|
|
@ -1,5 +1,3 @@
|
|||
#include <stdio.h>
|
||||
|
||||
#include "netex.h"
|
||||
#include "server.h"
|
||||
|
||||
|
@ -12,8 +10,13 @@
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
netex_init();
|
||||
setup_windows();
|
||||
if (!setup_srv_curses())
|
||||
{
|
||||
PRINT_LINE("Failed to setup srv windows!");
|
||||
getch();
|
||||
return 0;
|
||||
}
|
||||
getch(); // For debuging!
|
||||
const int init_result = initialize_server(argc, argv);
|
||||
if (init_result)
|
||||
{
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
#ifndef SERVER_H
|
||||
#define SERVER_H
|
||||
#include "nx_curses.h"
|
||||
|
||||
int initialize_server(int argc, char* argv[]);
|
||||
int server_execute(void);
|
||||
|
||||
int setup_windows(void);
|
||||
/* Curses */
|
||||
bool setup_srv_curses();
|
||||
|
||||
#endif //SERVER_H
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
#include <ncurses.h>
|
||||
|
||||
#include "netex.h"
|
||||
#include "server.h"
|
||||
#include "srv_tui.h"
|
||||
|
||||
#include "nx_tui.h"
|
||||
|
||||
|
||||
WINDOW *info_win, *log_win, *log_pad;
|
||||
|
||||
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 = create_base_window_box(" Info ",GET_PERC(ymax, 20), xmax-1, 1, 0);
|
||||
log_win = create_base_window_box(" Log window ", ymax-16, GET_PERC(xmax, 50), GET_PERC(ymax, 20) + 1, 0);
|
||||
log_pad = subpad(log_win, ymax-15, GET_PERC(xmax, 50) - 1, 1, 1);
|
||||
refresh();
|
||||
|
||||
for (int i = 0; i != 15; i++)
|
||||
{
|
||||
waddstr(log_pad, "Test!");
|
||||
}
|
||||
wrefresh(info_win);
|
||||
wrefresh(log_win);
|
||||
touchwin(log_win);
|
||||
prefresh(log_pad, 0, 0, 10, 10, 10, 10);
|
||||
|
||||
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.
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
//
|
||||
// Created by max on 10-2-24.
|
||||
//
|
||||
// https://invisible-island.net/ncurses/
|
||||
// https://tldp.org/HOWTO/NCURSES-Programming-HOWTO/
|
||||
|
||||
#ifndef SRV_TUI_H
|
||||
#define SRV_TUI_H
|
||||
|
||||
// Color pairs
|
||||
|
||||
#define PAIR_BG_WIN_COLOR 1
|
||||
|
||||
#endif //SRV_TUI_H
|
81
src/server/srv_ui.c
Normal file
81
src/server/srv_ui.c
Normal file
|
@ -0,0 +1,81 @@
|
|||
#include "netex.h"
|
||||
#include "server.h"
|
||||
|
||||
WINDOW *info_win, *log_win, *log_win_content;
|
||||
SCR_SIZE info_win_size, log_win_size;
|
||||
|
||||
bool setup_info_window(void);
|
||||
bool write_info(const char* conn, int port, const char* ipv);
|
||||
bool setup_log_window(void);
|
||||
void calculate_window_sizes(void);
|
||||
|
||||
bool setup_srv_curses(void)
|
||||
{
|
||||
calculate_window_sizes();
|
||||
if (!setup_info_window())
|
||||
return false;
|
||||
if (!setup_log_window())
|
||||
{
|
||||
delwin(info_win);
|
||||
return false;
|
||||
}
|
||||
refresh();
|
||||
wrefresh(info_win);
|
||||
wrefresh(log_win);
|
||||
wrefresh(log_win_content);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool setup_info_window(void)
|
||||
{
|
||||
info_win = subwin(stdscr, info_win_size.y, info_win_size.x, 1, 0);
|
||||
if (info_win == NULL)
|
||||
return false;
|
||||
box(info_win, 0, 0);
|
||||
mvwprintw(info_win, 0, 1, " Info ");
|
||||
write_info("0.0.0.0", 6950, "IPv4");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool write_info(const char* conn, const int port, const char* ipv)
|
||||
{
|
||||
if (info_win == NULL)
|
||||
return false;
|
||||
mvwprintw(info_win, 1, 2, "Listening: %s:%i", conn, port);
|
||||
mvwprintw(info_win, 2, 2, "IPv: %s", ipv);
|
||||
mvwprintw(info_win, 3, 2, "Connections: 2");
|
||||
mvwprintw(info_win, 4, 2, "Status: Server running");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool setup_log_window(void)
|
||||
{
|
||||
log_win = subwin(stdscr, log_win_size.y, log_win_size.x, info_win_size.y + 1, 0);
|
||||
box(log_win, 0, 0);
|
||||
mvwprintw(log_win, 0, 1, " Log ");
|
||||
log_win_content = derwin(log_win, log_win_size.y - 2, log_win_size.x - 2, 1, 1);
|
||||
if (log_win_content == NULL)
|
||||
{
|
||||
delwin(log_win);
|
||||
PRINT_LINE("Failed to create content log window!");
|
||||
return false;
|
||||
}
|
||||
scrollok(log_win_content, TRUE);
|
||||
for (int i = 0; i < 50; ++i)
|
||||
{
|
||||
wprintw(log_win_content, "Text!%i\n", i);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void calculate_window_sizes(void)
|
||||
{
|
||||
SCR_SIZE scr_size;
|
||||
getmaxyx(stdscr, scr_size.y, scr_size.x);
|
||||
|
||||
info_win_size.y = GET_PERC(scr_size.y, 20);
|
||||
info_win_size.x = scr_size.x-1;
|
||||
|
||||
log_win_size.y = scr_size.y-16;
|
||||
log_win_size.x = GET_PERC(scr_size.x, 50);
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
# server/tui
|
||||
target_sources(netex_svr PRIVATE
|
||||
"info_win.c")
|
|
@ -1,6 +0,0 @@
|
|||
//
|
||||
// Created by max on 10-2-24.
|
||||
//
|
||||
|
||||
#include <ncurses.h>
|
||||
|
Loading…
Reference in New Issue
Block a user