ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
stats.c File Reference

Go to the source code of this file.

Data Structures

struct  stats_table_context_t

Macros

#define TUI_STATS_TITLE_BUFFER_SIZE   160
#define TUI_STATS_FOOTER_BUFFER_SIZE   160
#define TUI_STATS_TEXT_BUFFER_SIZE   4096

Functions

terminal_size_t tui_stats_minimum (const stats_view_t *view)
void tui_stats_render (terminal_size_t size, const void *data)

Macro Definition Documentation

◆ TUI_STATS_FOOTER_BUFFER_SIZE

#define TUI_STATS_FOOTER_BUFFER_SIZE   160

Definition at line 4 of file lib/tui/stats.c.

Referenced by tui_stats_minimum(), and tui_stats_render().

◆ TUI_STATS_TEXT_BUFFER_SIZE

#define TUI_STATS_TEXT_BUFFER_SIZE   4096

Definition at line 5 of file lib/tui/stats.c.

◆ TUI_STATS_TITLE_BUFFER_SIZE

#define TUI_STATS_TITLE_BUFFER_SIZE   160

Definition at line 3 of file lib/tui/stats.c.

Referenced by tui_stats_minimum().

Function Documentation

◆ tui_stats_minimum()

terminal_size_t tui_stats_minimum ( const stats_view_t * view)

Definition at line 52 of file lib/tui/stats.c.

52 {
54 snprintf(title, sizeof(title), " ASCII-CHAT / %-20s LIVE STATS",
55 view->mode);
56 stats_footer(view, footer, sizeof(footer));
57 size_t width = stats_body_width(view) + 4;
58 if (strlen(title) + 1 > width)
59 width = strlen(title) + 1;
60 if (strlen(footer) + 3 > width)
61 width = strlen(footer) + 3;
62 // Both subtitles are shorter than the title. Keep one spare row and column
63 // to avoid terminal auto-wrap/scroll, in addition to the fixed header/footer.
64 return (terminal_size_t){.cols = (int)width, .rows = 10};
65}
unsigned int width
Definition fft.c:24
#define TUI_STATS_FOOTER_BUFFER_SIZE
#define TUI_STATS_TITLE_BUFFER_SIZE
char mode[32]

References stats_view_t::mode, TUI_STATS_FOOTER_BUFFER_SIZE, TUI_STATS_TITLE_BUFFER_SIZE, and width.

◆ tui_stats_render()

void tui_stats_render ( terminal_size_t size,
const void * data )

Definition at line 90 of file lib/tui/stats.c.

