#include <ncurses.h>
#include "ctx.h"
+#include "logging.h"
#include "stats.h"
#include "tui.h"
#include "util.h"
// The graph inside the frame
WINDOW* graph;
+ // The log window
+ WINDOW* log;
+
// The status bar
WINDOW* status;
};
+void fireperf_tui_log(void* data, int priority, const char* file,
+ int line, const char* fn, const char* format, va_list args) {
+ struct fireperf_tui* tui = data;
+ char buffer[1024];
+ ssize_t length;
+ int rows;
+ int cols;
+
+ // Fetch the dimensions of the log window
+ getmaxyx(tui->log, rows, cols);
+
+ // We leave one character free on the left and the right
+ cols -= 2;
+
+ // Format the message
+ length = vsnprintf(buffer, sizeof(buffer), format, args);
+ if (length < 0)
+ return;
+
+ // Scroll down the previous content to add an extra line
+ scroll(tui->log);
+
+ // Remove the trailing newline
+ length--;
+
+ // If the message is long
+ if (length > cols)
+ length = cols;
+
+ // Write the message
+ mvwaddnstr(tui->log, rows - 1, 1, buffer, length);
+
+ wrefresh(tui->log);
+
+ return;
+}
+
static const struct fireperf_stats* fireperf_tui_get_stats(struct fireperf_tui* tui, int i) {
return &tui->stats[(tui->s - i) % MAX_STATS];
}
int r;
// Create the graph
- tui->graph = newwin(LINES - 3, COLS - 3, 1, 1);
+ tui->graph = newwin(LINES - 13, COLS - 3, 1, 1);
if (!tui->graph)
return 1;
int r;
// Create the window
- tui->frame = newwin(LINES - 1, COLS, 0, 0);
+ tui->frame = newwin(LINES - 11, COLS, 0, 0);
if (!tui->frame)
return 1;
return 0;
}
-
static int fireperf_tui_update_status(struct fireperf_tui* tui) {
const struct fireperf_stats* stats = NULL;
char buffer[32];
return 0;
}
+static int fireperf_tui_setup_log(struct fireperf_tui* tui) {
+ int r;
+
+ // Create the window
+ tui->log = newwin(10, COLS, LINES - 11, 0);
+ if (!tui->log)
+ return 1;
+
+ // Enable scrolling in the window
+ scrollok(tui->log, 1);
+
+ // Refresh
+ wrefresh(tui->log);
+
+ return 0;
+}
+
static int fireperf_tui_setup_status(struct fireperf_tui* tui) {
int r;
if (r)
return r;
+ // Setup the log window
+ r = fireperf_tui_setup_log(tui);
+ if (r)
+ return r;
+
// Setup the status bar
r = fireperf_tui_setup_status(tui);
if (r)
if (r)
return r;
+ // Hijack log messages
+ fireperf_set_log_callback(ctx, fireperf_tui_log, t);
+
// Return the TUI
*tui = t;