Style
A text style: colors and attributes, applied to a string with paint.
Built by chaining: Style::new().bold().fg(Color::Red). Painting wraps the text in the escape
sequence for the style and a reset (ESC [ 0 m); a style with nothing set returns the text
unchanged. This only builds the strings: whether to emit colors at all (a terminal, NO_COLOR)
is for the caller to decide.
Import
Section titled “Import”Cargo feature ansi (enabled by default). To compile only this module:
or in Cargo.toml:
Definition
Section titled “Definition”Examples
Section titled “Examples”Methods
Section titled “Methods”An empty style: painting with it changes nothing.
Returns
Self — A style with no color and no attribute.
Sets the text color.
Parameters
| Parameter | Type | Description |
|---|---|---|
sel | mut self | |
color | Color | The foreground color. |
Returns
Self — The style with that text color.
Sets the background color.
Parameters
| Parameter | Type | Description |
|---|---|---|
sel | mut self | |
color | Color | The background color. |
Returns
Self — The style with that background.
Makes the text bold.
Parameters
| Parameter | Type |
|---|---|
sel | mut self |
Returns
Self — The style with bold on.
Makes the text dim (faint).
Parameters
| Parameter | Type |
|---|---|
sel | mut self |
Returns
Self — The style with dim on.
italic
Section titled “italic”Makes the text italic.
Parameters
| Parameter | Type |
|---|---|
sel | mut self |
Returns
Self — The style with italic on.
underline
Section titled “underline”Underlines the text.
Parameters
| Parameter | Type |
|---|---|
sel | mut self |
Returns
Self — The style with underline on.
strikethrough
Section titled “strikethrough”Strikes the text through.
Parameters
| Parameter | Type |
|---|---|
sel | mut self |
Returns
Self — The style with strikethrough on.
is_plain
Section titled “is_plain”Whether the style does nothing.
Returns
bool — true for a style with no color and no attribute.
Applies the style to text.
Parameters
| Parameter | Type | Description |
|---|---|---|
text | &str | The text to style. |
Returns
String — The text between the style’s escape sequence and a reset, or the text unchanged for a plain
style.
