#terminal #ansi #console #io

better_term

A crate that makes using the terminal easier

11 stable releases

1.5.0 Mar 6, 2022
1.4.0 Mar 6, 2022
1.3.7 Jan 31, 2023
1.3.6 Aug 31, 2022
0.1.1 Dec 15, 2020

#359 in Command line utilities

Download history 5/week @ 2022-10-14 17/week @ 2022-10-21 36/week @ 2022-10-28 69/week @ 2022-11-04 32/week @ 2022-11-11 24/week @ 2022-11-18 21/week @ 2022-11-25 8/week @ 2022-12-02 38/week @ 2022-12-09 24/week @ 2022-12-16 33/week @ 2022-12-23 26/week @ 2022-12-30 89/week @ 2023-01-06 43/week @ 2023-01-13 159/week @ 2023-01-20 93/week @ 2023-01-27

387 downloads per month
Used in pbars

MIT license

2MB
343 lines

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, rainbowify};

// prints the text in rainbow colors
println!("{}", rainbowify("This is rainbow!!!!!"));

// clear all colors and styles to reset to default
flush_styles();

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);

// ...

No runtime deps

Features

  • input
  • output