aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorPaul Oliver <contact@pauloliver.dev>2026-05-30 23:07:06 +0200
committerPaul Oliver <contact@pauloliver.dev>2026-06-02 01:58:34 +0200
commit8041d3697efb5eddef2c6e693248842ca0139590 (patch)
tree5f85a176c0debe2dabab2b52f4b42ac309951567 /ui
parent0df4e501aee0eeaec61217312eddddc077ca53a7 (diff)
adds v1 pop charts (wip)python_server_client
Diffstat (limited to 'ui')
-rw-r--r--ui/curses/ui.c97
1 files changed, 94 insertions, 3 deletions
diff --git a/ui/curses/ui.c b/ui/curses/ui.c
index ce73c01..950f109 100644
--- a/ui/curses/ui.c
+++ b/ui/curses/ui.c
@@ -1,9 +1,9 @@
#include <curses.h>
#include <locale.h>
-#include "tui.c"
-
#define LOG_LINE_COUNT 1024
+#define PANE_AND_MARGIN_WIDTH (PANE_WIDTH + 2)
+#define PANE_WIDTH 27
#define PROC_FIELD_WIDTH 21
#define PROC_PAGE_LINES 12
@@ -27,6 +27,7 @@ enum {
};
enum {
+ PAIR_NORMAL = 0,
PAIR_HEADER = 1,
PAIR_LIVE_PROC = 2,
PAIR_SELECTED_PROC = 3,
@@ -56,6 +57,7 @@ bool g_exit;
bool g_running;
unsigned g_core;
unsigned g_page;
+char *g_line_buff;
bool g_proc_genes;
uint64_t g_proc_scroll;
uint64_t g_proc_field_scroll;
@@ -310,8 +312,97 @@ void gfx_render(const struct Core *core, uint64_t pos, uint64_t zoom, uint64_t p
}
// ----------------------------------------------------------------------------
-// Core page functions
+// TUI functions
// ----------------------------------------------------------------------------
+void tui_line_buff_free(void) {
+ if (g_line_buff) {
+ free(g_line_buff);
+ }
+
+ g_line_buff = NULL;
+}
+
+void tui_line_buff_resize(void) {
+ tui_line_buff_free();
+
+ g_line_buff = calloc(COLS + 1, sizeof(char));
+}
+
+void tui_line(bool clear, int line, int color, int attr, const char *format, ...) {
+ assert(line >= 0);
+ assert(format);
+
+ if (line >= LINES) {
+ return;
+ }
+
+ if (clear) {
+ move(line, 0);
+ clrtoeol();
+ }
+
+ va_list args;
+
+ attron(COLOR_PAIR(color) | attr);
+ va_start(args, format);
+
+ vsnprintf(g_line_buff, COLS, format, args);
+ mvprintw(line, 1, "%s", g_line_buff);
+
+ va_end(args);
+ attroff(COLOR_PAIR(color) | attr);
+}
+
+void tui_clear_line(int l) {
+ tui_line(true, l, PAIR_NORMAL, A_NORMAL, "");
+}
+
+void tui_field(int line, int col, int color, int attr, const char *format, ...) {
+ assert(line >= 0);
+ assert(col >= 0);
+ assert(format);
+
+ if (line >= LINES || col >= COLS) {
+ return;
+ }
+
+ va_list args;
+
+ attron(COLOR_PAIR(color) | attr);
+ va_start(args, format);
+
+ vsnprintf(g_line_buff, COLS - col, format, args);
+ mvprintw(line, col, "%s", g_line_buff);
+
+ va_end(args);
+ attroff(COLOR_PAIR(color) | attr);
+}
+
+void tui_str_field(int l, const char *label, const char *value) {
+ assert(label);
+ assert(strlen(label) <= 4);
+ assert(value);
+ tui_line(false, l, PAIR_NORMAL, A_NORMAL, "%-4s : %18s", label, value);
+}
+
+void tui_ulx_field(int l, const char *label, uint64_t value) {
+ assert(label);
+ assert(strlen(label) <= 4);
+ tui_line(false, l, PAIR_NORMAL, A_NORMAL, "%-4s : %#18lx", label, value);
+}
+
+void tui_uld_field(int l, const char *label, uint64_t value) {
+ assert(label);
+ assert(strlen(label) <= 4);
+ tui_line(false, l, PAIR_NORMAL, A_NORMAL, "%-4s : %#18ld", label, value);
+}
+
+void tui_float_field(int l, const char *label, float value) {
+ assert(label);
+ assert(strlen(label) <= 4);
+ tui_line(false, l, PAIR_NORMAL, A_NORMAL, "%-4s : %18.1f", label, value);
+}
+
void tui_print_core(int l) {
tui_line(false, ++l, PAIR_HEADER, A_BOLD, "CORE [%d]", g_core);
tui_ulx_field(++l, "cycl", g_cores[g_core].cycl);