Termal

Rust library for terminal features with ansi escape codes.

Currently the library contains the ansii codes, and a special macro works only for colors.

Example

With macro

```rust 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

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

use termal::codes::*;

println!("{}{YELLOWFG}{ITALIC}hello{RESET}", moveto!(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: ```rust 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 a = format!("\x1b[{};{}H", 2 + 3, 7); ```

Gradients

Youn can create gradients with the function termal::gradient: ```rust use termal::*;

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

Macro syntax

In there are now 3 macros: formatc, printc and printcln. They are equivalent to format, print and println respectively.

In all of them the same sintax applies:

The color format can contain

the names and hex colors are separated by spaces

Hex colors

The hex colors may have either 1, 2, 3 or 6 digits. They are interpreted as follows: - Single digit colors are interpreted as the digit repeated 6 times (e.g. #B is same as #BBBBBB) - Two digit colors are interpreted as the two digits repeated 3 times (e.g. #AB is same as #ABABAB) - Three digit colors are interpreted as each digit being repeated once (e.g. #ABC is same as #AABBCC) - Six digit colors are interpreted as typical rgb value (that is #RRGGBB)

If you want to set the foreground color you just type the hex code (e.g. #ABCDEF), if you want to set the background color you immidietly follow the hex color by uncerscore (_) (e.g. #ABCDEF_)

List of names

Most of the names have aliases (e.g. writing white and w is the same). Some can be reset, that is done by the same name but starting with underscore (_). Some names may/must have arguments. These are numbers and are supplied by directly writing them after the name, multiple arguments are separated by commas. If the argument is optional it will have the default value written next to it. The commas must be present even if there are no arguments. (e.g. mt5,7 is valid, mt,7 is valid, mt5, is valid, mt, is valid, but mt is not valid)

Ascii
Moving the cursor
Erasing
Styles and colors
Other
Compound