Vari (Väri) is a Rust library for formatting strings with colors and cosmetic stuff to the terminal.

Overview

Logo

Vari

crates.io crates.io crates.io License

Vari (Väri) is a Rust library for formatting strings with colors and cosmetic stuff to the terminal. Like Rich library for Python.

Väri means "color" in Finnish.

Installing

Vari come with color anchors as default feature, The other opt-in features are: "log", "fun",

[dependencies]
vari =  "0.2.1"

Features

Color Anchor

This is in default features.

Color anchor are a bbcode-like markup for colors and styles (eg. "[$red]", "[bg$yellow]", "[$bold]")

Anchors

Colors:

  • [$black]
  • [$red]
  • [$green]
  • [$yellow]
  • [$blue]
  • [$magenta]
  • [$cyan]
  • [$white]
  • [$reset] or [$r] or [$/]

Bright colors:

  • [$bright_black] or [$brightblack]
  • [$bright_red] or [$brightred]
  • [$bright_green] or [$brightgreen]
  • [$bright_yellow] or [$brightyellow]
  • [$bright_blue] or [$brightblue]
  • [$bright_magenta] or [$brightmagenta]
  • [$bright_cyan] or [$brightcyan]
  • [$bright_white] or [$brightwhite]

Styles

  • [$regular]
  • [$bold]
  • [$dim] or [$low] or [$low_intensity] or [$lowintensity]
  • [$italic]
  • [$underline]
  • [$blink] or [$blinking]
  • [$reverse] or [$reversed]
  • [$invisible] or [$hidden]
  • [$strikethrough] or [$strike_through]

Note: [bg$any] is a valid anchors, it will be translated to [$reversed][$any] (where `any` is the color/style name above)

// [$/] is shorthand for [$reset]
let message = vari::format("[$blue]Hello, [$green]World![$/]");
println!("{}", message);

// Custom RGB!
println!("{}", vari::format("[$[114, 119, 39]]#727727![$[66, 4, 32]] Do you see it?[$/]"));

// Style anchor and also easy macros :O
vprintln!("{}Bold and Italic :O{}", "[$bold][$italic]", "[$/]");

// Background color
vprintln!("{}Backgroundssss{}[$/]", "[bg$magenta]", "[bg$[188, 188, 188]]World![$/]")

// Hexadecimal
vprintln!("[$#ffffff]Hello, [$#000000]World![$/]");

Colorize

[dependencies]
vari = { version =  "0.2.1", features = ["colorize"] }

Colorize string directly by calling colorize() method, like colored crate.

For example: "red".colorize("red") is the same as "[$red]red[$/]"

Note: Chaining is not yet implemented, because .colorize() adds [$/] so you can't chain styles

The argument should be the color's name (the same name as the anchor colors).

use vari::colorize::Colorize;

fn main() {
    println!("{}", "Hello, World".colorize("cyan"));
    println!("{}", "This is red".colorize("brightred"));
    println!("{}", "Bold.".colorize("bold"));
}

Log

[dependencies]
vari = { version =  "0.2.1", features = ["log"] }

Some println-ish function for logging

let log_message = vformat!("[$green]This message is send by main.rs![$/]");
let log_file = vformat!("[$dim]src/main.rs[$/]");
vari::util::log(&log_message, &log_file);

logs

No ANSI for .len()

This is in default features.

This might be used in padding calculation, because in colored string (eg. "\x1b[31mTest\x1b[0m"), the length calculated also contains the "[31m" and the "[0m" in it, making the padding incorrect. So this trait implements a ".no_ansi()" which remove all the ANSI escape sequence and then you could do ".len()" after it.

// vari::util::log()

// Calculate padding amount between the message.
// eg. left________right
let padding_amount = w - right.no_ansi().len() - left.no_ansi().len();
let padding = " ".repeat(padding_amount);
        
let mut result = String::new();

result.push_str(left);
result.push_str(&padding);
result.push_str(right);

return result      

no_ansi()

Fun

[dependencies]
vari = { version =  "0.2.1", features = ["fun"] }
fn main() {
    // Rainbow colors!
    println!("{}", vari::fun::rainbow("Rainbow!!!"));
}

License

This crate is under AGPL-3.0 license.

You might also like...
Parse hex colors to tui::style::Color

Color - Tui Parse hex colors to tui rgb colors #c3f111 - Color::Rgb(195,241,17) Note that the indexed colors are NOT HEX #142 - Color::Indexed(142)

Customize window border colors :3
Customize window border colors :3

cute-borders Makes focused and unfocused window borders have a different border color, configurable per program. Windows 11 only. Preview Installing D

STKLR is a tool to help you automatically link up named stuff in your rust docs!

