19 stable releases

1.5.0 Mar 6, 2022
1.4.61 Jan 31, 2024
1.4.5 Nov 17, 2023
1.4.0 Mar 6, 2022
0.1.1 Dec 15, 2020

#242 in Command line utilities

Download history 594/week @ 2024-03-13 344/week @ 2024-03-20 317/week @ 2024-03-27 205/week @ 2024-04-03 101/week @ 2024-04-10 531/week @ 2024-04-17 532/week @ 2024-04-24 338/week @ 2024-05-01 161/week @ 2024-05-08 176/week @ 2024-05-15 401/week @ 2024-05-22 411/week @ 2024-05-29 1091/week @ 2024-06-05 765/week @ 2024-06-12 137/week @ 2024-06-19 88/week @ 2024-06-26

2,118 downloads per month
Used in 2 crates

MIT license

2MB
336 lines

Contains (WOFF font, 290KB) doc/noto-sans-kr-v13-korean-regular.woff, (WOFF font, 190KB) doc/FiraSans-Medium.woff, (WOFF font, 135KB) doc/FiraSans-Medium.woff2, (WOFF font, 185KB) doc/FiraSans-Regular.woff, (WOFF font, 130KB) doc/FiraSans-Regular.woff2, (WOFF font, 69KB) doc/SourceCodePro-Regular.ttf.woff and 11 more.

better_term

A rust crate designed to allow easy styling of terminal output using standard ANSI escape codes.

Usage

Style

A struct used to style output

use better_term::Style;

// prints out Hello world! underlined and bold
let style = Style::default().underline().bold();

println!("{}Hello, world!", style);

Color

A struct used to be simple for just changing colors

use better_term::Color;

// prints Hello, world! in green and red
println!("{}Hello, {}world!", Color::BrightGreen, Color::BrightRed);

Flushing Styles and Colors

It may be useful to reset all the changes you have made, and go back to the default output style. the flush_styles() function is meant for this.

use better_term::{flush_styles};

// prints the text in rainbow colors
println!("{}This is red!", Color::Red);

// clear all colors and styles to reset to default
flush_styles();
println!("This is normal!");

Input

use better_term::{read_input, yesno_prompt};

// gets a string from stdin, with a prompt
let input: String = read_input!("Please enter a value: ");

// gets true if the user enters a value for yes, and false if the user enters no
let prompt: bool = yesno_prompt!("Are you sure you want to enter {}?", input);

// ...

Fancy

The fancy feature is not enabled by default. It currently adds the gradient() function which will return a gradient from a start color to an end color with a given length.
More tools are planned for this feature in the future.

use better_term::fancy::gradient;
use better_term::Color;

// prints a gradient from red to green with 10 steps
let gradient = gradient((255, 0, 0), (0, 255, 0), 10);
for color in gradient {
    println!("{}Hello, world!", color);
}

No runtime deps

Features