#tui #terminal #user-interface #ansi-codes #terminal-text #colored-text #color-printing

termint

Library for colored printing and Terminal User Interfaces

8 unstable releases (3 breaking)

new 0.4.2 Apr 11, 2024
0.4.1 Mar 26, 2024
0.3.1 Feb 27, 2024
0.2.0 Jan 30, 2024
0.1.1 Jan 27, 2024

#168 in GUI

Download history 5/week @ 2024-01-27 1/week @ 2024-02-17 139/week @ 2024-02-24 18/week @ 2024-03-02 12/week @ 2024-03-09 130/week @ 2024-03-16 87/week @ 2024-03-23 28/week @ 2024-03-30 123/week @ 2024-04-06

371 downloads per month

Custom license

105KB
2.5K SLoC

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(Fg::Cyan));
println!("{}", "Cyan text on white background".fg(Fg::Cyan).bg(Bg::White));
println!("{}", "Bold red text".fg(Fg::Red).modifier(vec![Modifier::Bold]));
println!("{}", "Text with RGB value".fg(Fg::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::new()
    .title("Termint")
    .direction(Direction::Horizontal)
    .border_type(BorderType::Double);

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

// Create block2 and adds span as its child
let mut block2 = Block::new().title("Another");
let span2 = "This is really cool, right?".fg(Fg::Blue);
block2.add_child(span2, Constrain::Percent(100));
// Adds block2 as child of main block
main.add_child(block2, Constrain::Fill);

// Renders the main block which renders all the children
main.render(&Coords::new(1, 1), &Coords::new(30, 8));

image

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.

Dependencies

~230KB