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§
- Colour
Policy - 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
BLINKINGwhensupports_colouris true fortarget; otherwise"". - bold_
for - Obtains
BOLDwhensupports_colouris true fortarget; 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
fdis attached to a terminal. - fd_
supports_ colour - Whether colour should be emitted for
fd. - is_tty
- Whether
writeris attached to a terminal. - refresh
- Drops the cached policy and the cached
TERM=dumbflag. - reset_
for - Obtains
RESETwhensupports_colouris true fortarget; otherwise"". - seq_for
- Obtains
seqwhensupports_colouris true forwriter; otherwise"". - seq_
for_ absent - Yields
seqfrom 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_VERlayout. - version_
string - Version string, including the prerelease label.