7814
Ta
tiny-c-agent / files
tiny-c-agent / src / tui / theme.h
2.4 KB
1// tiny TUI theme: the TokyoNight `night` palette and the SGR writer. 2// 3// Every colour the TUI writes comes from the active palette, foreground and 4// background alike, so no row falls back to the host terminal's own colours. 5// Truecolor only. 6 7#ifndef TINY_TUI_THEME_H 8#define TINY_TUI_THEME_H 9 10#include <stdbool.h> 11 12#include "util.h" 13#include "config.h" 14 15typedef struct { 16 const char *bg; 17 const char *fg; 18 const char *fg_dark; 19 const char *comment; 20 const char *terminal_black; 21 const char *blue; 22 const char *blue1; 23 const char *blue5; 24 const char *green; 25 const char *green1; 26 const char *magenta; 27 const char *orange; 28 const char *purple; 29 const char *red; 30 const char *teal; 31 const char *yellow; 32} tiny_palette; 33 34// A capture style: a foreground, a background, and the text attributes. 35typedef struct { 36 const char *fg; 37 const char *bg; 38 bool bold; 39 bool italic; 40 bool underline; 41} tiny_style; 42 43// Selects the active palette. Must be called before any drawing. 44void tiny_theme_use(tiny_theme theme); 45 46const char *tiny_normal_fg(void); 47const char *tiny_normal_bg(void); 48const char *tiny_diff_add(void); 49const char *tiny_diff_delete(void); 50 51// One `38;2;r;g;b` / `48;2;r;g;b`, and attributes off then `Normal`. 52void sgr_fg(tui_buf *b, const char *hex); 53void sgr_bg(tui_buf *b, const char *hex); 54void sgr_plain(tui_buf *b); 55 56// A style's own attributes with the defaults spelled out, so a span that names 57// no colour never inherits the one before it. 58void sgr_style(tui_buf *b, const tiny_style *s); 59 60// Inline fg styling: writes `sgrFg(colour)`, text, `sgrFg(Normal)`, so the row's 61// background survives. 62typedef void (*tiny_fg_fn)(tui_buf *b, const char *text); 63void fg_dim(tui_buf *b, const char *text); 64void fg_red(tui_buf *b, const char *text); 65void fg_green(tui_buf *b, const char *text); 66void fg_yellow(tui_buf *b, const char *text); 67void fg_cyan(tui_buf *b, const char *text); 68void fg_blue(tui_buf *b, const char *text); 69void fg_teal(tui_buf *b, const char *text); 70 71// Capture name to colour, mapped the way tokyonight.nvim maps captures. A 72// dotted name falls back to its parent; NULL when nothing matches. 73const tiny_style *tiny_capture_style(const char *capture); 74 75// A heading level (1-based, clamped to 8) with its rainbow tint, and inline code. 76const tiny_style *tiny_heading_style(int level); 77const tiny_style *tiny_inline_code_style(void); 78 79#endif