From: Michael Tremer Date: Thu, 19 Sep 2024 14:52:49 +0000 (+0000) Subject: tui: Add a grid to the graph X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=4e997dd74fcadf821b3fcf77648dedcb9405f220;p=fireperf.git tui: Add a grid to the graph Signed-off-by: Michael Tremer --- diff --git a/src/tui.c b/src/tui.c index 0e6433b..956de21 100644 --- a/src/tui.c +++ b/src/tui.c @@ -29,6 +29,7 @@ #include "ctx.h" #include "stats.h" #include "tui.h" +#include "util.h" #define MAX_STATS 1024 @@ -137,6 +138,7 @@ static int fireperf_tui_setup(struct fireperf_tui* tui) { init_pair(2, COLOR_GREEN, COLOR_BLACK); init_pair(3, COLOR_BLUE, COLOR_BLACK); init_pair(4, COLOR_BLACK, COLOR_WHITE); + init_pair(5, COLOR_YELLOW, COLOR_BLACK); // Enable raw mode raw(); @@ -277,6 +279,7 @@ static size_t fireperf_tui_get_peak_bps(struct fireperf_tui* tui, int max) { */ static int fireperf_tui_draw_graph(struct fireperf_tui* tui) { const struct fireperf_stats* stats = NULL; + char* scale = NULL; int max_x = 0; int max_y = 0; @@ -290,7 +293,30 @@ static int fireperf_tui_draw_graph(struct fireperf_tui* tui) { size_t peak_bps = fireperf_tui_get_peak_bps(tui, max_x); // Figure out how many bps a step represents - double step = peak_bps / (max_y + 1); + double step = peak_bps / (max_y + 0); + + // Make the brush yellow + wattron(tui->graph, COLOR_PAIR(5)); + + // Draw the grid + for (double line = 0; line <= 1; line += 0.25) { + scale = format_size(line * peak_bps, FIREPERF_FORMAT_BITS); + if (!scale) + continue; + + size_t l = strlen(scale); + + // Draw a horizontal line + for (unsigned int x = 0; x < max_x - l - 1; x++) { + mvwaddch(tui->graph, max_y - (max_y * line), x, ACS_HLINE); + } + + // Write the scale + mvwaddnstr(tui->graph, max_y - (max_y * line), max_x - l, scale, l); + free(scale); + } + + wattroff(tui->graph, COLOR_PAIR(5)); // Make the brush red wattron(tui->graph, COLOR_PAIR(1));