Terminal text styling via ANSI escape sequences.

Overview

Iridescent


terminal screenshot showing off styled output

Features

iridescent is a library for styling terminal text easily. It supports basic ANSI sequences, Xterm-256 colors, and RGB. You can operate directly on &str and String types without needing to worry about conversions. It is important to note that not all terminals support all features. While most modern terminals will support up to true RGB colors, certain text modes, such as blink, are not reliable.

Usage

[dependencies]
iridescent = { version = "0.1" }

The only requirement is that you import the Styled trait into the module you plan on using library methods. Once you have declared it at the top of your module, the methods will be available on all &str and String types.

Note that all Styled methods can be chained, as seen in the example above where first we call the foreground method, followed by the bold method. These do not have to be in any specific order.

Using Basic Colors

use iridescent::{constants::GREEN, Styled};

fn main() {
    // Here we can use a built-in method called `.green()` to apply the color.
    // Every basic color has a helper method for the foreground, as this is
    // the most common thing to style.
    let s = "Hello".green().bold();

    // But we could manually do it this way, too. You'll need to import the
    // color codes from the constants file, of course.
    let s2 = "world".foreground(GREEN).bold();

    println!("{}, {}!", s, s2);
}

Using 256-bit & RGB Colors

use iridescent::{Styled, Rgb};

fn main() {
    // We use .foreground() for a 256-bit color; in this case, 155 - or a lime green.
    let s = "Hello".foreground(155).underline();

    // Here we combine a 256-bit color with an RGB color. First, we set the foreground
    // to an RGB value of (4, 11, 214) - some variant of dark blue. Next, we set
    // the background to a value of 195 - a very light, almost white, blue. In 
    // addition, we apply some modes (underline and blink) to our text.
    //
    // As you can see, mixing and matching various sequence types is no problem!
    let s2 = "world"
        .rgb_foreground(Rgb::new(4, 11, 214))
        .background(195)
        .blink();

    println!("{}, {}!", s, s2);
}

See here for all the methods available.

Examples

If you have cloned the iridescent repository, you can run an example with the command cargo run --example <example_name>. You can add features, if needed, with --features <feature_name>.

Example File Description Features
rainbow colors.rs Shows off all base colors in the terminal.
rgb rainbow.rs Shows off both 8-bit and 24-bit depth randomized colors in the terminal. random
modes modes.rs Shows off the various text modes in the terminal.

Feature Flags

Flag Default Description Dependencies
random Disabled Enables the use of Color::random() and Color::random_rgb() rand

License

Iridescent is dual-licensed under either

at your option.

You might also like...
Shell Escape for Typst typesetting system. Linux Only.

Shell Escape for Typst This is a simple shell escape for Typst. It allows you to run shell commands directly from Typst compiler. That said, it does n

Rust library to convert RGB 24-bit colors into ANSI 256 (8-bit) color codes with zero dependencies and at compile-time.
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

convert images to ansi or irc, with a bunch of post-processing filters
convert images to ansi or irc, with a bunch of post-processing filters

img2irc (0.2.0) img2irc is a utility which converts images to halfblock irc/ansi art, with a lot of post-processing filters halfblock means that each

An implementation of Piet's text interface using cosmic-text

piet-cosmic-text Implements piet's Text interface using the cosmic-text crate. License piet-cosmic-text is free software: you can redistribute it and/

 create and test the style and formatting of text in your terminal applications
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

 Amp: A text editor for your terminal.
Amp: A text editor for your terminal.

Amp: A text editor for your terminal. Heavily inspired by Vi/Vim. Amp aims to take the core interaction model of Vim, simplify it, and bundle in the e

A library that creates a terminal-like window with feature-packed drawing of text and easy input handling. MIRROR.

BearLibTerminal provides a pseudoterminal window with a grid of character cells and a simple yet powerful API for flexible textual output and uncompli

Simple macros to write colored and formatted text to a terminal. Based on `termcolor`, thus also cross-platform.
Simple macros to write colored and formatted text to a terminal. Based on `termcolor`, thus also cross-platform.

Bunt: simple macro-based terminal colors and styles bunt offers macros to easily print colored and formatted text to a terminal. It is just a convenie

A little program written in Rust that prints random PNG images to the terminal in text grabbed from an image repo.

Cermic A little program written in Rust that prints random PNG images to the terminal in text grabbed from an image repo. NOTE: As of right now, Cermi

