Skip to main content

Crate woad

Crate woad 

Source
Expand description

Minimal ANSI terminal colour codes, for Rust.

woad provides fixed SGR sequences, and stream-conditional sequences that emit only when the destination warrants colour. The decision is the portable half of the woad 0.3.0 colour contract: cached environment inspection, TERM=dumb, and std::io::IsTerminal. It is not a console or TUI framework.

Windows console-mode changes, virtual-terminal gating, and handle currencies are not part of this alpha. console_supports_ansi is always true, which is the non-Windows answer. On Windows a terminal is treated with the Unix rule.

use woad::{reset_for, seq_for, FG_GREEN};

let stdout = std::io::stdout();

println!("{}ok{}", seq_for(FG_GREEN, &stdout), reset_for(&stdout),);

Enums§

ColourPolicy
Prevailing colour policy. Discriminants are the woad 0.3.0 values.

Constants§

BG_BLACK
Background black.
BG_BLUE
Background blue.
BG_BRIGHT_BLACK
Background bright black.
BG_BRIGHT_BLUE
Background bright blue.
BG_BRIGHT_CYAN
Background bright cyan.
BG_BRIGHT_GREEN
Background bright green.
BG_BRIGHT_MAGENTA
Background bright magenta.
BG_BRIGHT_RED
Background bright red.
BG_BRIGHT_WHITE
Background bright white.
BG_BRIGHT_YELLOW
Background bright yellow.
BG_CYAN
Background cyan.
BG_GREEN
Background green.
BG_MAGENTA
Background magenta.
BG_RED
Background red.
BG_WHITE
Background white.
BG_YELLOW
Background yellow.
BLINKING
Blinking (SGR 5).
BOLD
Bold (SGR 1).
FG_BLACK
Foreground black.
FG_BLUE
Foreground blue.
FG_BRIGHT_BLACK
Foreground bright black.
FG_BRIGHT_BLUE
Foreground bright blue.
FG_BRIGHT_CYAN
Foreground bright cyan.
FG_BRIGHT_GREEN
Foreground bright green.
FG_BRIGHT_MAGENTA
Foreground bright magenta.
FG_BRIGHT_RED
Foreground bright red.
FG_BRIGHT_WHITE
Foreground bright white.
FG_BRIGHT_YELLOW
Foreground bright yellow.
FG_CYAN
Foreground cyan.
FG_GREEN
Foreground green.
FG_MAGENTA
Foreground magenta.
FG_RED
Foreground red.
FG_WHITE
Foreground white.
FG_YELLOW
Foreground yellow.
RESET
Reset all attributes.
VERSION
Crate version, SemVer, including the prerelease label.
VERSION_MAJOR
Major component of version.
VERSION_MINOR
Minor component of version.
VERSION_PATCH
Patch component of version.
VERSION_RELSTATUS
Release-status byte of version.

Functions§

blinking_for
Obtains BLINKING when supports_colour is true for target; otherwise "".
bold_for
Obtains BOLD when supports_colour is true for target; otherwise "".
colour_policy
Prevailing colour policy, cached until refresh.
console_supports_ansi
Whether ANSI SGR sequences are known to be interpreted.
fd_is_tty
Whether fd is attached to a terminal.
fd_supports_colour
Whether colour should be emitted for fd.
is_tty
Whether writer is attached to a terminal.
refresh
Drops the cached policy and the cached TERM=dumb flag.
reset_for
Obtains RESET when supports_colour is true for target; otherwise "".
seq_for
Obtains seq when supports_colour is true for writer; otherwise "".
seq_for_absent
Yields seq from the policy alone, as for a null stream.
seq_for_fd
Descriptor equivalent of seq_for.
supports_colour
Whether colour should be emitted for writer.
supports_colour_absent
Whether colour should be emitted when no destination is available.
version
Packed woad version, in the WOAD_VER layout.
version_string
Version string, including the prerelease label.