90 {
91 const stats_view_t *view = data;
92 frame_buffer_t *buffer = frame_buffer_create(size.rows, size.cols + 64);
93 if (!buffer)
94 return;
95 terminal_capabilities_t caps =
97 terminal_color_mode_t mode = GET_OPTION(color_mode);
98 bool color = mode != TERM_COLOR_NONE &&
100 !GET_OPTION(strip_ansi) &&
101 (mode != TERM_COLOR_AUTO || caps.color_level != TERM_COLOR_NONE);
102 const char *blue = color ? ui_text_color_prefix(LOG_COLOR_DEBUG) : "";
105 buffer, "\033[1m%s ASCII-CHAT / %-20s LIVE STATS\033[0m\033[K\n", blue,
106 view->mode);
107 frame_buffer_printf(buffer, " ");
108 frame_buffer_printf(buffer, "%s", blue);
109 ui_text_render_values(buffer, view->page ? "CONNECTIONS & MODE DETAILS"
110 : "OVERVIEW / rates over ~1 second");
111 frame_buffer_printf(buffer, "\033[K\n");
112 frame_buffer_render_border(buffer, size.cols, blue);
113 ui_layout_t layout;
114 if (ui_layout_measure(size, 3, 1, 2, &layout) != ASCIICHAT_OK) {
115 frame_buffer_destroy(buffer);
116 return;
117 }
118 int available = layout.body_rows > 0 ? layout.body_rows : 1;
119 const ui_table_column_t column = {.heading = "Statistics",
120 .width = size.cols - 4};
121 stats_table_context_t context = {.view = view};
122 ui_table_t table = {
123 .columns = &column,
124 .column_count = 1,
125 .row_count = view->count,
126 .viewport = {.selected = view->selected, .first_visible = view->offset},
127 .cells = stats_cells,
128 .data = &context,
129 .selectable = true};
130 ui_table_render(buffer, &table, 4, 2, size.cols - 2, available);
131 frame_buffer_printf(buffer, "\033[%d;1H", size.rows - 2);
132 frame_buffer_render_border(buffer, size.cols, blue);
133 char footer[TUI_STATS_FOOTER_BUFFER_SIZE];
134 stats_footer(view, footer, sizeof(footer));
135 frame_buffer_printf(buffer, " ");
136 ui_text_render_values(buffer, footer);
137 frame_buffer_printf(buffer, "\033[K");
141 frame_buffer_destroy(buffer);
142}
@ LOG_COLOR_DEBUG
Definition color.h:8
int color_mode
Definition fft.c:26
void frame_buffer_cursor_home(frame_buffer_t *buf)
Append cursor home escape code (\033[H).
void frame_buffer_destroy(frame_buffer_t *buf)
Destroy a frame buffer.
size_t frame_buffer_get_length(const frame_buffer_t *buf)
Get the current content length of the frame buffer.
const char * frame_buffer_get_content(const frame_buffer_t *buf)
Get a pointer to the buffer content.
frame_buffer_t * frame_buffer_create(int rows, int cols)
Create a new frame buffer.
void frame_buffer_printf(frame_buffer_t *buf, const char *fmt,...)
Printf-style append to the buffer.
void frame_buffer_render_border(frame_buffer_t *buf, int cols, const char *color)
Render a horizontal border line (used by both splash and status screens).
struct frame_buffer frame_buffer_t
Opaque frame buffer handle.
@ ASCIICHAT_OK
Definition error_codes.h:50
#define GET_OPTION(field)
Definition options.h:1339
#define options_terminal_settings()
Definition options.h:1287
@ COLOR_SETTING_FALSE
Force colors OFF: disable all colors and logging colors.
Definition options.h:250
terminal_capabilities_t detect_terminal_capabilities(const terminal_options_t *options)
unsigned page
unsigned selected
unsigned offset
unsigned count
int body_rows
Definition ui/layout.h:9
The useful part of ui table column is in heading, width, alignment, ellipsis: together they describe ...
Definition table.h:35
void ui_table_render(frame_buffer_t *out, ui_table_t *t, int row, int col, int width, int height)
Definition table.c:81
const char * ui_text_color_prefix(log_color_t color)
Definition text.c:18
void ui_text_render_values(frame_buffer_t *out, const char *text)
Definition text.c:158
asciichat_error_t ui_controller_write(int fd, const char *data, size_t len)
int ui_controller_active_fd(void)
asciichat_error_t ui_layout_measure(terminal_size_t size, int header, int detail, int footer, ui_layout_t *out)
Definition ui/layout.c:3

References ASCIICHAT_OK, ui_layout_t::body_rows, color_mode, COLOR_SETTING_FALSE, stats_view_t::count, detect_terminal_capabilities(), frame_buffer_create(), frame_buffer_cursor_home(), frame_buffer_destroy(), frame_buffer_get_content(), frame_buffer_get_length(), frame_buffer_printf(), frame_buffer_render_border(), GET_OPTION, LOG_COLOR_DEBUG, stats_view_t::mode, stats_view_t::offset, options_terminal_settings, stats_view_t::page, stats_view_t::selected, TUI_STATS_FOOTER_BUFFER_SIZE, ui_controller_active_fd(), ui_controller_write(), ui_layout_measure(), ui_table_render(), ui_text_color_prefix(), and ui_text_render_values().