CUI

Components / Data display

Log console

A log view for many thousands of lines, with level filters, search, follow and copy.

Functions: cui_log_append, cui_log_init, cui_log_view

Log console

Usage

static cui_log_line lines[8192];
static char text[512 * 1024];
static cui_log_buffer log;
cui_log_init(&log, lines, 8192, text, sizeof text);   /* once */

log.now = seconds_since_start();                     /* timestamp for the next lines */
cui_log_append(&log, CUI_LOG_WARN, "Physics step took %.1f ms (budget %.1f ms)", step_ms, budget_ms);

cui_log_view(ui, "log", &log, .height = 320, .timestamps = true);

The app owns the storage: an array of line records and a byte buffer for the text, used as a ring. Appending never allocates; when either fills up the oldest lines are dropped, and a line longer than the whole text buffer is cut to fit. The view builds only the rows in sight, so a buffer of many thousands of lines scrolls as fast as a short one, and it keeps a small index of the lines that pass its filter (at most one entry per line slot, freed with the context).

Each line shows its level as a quiet tag (warnings and errors also tint their row), an optional HH:MM:SS.mmm time and the text in the code font. The toolbar filters by level (warning and error counts appear on their toggles, which shorten to initials when the console is narrow), searches as you type (matches are marked and the field counts the lines found), and Follow keeps the newest line in view: scrolling up turns it off, coming back to the bottom turns it on. Copy takes the selected lines or, with no selection, every line shown; Clear empties the buffer. Click a line to select it, drag or Shift+click for a range. With the list focused, the arrows move through lines, Shift+arrows extend the selection, Page Up, Page Down and Home jump, End returns to following, Ctrl+A selects all, Ctrl+C copies and Esc clears the selection.

Keyboard

  • Click a line to select it, drag or Shift+click for a range.
  • With the list focused, the arrows move through lines, Shift+arrows extend the selection, Page Up, Page Down and Home jump, End returns to following, Ctrl+A selects all, Ctrl+C copies and Esc clears the selection.

Options of cui_log_view

OptionTypeDefaultDescription
.widthcui_sizefilldefault fill
.heightfloat320default 320; negative fills the space
.timestampsboolshow each line's time as HH:MM:SS.mmm
.no_toolbarbooljust the lines
.sizefloat12font size, default 12

cui_log_buffer

FieldTypeDescription
nowdoubletimestamp given to the next appended line (seconds)
linescui_log_line *the line records given to cui_log_init
line_capinthow many records lines has room for
textchar *the bytes given to cui_log_init, holding the text of the lines
text_capuint32_tsize of text in bytes
firstintring of lines: oldest record and how many
countintring of lines: oldest record and how many
text_enduint32_twhere the next line's text goes
totaluint64_tlines ever appended; line i of the buffer is number total - count + i
level_countint[CUI_LOG_LEVEL_COUNT]lines of each level now in the buffer, indexed by cui_log_level

cui_log_line

FieldTypeDescription
offsetuint32_twhere the line's text starts in the buffer's text
lenuint32_tbytes of text, not counting the terminator
timedoublethe timestamp it was appended with, in seconds
leveluint8_ta cui_log_level

Related

  • Terminal: Output over an input line, for build logs, a game console or a REPL.
  • Property inspector: A panel of named properties in folding groups, each edited with the control that fits its type.
  • Hex viewer: The bytes of a file or of memory in hex and ASCII, for binary tools, emulators and debuggers.
  • Diff viewer: Compares two versions of a text line by line.