Crate termint

Source
Expand description

§termint

Crates.io Version docs.rs Crates.io Total Downloads

Rust library for colored printing and Terminal User Interfaces

§Table of Contents

§Installation:

This library is available on crates.io. You can add it to your projects using cargo:

cargo add termint

§Examples

§Printing colored text

Printing colored text is really easy, you can do it like this:

// Using Span widget
println!("{}", "Cyan text".fg(Color::Cyan));
println!("{}", "Cyan text on white".fg(Color::Cyan).bg(Color::White));
println!("{}", "Bold red text".fg(Color::Red).modifier(Modifier::BOLD));
println!("{}", "Text with RGB value".fg(Color::Rgb(0, 249, 210)));

image

You can see all the colors and modifiers in the documentation.

§More complex layout

You can also create TUIs using this library. This example shows how you can use Block widget and add children to it and creating Layout:

// Creates main block and sets its properties
let mut main = Block::horizontal()
    .title("Termint")
    .border_type(BorderType::Double);

// Creates block1 and adds span as its child
let mut block1 = Block::vertical().title("Sub block");
let span1 = "I like it!".fg(Color::Green).bg(Color::Yellow);
block1.push(span1, Constraint::Percent(100));
// Adds block1 as child of main block
main.push(block1, Constraint::Min(0));

// Creates block2 and adds span as its child
let mut block2 = Block::vertical().title("Another");
let span2 = "This is really cool, right?".fg(Color::Blue);
block2.push(span2, Constraint::Percent(100));
// Adds block2 as child of main block
main.push(block2, Constraint::Fill(1));

// Renders the main block which renders all the children using Buffer
let mut buffer = Buffer::empty(Rect::new(1, 1, 30, 8));
main.render(&mut buffer);
buffer.render();

image

§Usage

Code blocks above are just examples of the usage. To see more about functions, Widgets and more, please visit the documentation.

§Usage:

Code blocks above are just examples of the usage. To see more about functions, Widgets and more, please visit the documentation.

§Technologies

Obviously this library was created in Rust, but I also used library called term-size to get terminal size.

Modules§

buffer
enums
Contains enums for foreground, background and more
geometry
Contains structs for geometry, such as Coords
macros
Contains useful macros
style
term
Contains Term struct
widgets
Contains widgets (Layout, Block, Span) widgets is collection of types that implement Widget trait

Macros§

borders
Macro to combine [Border] sides
help
Makes creating help easier
modifiers
Creates vector with given given Modifiers
paragraph
Creates new paragraph in more simple way