Expand description
Visual text styles and terminal SGR output.
§Style as a value
Style is a small, copyable visual value. It contains optional colors,
an UnderlineStyle, and AttrFlags. Cells store their shared OSC 8
Link separately. Use crate::cell::Cell::set_link to attach a link.
§Open/close versus wrapped rendering
The std::fmt::Display implementation for Style emits the opener: the
SGR sequence (CSI ... m). Following output remains in that style until another style
or reset is written.
The alternate form ({style:#}) emits the matching SGR reset (CSI m).
Used together, {style} and {style:#} wrap a complete
span with a single style value. The SGR reset clears to defaults rather than
restoring a previously active style, so wrap each span independently:
Link uses the same format syntax for OSC 8 hyperlinks:
{link} opens the link and {link:#} closes it. Hyperlink controls
preserve the visual style.
§Attributes and underline
Boolean SGR attributes such as bold, italic, blinking, reverse video,
conceal, and strikethrough live in AttrFlags. Underlining is modeled
separately with UnderlineStyle because SGR supports multiple underline
shapes (4, 4:2, 4:3, 4:4, 4:5) and an independent underline
color.
§SGR encoding
Style emission uses a single CSI … m sequence for all SGR state. Standard
foreground/background colors use 30–37/40–47, bright colors use
90–97/100–107, indexed colors use 38;5;n/48;5;n, true color
uses 38;2;r;g;b/48;2;r;g;b, and underline color uses the colon
subparameter form (58:5:n or 58:2::r:g:b).
ESC [ 1 ; 4:3 ; 38;2;255;128;0 ; 58:2::0:255:255 m
└─┬─┘ └─────────────── SGR parameters ─────────────────────┘ └┬┘
CSI attrs underline fg truecolor ul color finaluse uncurses::color::Color;
use uncurses::style::Style;
// `{style}` writes the opener; `{style:#}` writes the matching closer.
let heading = Style::default().bold().fg(Color::Green);
println!("{heading}Hello{heading:#}");
let emphasis = Style::default().underline();
println!("{emphasis}docs{emphasis:#}");Structs§
- Attr
Flags - Bitflags for SGR text attributes.
- Link
- A shared OSC 8 hyperlink target for a
Cell. - Style
- A copyable visual terminal text style.
Enums§
- Underline
Style - Underline shape encoded in SGR underline parameters.