pub struct Styled<'a, T: Display + ?Sized> { /* private fields */ }
Expand description
Styled “string”-like object
Can be used instead of raw ANSI sequences because of cleaner interface.
This type is a wrapper around any object which implements Display trait — usually some kind of strings or other simple ogjects. It wraps one style change at a time, making it possible to chain styles to apply them from the innermost to the outermost.
All the magic happens in Style trait.
use statusline::Style;
let hello = "Hello world!";
let styled = hello.boxed().red().bold().with_reset().to_string();
// ^^^^^^^^------=======.............
assert_eq!("\x1b[1m\x1b[31m[Hello world!]\x1b[0m", styled);
// =======--------^ ^.......
This wrapper applies styles only when formatted to string. Formatting results are never saved
and every call to <Styled as ToString>::to_string()
will format the result one more time,
which may lead to different results for special types like the one which tells the exact
moment of time at the std::fmt::Display::fmt
call.
Trait Implementations§
Auto Trait Implementations§
impl<'a, T> Freeze for Styled<'a, T>where
T: ?Sized,
impl<'a, T> RefUnwindSafe for Styled<'a, T>where
T: RefUnwindSafe + ?Sized,
impl<'a, T> Send for Styled<'a, T>
impl<'a, T> Sync for Styled<'a, T>
impl<'a, T> Unpin for Styled<'a, T>where
T: ?Sized,
impl<'a, T> UnwindSafe for Styled<'a, T>where
T: RefUnwindSafe + ?Sized,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Style for T
impl<T> Style for T
Source§fn bold(&self) -> Styled<'_, Self>
fn bold(&self) -> Styled<'_, Self>
Prepend bold style. Colors from 16-color palette may shift a bit Read more
Source§fn low_color(&self, index: usize) -> Styled<'_, Self>
fn low_color(&self, index: usize) -> Styled<'_, Self>
Use colors from 16-color palette, dark version (0 for CSI 31 thru 6 for CSI 37, CSI 30 is black which
is useless)
Source§fn true_color(&self, red: u8, green: u8, blue: u8) -> Styled<'_, Self>
fn true_color(&self, red: u8, green: u8, blue: u8) -> Styled<'_, Self>
Use true color. Note that some terminals lack true color support and will approximate
the result with colors they do support. This may lead to text being completely unreadable. Read more
Source§fn invisible(&self) -> Styled<'_, Self>
fn invisible(&self) -> Styled<'_, Self>
Wrap into “readline invisible” characters, for PS1 output or some other strange things Read more
Source§fn visible(&self) -> Styled<'_, Self>
fn visible(&self) -> Styled<'_, Self>
Wrap into “readline invisible” but reverse — for making surroundings invisible. Read more
Source§fn with_reset(&self) -> Styled<'_, Self>
fn with_reset(&self) -> Styled<'_, Self>
Add “reset colors and boldness” to the end Read more
Source§fn horizontal_absolute(&self, pos: usize) -> Styled<'_, Self>
fn horizontal_absolute(&self, pos: usize) -> Styled<'_, Self>
Set cursor position, the horizontal part, with absolute value. Coordinates are counted
from 1, from line start to line end, which may seem counter-intuitive
Source§fn prev_line(&self, count: i32) -> Styled<'_, Self>
fn prev_line(&self, count: i32) -> Styled<'_, Self>
Move cursor to the beginning of line which is
count
lines above the current oneSource§fn save_restore(&self) -> Styled<'_, Self>
fn save_restore(&self) -> Styled<'_, Self>
Wrap into cursor saver — for example for outputting PS1 above the PS1 “line”
Source§fn clear_till_end(&self) -> Styled<'_, Self>
fn clear_till_end(&self) -> Styled<'_, Self>
Prepends line cleaner
Source§fn join_lf(&self, s: String) -> Styled<'_, Self>
fn join_lf(&self, s: String) -> Styled<'_, Self>
Join current line with fixed one with newline
Source§fn light_gray(&self) -> Styled<'_, Self>
fn light_gray(&self) -> Styled<'_, Self>
Light gray color from 16-color palette (CSI 37)
Source§fn light_green(&self) -> Styled<'_, Self>
fn light_green(&self) -> Styled<'_, Self>
Light green color (true)