pub trait Style: Display {
Show 27 methods
// Provided methods
fn as_title(&self) -> Styled<'_, Self> { ... }
fn bold(&self) -> Styled<'_, Self> { ... }
fn italic(&self) -> Styled<'_, Self> { ... }
fn low_color(&self, index: usize) -> Styled<'_, Self> { ... }
fn true_color(&self, red: u8, green: u8, blue: u8) -> Styled<'_, Self> { ... }
fn invisible(&self) -> Styled<'_, Self> { ... }
fn visible(&self) -> Styled<'_, Self> { ... }
fn with_reset(&self) -> Styled<'_, Self> { ... }
fn boxed(&self) -> Styled<'_, Self> { ... }
fn rounded(&self) -> Styled<'_, Self> { ... }
fn horizontal_absolute(&self, pos: usize) -> Styled<'_, Self> { ... }
fn prev_line(&self, count: i32) -> Styled<'_, Self> { ... }
fn save_restore(&self) -> Styled<'_, Self> { ... }
fn clear_till_end(&self) -> Styled<'_, Self> { ... }
fn join_lf(&self, s: String) -> Styled<'_, Self> { ... }
fn red(&self) -> Styled<'_, Self> { ... }
fn green(&self) -> Styled<'_, Self> { ... }
fn yellow(&self) -> Styled<'_, Self> { ... }
fn blue(&self) -> Styled<'_, Self> { ... }
fn purple(&self) -> Styled<'_, Self> { ... }
fn cyan(&self) -> Styled<'_, Self> { ... }
fn light_gray(&self) -> Styled<'_, Self> { ... }
fn pink(&self) -> Styled<'_, Self> { ... }
fn light_green(&self) -> Styled<'_, Self> { ... }
fn light_red(&self) -> Styled<'_, Self> { ... }
fn gray(&self) -> Styled<'_, Self> { ... }
fn colorize_with(&self, with: &str) -> Styled<'_, Self> { ... }
}Expand description
Styling functions for function chaining
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);
// =======--------^ ^.......Every chained function call a new Styled object wraps the previous result like a cabbage.
Provided Methods§
Sourcefn as_title(&self) -> Styled<'_, Self>
fn as_title(&self) -> Styled<'_, Self>
Format as a title for terminal
use statusline::Style;
assert_eq!("\x1b]0;yuki@reimu: /home/yuki\x07", "yuki@reimu: /home/yuki".as_title().to_string());Sourcefn bold(&self) -> Styled<'_, Self>
fn bold(&self) -> Styled<'_, Self>
Prepend bold style. Colors from 16-color palette may shift a bit
use statusline::Style;
assert_eq!("\x1b[1mBOLD text", "BOLD text".bold().to_string());Sourcefn italic(&self) -> Styled<'_, Self>
fn italic(&self) -> Styled<'_, Self>
Prepend italic style
use statusline::Style;
assert_eq!("\x1b[3mItalic text", "Italic text".italic().to_string());Sourcefn 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)
Sourcefn 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.
However, since most GUI terminal emulators in linux do support true color display no worry is usually needed. Just use it as-is
Sourcefn invisible(&self) -> Styled<'_, Self>
fn invisible(&self) -> Styled<'_, Self>
Wrap into “readline invisible” characters, for PS1 output or some other strange things
use statusline::Style;
assert_eq!("\x01invis\x02", "invis".invisible().to_string());Sourcefn visible(&self) -> Styled<'_, Self>
fn visible(&self) -> Styled<'_, Self>
Wrap into “readline invisible” but reverse — for making surroundings invisible.
use statusline::Style;
assert_eq!("\x01\x1b[31m\x02Visible\x01\x1b[0m\x02",
"Visible".visible().red().with_reset().invisible().to_string());Sourcefn with_reset(&self) -> Styled<'_, Self>
fn with_reset(&self) -> Styled<'_, Self>
Add “reset colors and boldness” to the end
use statusline::Style;
assert_eq!("\x1b[31mRED\x1b[0mnormal", "RED".red().with_reset().to_string() + "normal");Sourcefn boxed(&self) -> Styled<'_, Self>
fn boxed(&self) -> Styled<'_, Self>
Wrap into square brackets
use statusline::Style;
assert_eq!("[nya]", "nya".boxed().to_string());Sourcefn rounded(&self) -> Styled<'_, Self>
fn rounded(&self) -> Styled<'_, Self>
Wrap into round brackets
use statusline::Style;
assert_eq!("(nyaah~)", "nyaah~".rounded().to_string());Sourcefn 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
Sourcefn 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 one
Sourcefn save_restore(&self) -> Styled<'_, Self>
fn save_restore(&self) -> Styled<'_, Self>
Wrap into cursor saver — for example for outputting PS1 above the PS1 “line”
Sourcefn clear_till_end(&self) -> Styled<'_, Self>
fn clear_till_end(&self) -> Styled<'_, Self>
Prepends line cleaner
Sourcefn light_gray(&self) -> Styled<'_, Self>
fn light_gray(&self) -> Styled<'_, Self>
Light gray color from 16-color palette (CSI 37)
Sourcefn light_green(&self) -> Styled<'_, Self>
fn light_green(&self) -> Styled<'_, Self>
Light green color (true)
Sourcefn colorize_with(&self, with: &str) -> Styled<'_, Self>
fn colorize_with(&self, with: &str) -> Styled<'_, Self>
String autocolorizer.
Colors self with a “random” color associated with given string with.
with value | Resulting color |
|---|---|
="root" | Red |
| other | Some non-red color |
There are 24 different colors
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.