crates/veilvoice-cli/src/theme.rs
veilvoice-cli · 144 lines · read the source here · or on GitHub
Tokyo Night colouring for the terminal.
The same palette the GUI uses, so the two halves of VeilVoice look like one program. Colour is suppressed when the output is not a terminal, when NO_COLOR is set (the widely-honoured convention), or when TERM=dumb, so piping to a file or a log never produces escape-code soup.
Why a command-line tool has a palette at all
Because the two front-ends are one program. Somebody who uses the desktop application and then runs the binary over SSH should recognise what they are looking at, and the colours carry meaning consistently in both: green for a result, amber for a caveat, red for a refusal, muted for the scope notes that qualify a claim.
Colour is suppressed rather than assumed
Three independent conditions turn it off, and all three are checked: output that is not a terminal, NO_COLOR set to anything at all (the widely-honoured convention), and TERM=dumb. The check runs once through a std::sync::OnceLock rather than per call, because this is used inside loops that print a line per file.
Escape sequences in a log file are worse than no colour: they survive into bug reports, pasted output and issue trackers, where they are noise that obscures the message somebody was trying to show you.
In plain words
The colours and the layout of what the terminal prints.
The same palette the window uses, so the two halves of VeilVoice look like one program. Colour is dropped automatically when the output is going into a file or another program rather than to a person, because escape codes in a log are noise.
WHAT THIS FILE CONTAINS
144 lines defining 7 functions (6 public), 0 types and 0 constants. Everything below is read out of the source, so it cannot disagree with the code.
What happens when it runs. These are the ways in: public, and nothing else in this file calls them, so they are what an outside caller reaches first.
okline 91 · A success line.
reachespaint,enabledwarnline 96 · A warning line.
reachespaint,enablederrline 101 · An error line.
reachespaint,enabledheadingline 106 · A section heading.
reachespaint,enabledfieldline 111 · A label: value line with the value highlighted.
reachespaint,enabled
WHAT CALLS WHAT
The functions this file defines, and the calls between them. An edge means the callee's name appears, called, inside the caller's body. This is a syntactic reading, not a type-resolved one.
The same graph as Mermaid source
%%{init: {"theme":"base","themeVariables":{"background":"#1a1b26","primaryColor":"#1f2335","primaryTextColor":"#c0caf5","primaryBorderColor":"#7aa2f7","secondaryColor":"#16161e","tertiaryColor":"#16161e","lineColor":"#737aa2","textColor":"#c0caf5","mainBkg":"#1f2335","nodeBorder":"#7aa2f7","clusterBkg":"#16161e","clusterBorder":"#2f3549","fontFamily":"ui-monospace, SFMono-Regular, Consolas, monospace","fontSize":"14px"}}}%%
flowchart TD
n_enabled["enabled<br/>line 68"]
n_paint["paint<br/>line 82"]
n_ok(["ok<br/>line 91"])
n_warn(["warn<br/>line 96"])
n_err(["err<br/>line 101"])
n_heading(["heading<br/>line 106"])
n_field(["field<br/>line 111"])
n_err --> n_paint
n_field --> n_paint
n_heading --> n_paint
n_ok --> n_paint
n_paint --> n_enabled
n_warn --> n_paint
click n_enabled href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-cli/src/theme.rs#L68" "open the source"
click n_paint href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-cli/src/theme.rs#L82" "open the source"
click n_ok href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-cli/src/theme.rs#L91" "open the source"
click n_warn href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-cli/src/theme.rs#L96" "open the source"
click n_err href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-cli/src/theme.rs#L101" "open the source"
click n_heading href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-cli/src/theme.rs#L106" "open the source"
click n_field href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-cli/src/theme.rs#L111" "open the source"
classDef entry fill:#1f2335,stroke:#7aa2f7,color:#c0caf5
class n_ok,n_warn,n_err,n_heading,n_field entry
classDef api fill:#1f2335,stroke:#7dcfff,color:#c0caf5
class n_paint api
classDef helper fill:#1f2335,stroke:#bb9af7,color:#c0caf5
class n_enabled helper
This site loads no third-party script, so it cannot run Mermaid; the diagram above is the same nodes and edges drawn by the generator instead. GitHub renders the source below directly.
ITEMS
| Item | Line | Documentation |
|---|---|---|
colour pub mod | 49 | Tokyo Night, as 24-bit foreground escape sequences. |
enabled fn | 68 | |
paint pub fn | 82 | Wrap text in colour, or return it unchanged when colour is off. |
ok pub fn | 91 | A success line. |
warn pub fn | 96 | A warning line. |
err pub fn | 101 | An error line. |
heading pub fn | 106 | A section heading. |
field pub fn | 111 | A label: value line with the value highlighted. |