Comments
Releases(v0.2.1)
  • v0.2.1(Oct 20, 2022)

  • v0.2.0(Oct 20, 2022)

    2022.10.19 - v0.2

    • Breaking Consolidated the rgb_foreground and rgb_background methods into foreground and background respectively. This allows for a much simpler user-facing API.
    • The new foreground and background methods now accept any type that can be converted into a ForegroundColor or BackgroundColor.
    • Added From<u8> impl for both ForegroundColor and BackgroundColor.
    • Added From<Rgb> impl for both ForegroundColor and BackgroundColor.
    • Added From<[u8; 3]> impl for the Rgb type.
    • Added From<[u8; 3]> impl for both ForegroundColor and BackgroundColor.
    • Added support for hex string literals (e.g. "#FF0000"):
      • Added From<&str> impl for the Rgb type.
      • Added From<&str> impl for both ForegroundColor and BackgroundColor.
    • Breaking Color has been split into ForegroundColor and BackgroundColor.
    • Breaking The random methods are now a part of the Rgb type and a new-type wrapper over u8, Simple. You can call them like so: Rgb::random() and Simple::random().

    Examples of the new API:

    use iridescent::{Styled, constants::{RED, WHITE}};
    
    fn main() {
        let hello = "Hello".foreground("#ff00ff").bold();
        let world = "world".foreground(&[0, 255, 0]);
        println!("{hello}, {world}!");
    
        let nice = "Nice".foreground(RED).background(WHITE).bold();
        println!("{nice}");
    }
    
    Source code(tar.gz)
    Source code(zip)
Owner
Rob
Rob
View Source, but for terminal escape sequences

Escape Artist Escape Artist is a tool for seeing ANSI escape codes in terminal applications. You interact with your shell just like you normally would

Reilly Wood 8 Apr 16, 2023
Given a set of kmers (fasta format) and a set of sequences (fasta format), this tool will extract the sequences containing the kmers.

Kmer2sequences Description Given a set of kmers (fasta / fastq [.gz] format) and a set of sequences (fasta / fastq [.gz] format), this tool will extra

Pierre Peterlongo 22 Sep 16, 2023
Rust crate to enable ANSI escape code support on Windows.

enable-ansi-support: Enable ANSI escape code support on Windows 10 About This crate provides one function, enable_ansi_support, which allows ANSI esca

Rain 9 Nov 18, 2022
Rust library for ANSI terminal colours and styles (bold, underline)

rust-ansi-term This is a library for controlling colours and formatting, such as red bold text or blue underlined text, on ANSI terminals. View the Ru

Benjamin Sago 407 Jan 2, 2023
A dead simple ANSI terminal color painting library for Rust.

yansi A dead simple ANSI terminal color painting library for Rust. use yansi::Paint; print!("{} light, {} light!", Paint::green("Green"), Paint::red(

Sergio Benitez 169 Dec 25, 2022
Build terminal dashboards using ascii/ansi art and javascript

blessed-contrib Build dashboards (or any other application) using ascii/ansi art and javascript. Friendly to terminals, ssh and developers.

Yaron Naveh 15k Jan 2, 2023
100% stream-based O(n) syntax highlighter for ANSI terminal

Lex-highlighter 100% stream-based $\mathcal O(n)$ syntax highlighter for ANSI terminal Warning This is proof-of-concept implementation and WON't be co

Abiria 10 Nov 17, 2023
📺(tv) Tidy Viewer is a cross-platform CLI csv pretty printer that uses column styling to maximize viewer enjoyment.

??(tv) Tidy Viewer is a cross-platform CLI csv pretty printer that uses column styling to maximize viewer enjoyment.

Alex Hallam 1.8k Jan 2, 2023
Rust crate `needleman_wunsch` of the `fasebare` package: reading FASTA sequences, Needleman-Wunsch alignment

fasebare Rust crate needleman_wunsch of the fasebare package: reading FASTA sequences, Needleman-Wunsch alignment. Synopsis The crate needleman_wunsch

Laurent Bloch 2 Nov 19, 2021
Chemical structure generation for protein sequences as SMILES string.

proteinogenic Chemical structure generation for protein sequences as SMILES string. ?? Usage This crate builds on top of purr, a crate providing primi

Martin Larralde 4 Aug 4, 2022