tui.h (1307B)
1 // Copyright 2023, Brian Swetland <swetland@frotz.net> 2 // Licensed under the Apache License, Version 2.0. 3 4 #pragma once 5 6 #include <stdarg.h> 7 8 void tui_init(void); 9 void tui_exit(void); 10 int tui_handle_event(void (*callback)(char* line, unsigned len)); 11 12 void tui_status_rhs(const char* status); 13 void tui_status_lhs(const char* status); 14 15 // Write a line (or multiple lines separated by '\n') to the TUI log 16 // Non-printing and non-ascii characters are ignored. 17 // Lines larger than the TUI log max width (128) are truncated. 18 void tui_printf(const char* fmt, ...); 19 void tui_vprintf(const char* fmt, va_list ap); 20 21 // TUI Channels provide a way for different entities to use a 22 // printf() interface to send log lines to the TUI without 23 // interleaving partial log lines. 24 25 // They contain a line assembly buffer and only send lines to 26 // the TUI log when a newline character is encountered. 27 28 // It is safe for different threads to use different channels 29 // to simultaneously send log lines, but it is NOT safe for 30 // different threads to simultaneously use the same channel. 31 typedef struct tui_ch tui_ch_t; 32 33 int tui_ch_create(tui_ch_t** ch, unsigned flags); 34 void tui_ch_destroy(tui_ch_t* ch); 35 void tui_ch_printf(tui_ch_t* ch, const char* fmt, ...); 36 void tui_ch_vprintf(tui_ch_t* ch, const char* fmt, va_list ap); 37