Expand description
Conversion methods for termion’s text style types.
Requires the termion feature.
Termion does not use store the text format in generic data types together with the formatted texts. Instead, if provides separate commands for all formatting options. These commands produce ANSI escape sequencens that can be printed to stdout.
This module defines the Termion trait that is implemented for StyledStr and
StyledString. Its termion method produces an instance of the
TermionStr struct that can be converted into the escape sequences produced by termion
using its Display implementation.
Alternatively, you can use the render function to render a single string and the
render_iter function to render an iterator over strings.
Note that this implementation always uses termion::style::Reset to clear the formatting
instead of termion::style::NoBold etc. for compatibility with terminals that don’t
support the No Bold style.
§Examples
Rendering a single string:
let s = text_style::StyledStr::plain("test").bold();
text_style::termion::render(std::io::stdout(), s)
.expect("Failed to render string");Rendering multiple strings:
let v = vec![
text_style::StyledStr::plain("test").bold(),
text_style::StyledStr::plain(" "),
text_style::StyledStr::plain("test2").italic(),
];
text_style::termion::render_iter(std::io::stdout(), v.iter())
.expect("Failed to render string");Using the Termion trait:
use text_style::termion::Termion;
println!("{}", text_style::StyledStr::plain("test").bold().termion());Structs§
- Termion
Str - A styled string that can be rendered using
termion.
Traits§
- Termion
- Extension trait for producing formatted strings with
termion.
Functions§
- render
- Renders a styled string to the given output using
termion. - render_
iter - Renders multiple styled string to the given output using
termion.