add log message buffer

The log message buffer is used to display in
the ncurses log window even those messages
logged before ncurses has started.
This commit is contained in:
Christian Giese
2022-11-02 17:52:51 +01:00
committed by Christian Giese
parent 842d0103e4
commit b41d4947ab
5 changed files with 87 additions and 8 deletions
+6 -1
View File
@@ -23,7 +23,11 @@
bbl_ctx_s *g_ctx = NULL;
/* Global Variables */
bool g_interactive = false; /* interactive mode using ncurses */
bool g_interactive = false; /* interactive mode using ncurses */
uint8_t g_log_buf_cur = 0;
char *g_log_buf = NULL;
bool g_init_phase = true;
bool g_traffic = true;
bool g_banner = true;
@@ -444,6 +448,7 @@ main(int argc, char *argv[])
break;
case 'I':
interactive = true;
bbl_interactive_log_buf_init();
break;
case 'S':
g_ctx->ctrl_socket_path = optarg;
+46
View File
@@ -57,6 +57,51 @@ uint32_t g_session_selected = 1;
extern const char banner[];
/*
* The log message buffer is used to display in the ncurses log window
* even those messages logged before ncurses has started.
*/
extern char *g_log_buf;
extern uint8_t g_log_buf_cur;
void
bbl_interactive_log_buf_init()
{
if(g_log_buf) {
free(g_log_buf);
}
g_log_buf = calloc(LOG_BUF_LINES, LOG_BUF_STR_LEN);
g_log_buf_cur = 0;
}
static void
bbl_interactive_log_buf_free()
{
int i = 0;
char *line = NULL;
if(!g_log_buf) {
return;
}
for(i = g_log_buf_cur; i < LOG_BUF_LINES; i++) {
line = g_log_buf+(i*LOG_BUF_STR_LEN);
if(!strnlen(line, LOG_BUF_STR_LEN)) {
break;
}
wprintw(log_win, "%s", line);
}
for(i = 0; i < g_log_buf_cur; i++) {
line = g_log_buf+(i*LOG_BUF_STR_LEN);
if(!strnlen(line, LOG_BUF_STR_LEN)) {
break;
}
wprintw(log_win, "%s", line);
}
wrefresh(log_win);
free(g_log_buf);
g_log_buf = NULL;
}
/*
* Format a progress bar.
*/
@@ -680,6 +725,7 @@ bbl_interactive_init()
bbl_interactive_init_window();
wrefresh(stats_win);
bbl_interactive_log_buf_free();
g_interactive = true;
}
+3
View File
@@ -11,6 +11,9 @@
#ifndef __BBL_INTERACTIVE_H__
#define __BBL_INTERACTIVE_H__
void
bbl_interactive_log_buf_init();
void
bbl_interactive_init();