aboutsummaryrefslogtreecommitdiff
path: root/core/tui.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/tui.c')
-rw-r--r--core/tui.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/core/tui.c b/core/tui.c
new file mode 100644
index 0000000..6c27ff5
--- /dev/null
+++ b/core/tui.c
@@ -0,0 +1,86 @@
+enum {
+ PAIR_NORMAL = 0,
+};
+
+char *g_line_buff;
+
+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(value);
+ tui_line(false, l, PAIR_NORMAL, A_NORMAL, "%s : %18s", label, value);
+}
+
+void tui_ulx_field(int l, const char *label, uint64_t value) {
+ assert(label);
+ tui_line(false, l, PAIR_NORMAL, A_NORMAL, "%-4s : %#18lx", label, value);
+}
+
+void tui_float_field(int l, const char *label, float value) {
+ assert(label);
+ tui_line(false, l, PAIR_NORMAL, A_NORMAL, "%-4s : %18.1f", label, value);
+}
+