mirror of
https://github.com/hmaxnl/netex.git
synced 2025-04-18 19:28:12 +02:00
81 lines
2.0 KiB
C
Executable File
81 lines
2.0 KiB
C
Executable File
#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);
|
|
} |