macro termal_proc

Rust library for fancy colored cli using ansi codes

3 stable releases

1.1.0 Aug 6, 2024
1.0.1 Apr 15, 2024
1.0.0 Jan 24, 2024

#1470 in Procedural macros

Download history 2/week @ 2024-06-20 2/week @ 2024-06-27 2/week @ 2024-07-11 3/week @ 2024-07-18 1/week @ 2024-07-25 103/week @ 2024-08-01 23/week @ 2024-08-08 4/week @ 2024-08-15 3/week @ 2024-08-22 14/week @ 2024-08-29 1/week @ 2024-09-05 16/week @ 2024-09-12 32/week @ 2024-09-19 41/week @ 2024-09-26 15/week @ 2024-10-03

104 downloads per month
Used in termal

Custom license

84KB
1.5K SLoC

Termal

crates.io donwloads

Rust library for terminal features with ansi escape codes.

Currently the library contains the ansii codes, and a special macro. Works for text styles, colors and moving the cursor.

Example

With macro

use termal::*;

// you can use a special macro to inline the color codes, this will write
// italic text with yellow foreground and reset at the end.
printcln!("{'yellow italic}hello{'reset}");

// the macro also supports standard formatting
printcln!("{'yellow italic}{}{'reset}", "hello");

// you can also use short versions of the codes
printcln!("{'y i}{}{'_}", "hello");

// you can also use true colors with their hex codes
printcln!("{'#dd0 i}{}{'_}", "hello");

Without macro

// Move cursor to position column 5 on line 7 and write 'hello' in italic
// yellow

use termal::codes::*;

println!("{}{YELLOW_FG}{ITALIC}hello{RESET}", move_to!(5, 7));

The macros such as move_to! can accept either literals or dynamic values. Its main feature is that if you supply literals, it expands to a string literal with the ansi code. If you however supply dynamic values it expands to a format! macro:

use termal::codes::*;

let a = move_to!(5, 7);
// expands to:
let a = "\x1b[5;7H";

let b = move_to!(2 + 3, 7);
// expands to:
let b = format!("\x1b[{};{}H", 2 + 3, 7);

If you know the values for the arguments you can also use the *c macros:

use termal::formatc;

// the spaces, or the lack of them is important
let a = formatc!("{'move_to5,7}");

Gradients

Youn can create gradients with the function termal::gradient:

use termal::*;

// This will create foreground gradient from the rgb color `(250, 50, 170)`
// to the rgb color `(180, 50, 240)`
printcln!("{}{'_}", gradient("BonnyAD9", (250, 50, 170), (180, 50, 240)));

How to use it

To see all the possible commands and uses see docs.

How to get it

It is available on crates.io:

With cargo

cargo add termal

In Cargo.toml

[dependencies]
termal = "1.0.0"

Dependencies

~1–1.5MB
~30K SLoC