theme.rs

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.

  • ok line 91 · A success line.
    reaches paint, enabled
  • warn line 96 · A warning line.
    reaches paint, enabled
  • err line 101 · An error line.
    reaches paint, enabled
  • heading line 106 · A section heading.
    reaches paint, enabled
  • field line 111 · A label: value line with the value highlighted.
    reaches paint, enabled

WHAT CALLS WHAT

enabled line 68 paint line 82 ok line 91 warn line 96 err line 101 heading line 106 field line 111 entry: a way in: public, and nothing in this file calls it api: public, and also used inside this file helper: private to this file dashed: a call that goes back up, or across a wrapped rank 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 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

ItemLineDocumentation
colour pub mod49Tokyo Night, as 24-bit foreground escape sequences.
enabled fn68
paint pub fn82Wrap text in colour, or return it unchanged when colour is off.
ok pub fn91A success line.
warn pub fn96A warning line.
err pub fn101An error line.
heading pub fn106A section heading.
field pub fn111A label: value line with the value highlighted.