pub struct Style { /* private fields */ }std only.Expand description
A piece of text together with the color and attributes to render it with.
Created by style. The setter methods consume and return self, so they
chain. Style implements Display: passing one to out
renders it, and the color depth matches whatever the terminal supports.
§Examples
use cli_forge::{out, style};
out(style("done").green().bold());
out(style("note").hex("#88aaff"));
out(style("ok").rgb(0, 200, 120));Implementations§
Source§impl Style
impl Style
Sourcepub fn hex(self, hex: &str) -> Style
pub fn hex(self, hex: &str) -> Style
Set the foreground to a 24-bit hex color, e.g. "#ff8800".
The leading # is optional; the rest must be exactly six hex digits. An
invalid string leaves the current color unchanged, so the builder never
fails. On terminals without 24-bit support the color is downgraded to the
nearest representable value at render time.
§Examples
use cli_forge::style;
let link = style("https://example.com").hex("#3b82f6").underline();
assert!(link.render().contains("https://example.com"));
// An invalid hex string is ignored rather than panicking.
let plain = style("x").hex("nope");
assert_eq!(plain.render(), "x");Sourcepub fn rgb(self, r: u8, g: u8, b: u8) -> Style
pub fn rgb(self, r: u8, g: u8, b: u8) -> Style
Set the foreground to a 24-bit RGB color.
On terminals without 24-bit support the color is downgraded to the nearest representable value at render time.
§Examples
use cli_forge::style;
let teal = style("ok").rgb(0, 200, 120);
assert!(teal.render().contains("ok"));Sourcepub fn bold(self) -> Style
pub fn bold(self) -> Style
Render the text in bold.
§Examples
use cli_forge::style;
let heading = style("Summary").bold();
assert!(heading.render().contains("Summary"));Sourcepub fn underline(self) -> Style
pub fn underline(self) -> Style
Underline the text.
§Examples
use cli_forge::style;
let link = style("docs").underline();
assert!(link.render().contains("docs"));Sourcepub fn render(&self) -> String
pub fn render(&self) -> String
Render to an owned String, ready to print or store.
Equivalent to formatting the Style via its Display implementation.
The color depth matches the terminal detected for standard output, so on
a pipe or a NO_COLOR environment the result is the plain text.
§Examples
use cli_forge::style;
let s = style("ready").green().render();
assert!(s.contains("ready"));