_____ _______ _ ___ _____ / ____|__ __| |/ / | | __ \ | (___ | | | ' /| | | |__) | \___ \ | | | | | | _ / ___

Fmt-rfcs - RFCs for Rust formatting guidelines and changes to Rustfmt

Rust code formatting RFCs This repository exists to decide on a code style for Rust code, to be enforced by the Rustfmt tool. Accepted RFCs live in th

A Turing-complete but dead-simple spaced repetition CLI that helps you learn stuff.

Forne — Learn Stuff Forne is a Turing-complete spaced repetition engine to help you learn stuff your way. What does that mean? Well, there are a few p

Monorepo for dprint—a pluggable and configurable code formatting platform

dprint Monorepo for dprint—a pluggable and configurable code formatting platform. This project is under active early development. I recommend you chec

Sleek is a CLI tool for formatting SQL. It helps you maintain a consistent style across your SQL code, enhancing readability and productivity.

Sleek: SQL Formatter ✨ Sleek is a CLI tool for formatting SQL. It helps you maintain a consistent style across your SQL code, enhancing readability an

Fast, minimal, feature-rich, extended formatting syntax for Rust!

Formatting Tools Fast, minimal, feature-rich, extended formatting syntax for Rust! Features include: Arbitrary expressions inside the formatting brace

Small CLI for escaping and unescaping characters in strings

🐌 esc Small CLI for escaping characters in strings. Install cargo install esc Usage cat LICENSE-MIT | esc escape | pbcopy pbpaste | esc unescape | pb

Releases(v0.2.1)
  • v0.2.1(Jan 15, 2022)

  • v0.1.8(Jan 15, 2022)

    Features

    • no_ansi() str trait for removing ANSI escape sequence.
    • log() println-ish style function for logging with file suffix.

    Fix

    • Anchor splitting ignoring the string if it doesn't end with any color anchor.
    Source code(tar.gz)
    Source code(zip)
  • v0.1.7(Jan 14, 2022)

Owner
azur
stoodent 06:30 - 14:30 sleep schedule
azur
Cross-platform Rust library for coloring and formatting terminal output

Coloring terminal output Documentation term-painter is a cross-platform (i.e. also non-ANSI terminals) Rust library for coloring and formatting termin

Lukas Kalbertodt 75 Jul 28, 2022
create and test the style and formatting of text in your terminal applications

description: create and test the style and formatting of text in your terminal applications docs: https://docs.rs/termstyle termstyle is a library tha

Rett Berg 18 Jul 3, 2021
Rust library to convert RGB 24-bit colors into ANSI 256 (8-bit) color codes with zero dependencies and at compile-time.

rgb2ansi256 rgb2ansi256 is a small Rust library to convert RGB 24-bit colors into ANSI 256 (8-bit) color codes with zero dependencies and const fn. Th

Linda_pp 7 Nov 17, 2022
⚡️Highly efficient data and string formatting library for Rust.

⚡️Highly efficient data and string formatting library for Rust. ?? Overview Pad and format string slices and generic vectors efficiently with minimal

Firelink Data 3 Dec 21, 2023
ratlab is a programming platform designed loosely for hobbyist and masochist to analyse and design stuff and things that transform our world?

ratlab A programming language developed by Quinn Horton and Jay Hunter. ratlab is a programming platform designed loosely for hobbyists and masochists

Jay 10 Sep 4, 2023
Command-Line program that takes images and produces the copy of the image with a thin frame and palette made of the 10 most frequent colors.

paleatra v.0.0.1 Command-Line program that takes an image and produces the copy of the image with a thin frame and palette made of the 10 most frequen

Beka Modebadze 24 Dec 29, 2022
fas stand for Find all stuff and it's a go app that simplify the find command and allow you to easily search everything you nedd

fas fas stands for Find all stuff and it's a rust app that simplify the find command and allow you to easily search everything you need. Note: current

M4jrT0m 1 Dec 24, 2021
A rust crate for working with colors and color spaces.

Color Art A rust crate for working with colors and color spaces. Documentation See Color Art. Usage Add Dependency [dependencies] color-art = "0.2" Co

cx33 5 Dec 30, 2022
A CLI utility installed as "ansi" to quickly get ANSI escape sequences. Supports the most basic ones, like colors and styles as bold or italic.

'ansi' - a CLI utility to quickly get ANSI escape codes This Rust project called ansi-escape-sequences-cli provides an executable called ansi which ca

Philipp Schuster 5 Jul 28, 2022
🍅 A command-line tool to get and set values in toml files while preserving comments and formatting

tomato Get, set, and delete values in TOML files while preserving comments and formatting. That's it. That's the feature set. I wrote tomato to satisf

C J Silverio 15 Dec 23, 2022