Skip to content
Kavachकवच

The Terminal: Colors and styles

● Intermediate2 min

Each color or style function takes text and gives it back colored. They nest: an inner style ends only itself.

use std.term

fn main() {
    print(term.red("error:") + " file not found")
    print(term.bold(term.green("done") + " in 2 s"))
    print(term.yellow("warning:") + " " + term.underline("disk") + " almost full")
}

The program ran and printed:

kavach run colors.kav

error: file not founddone in 2 swarning: disk almost full
colors.kav: Kavach code, then what running it prints
FunctionGives s…
term.black(s), term.red(s), term.green(s), term.yellow(s), term.blue(s), term.magenta(s), term.cyan(s), term.white(s), term.gray(s)in that color
term.bold(s)in bold
term.dim(s)faint
term.italic(s)in italics
term.underline(s)underlined

In term.red("a" + term.green("b") + "c"), c is red again: each function resets only its own style.