Crates.io | better_term |
lib.rs | better_term |
version | 1.4.61 |
source | src |
created_at | 2020-12-15 10:16:57.764807 |
updated_at | 2024-01-31 01:45:06.530226 |
description | A crate that makes using the terminal easier. |
homepage | |
repository | https://github.com/Sk3pz/better_term |
max_upload_size | |
id | 323058 |
size | 2,108,891 |
A rust crate designed to allow easy styling of terminal output using standard ANSI escape codes.
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);
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);
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!");
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);
// ...
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);
}