#termal #codes #proc #ansi #testing #linux

macro termal_proc

Rust library for fancy colored cli using ansi codes

6 stable releases

Uses new Rust 2024

new 2.1.2 May 2, 2025
2.1.1 Apr 1, 2025
2.0.0 Jan 28, 2025
1.1.0 Aug 6, 2024
1.0.0 Jan 24, 2024

#4 in #termal

Download history 13/week @ 2025-01-12 19/week @ 2025-01-19 110/week @ 2025-01-26 63/week @ 2025-02-02 71/week @ 2025-02-09 26/week @ 2025-02-16 33/week @ 2025-02-23 25/week @ 2025-03-02 27/week @ 2025-03-09 28/week @ 2025-03-16 16/week @ 2025-03-23 114/week @ 2025-03-30 33/week @ 2025-04-06 20/week @ 2025-04-13 28/week @ 2025-04-20 80/week @ 2025-04-27

167 downloads per month
Used in 4 crates (via termal)

Custom license

270KB
5K SLoC

Termal

crates.io donwloads

Rust library for terminal features.

RAW terminal support

  • Unix (linux)
  • Windows (not tested)

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 = "2.1.1"

Features

  • raw: enable features for raw terminal.
  • term_image: enables functionality for drawing images to terminal.
  • image: enables term_image and dependency for image with impl for Image trait.
  • term_text: enable features for basic parsing of ansi escape codes.
  • all: enable all features.

Dependencies

~1–1.5MB
~29K SLoC