theme.rs

crates/veilvoice-cli/src/theme.rs

veilvoice-cli · 152 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

152 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 99 · A success line.
    reaches paint, enabled
  • warn line 104 · A warning line.
    reaches paint, enabled
  • err line 109 · An error line.
    reaches paint, enabled
  • heading line 114 · A section heading.
    reaches paint, enabled
  • field line 119 · A label: value line with the value highlighted.
    reaches paint, enabled

WHAT CALLS WHAT

enabled line 76 paint line 90 ok line 99 warn line 104 err line 109 heading line 114 field line 119 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 76"]
    n_paint["paint<br/>line 90"]
    n_ok(["ok<br/>line 99"])
    n_warn(["warn<br/>line 104"])
    n_err(["err<br/>line 109"])
    n_heading(["heading<br/>line 114"])
    n_field(["field<br/>line 119"])
    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#L76" "open the source"
    click n_paint href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-cli/src/theme.rs#L90" "open the source"
    click n_ok href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-cli/src/theme.rs#L99" "open the source"
    click n_warn href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-cli/src/theme.rs#L104" "open the source"
    click n_err href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-cli/src/theme.rs#L109" "open the source"
    click n_heading href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-cli/src/theme.rs#L114" "open the source"
    click n_field href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-cli/src/theme.rs#L119" "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
    subgraph chart_key ["Key"]
        direction LR
        key_entry["entry: a way in: public, and nothing in this file calls it"]
        key_api["api: public, and also used inside this file"]
        key_helper["helper: private to this file"]
    end
    class key_entry entry
    class key_api api
    class key_helper 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 fn76Whether to colour the output, decided once and remembered.
paint pub fn90Wrap text in colour, or return it unchanged when colour is off.
ok pub fn99A success line.
warn pub fn104A warning line.
err pub fn109An error line.
heading pub fn114A section heading.
field pub fn119A label: value line with the value highlighted.