Crate termstyle

Source
Expand description

termstyle: create and test the style and formatting for the text in your terminal applications

termstyle is a library that aims to make it easy to build formatted and styled command line applications.

§Examples

extern crate serde_yaml;
use termstyle::{Color, El, Text};

// example raw yaml file
let example = r#"
- ["plain ", {t: "and bold", b: true}]
- ["plain ", {t: "and red", c: red}]
"#;

// deserialize as yaml (you can use `serde_json::from_str` for json, etc).
let els = termstyle::from_str(serde_yaml::from_str, example).unwrap();

// This could have also been programmatically constructed like this
let expected = vec![
    El::plain("plain ".into()),
    El::Text(Text::new("and bold".into()).bold()),
    El::plain("plain ".into()),
    El::Text(Text::new("and red".into()).color(Color::Red)),
];

assert_eq!(els, expected);

// Render directly to stdout. Can also use `El::paint` to
// do one at a time.
termstyle::paint(&mut ::std::io::stdout(), &els).unwrap();

§Styled Tables

See the documentation for Table

Structs§

Table
A paintable Table
TableRaw
Raw Table type, used only for deserializing.
Text
A piece of text, may be colored, etc

Enums§

Color
Possible Terminal Colors
El
A Element that can be rendered as styled+formatted text using paint().
ElRaw
Raw El type, used only for deserializing.
TextRaw
Raw Text type, used only for deserializing.
TextsRaw
Raw Text type, used so you can specify "foo bar" or ["foo ", "bar"]

Functions§

eprint_diff
Helper function to make tests easier for others.
eprint_repr
Print the byte representation directly to stderr.
from_str
Convert a string into Vec<El> using the given deserializer.
paint
Paint the given elements into the writer.
print_repr
Helper function to make tests easier for others.
write_repr
Helper function to make tests easier for others.