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.

Overview

'ansi' - a CLI utility to quickly get ANSI escape codes

This Rust project called ansi-escape-sequences-cli provides an executable called ansi which can be used on the Terminal to easily colorize/style your output.

Install

$ cargo install ansi-escape-sequences-cli (the binary is just called ansi!)

What it returns (you can copy&paste the value!)

Explanation:

  1. returns the sequence in a "regular characters only"-form (for copy & paste), i.e. the ESC-code is escaped
  2. same, but seen on the byte-level
  3. returns the ESC-code directly, unescaped (harder to copy%paste) what output looks like

Usage example 1: in Terminal

$ echo "$(ansi bg-purple)Hello World $(ansi reset)$(ansi red)$(ansi bold)$(ansi underline)Red Warning$(ansi reset)"

Colorful example of terminal output

Usage example 2: multiple uses in a bash script

test.sh

# with "-e" we can prevent unnecessary ASCII-escaping of the "ESC" symbol
# otherwise it can happen that your shell script outputs 
# "Foo=\e[31mbar" instead of the colored/styled output you wanted
reset=$(ansi -e reset)
red=$(ansi -e red)
echo "Foo=${red}bar"
echo "Bar=${reset}foo"

zsh auto completion file

In res/zsh-completion/_ansi is a completion file. Install it for example into /usr/local/share/zsh/site-functions/.

How does it differ from tput?

It is simpler and you can use color names like green and red. In tput you need to know the color indices, like here: https://unix.stackexchange.com/questions/269077/tput-setaf-color-table-how-to-determine-color-codes

Options/Parameters

Image of colorful help page, text version is below 1:1 copy of "help"-page

ANSI-ESCAPE-SEQUENCES-CLI ('ansi') @ version 0.1.1
Made by Philipp Schuster <[email protected]>
See - https://crates.io/crates/ansi-escape-sequences-cli or
      https://github.com/phip1611/ansi-escape-sequences-cli
----------------------------------------------------
SYNOPSIS:
 ansi red|green|bold|strike|bg-cyan|... 
      [-n|--new-line] [-e|--no-escape] [-h|--help]
      [-s|--escape-style bash|unicode|unicode-rust|hex]
PARAMETERS:
  -n: add new line character to output (default: false)
  -e: don't escape 'ESC'-symbol, i.e. return the real ASCII value of `ESC` instead of `\e`
  -s: only useful if `-e` is NOT provided: style of the `ESC`-character-escaping
COMMANDS:
  For a full list visit: https://crates.io/crates/ansi-escape-sequences-cli
  The most basic ones are all supported. For example:
    reset
    black
    bg-black
    red
    bg-red
    green
    bg-green
    yellow
    bg-yellow
    blue
    bg-blue
    purple
    bg-purple
    cyan
    bg-cyan
    white
    bg-white
    normal
    bold
    dimmed
    italic
    underline
    blink
    hidden (hidden)
    strike | strikethrough
ESCAPE STYLES
  bash:         Bash (and many other tools) support `\e` as escaped version of `ESC` code
  hex:          Many tools allow hex values in the following notation: `\x1b`, i.e. an escaped version of `ESC` code.
  unicode     : Many tools allow unicode values in the following notation: `\u001b`, i.e. an escaped version of `ESC` code.
  unicode-rust: Rust uses unicode in the following form: `\u{1b}`, i.e. an escaped version of `ESC` code.

FAQ/Troubleshooting

red is not red, blue is not blue

Your Terminal app may uses a theme that doesn't follow the convention/specification for ANSI escape sequences and the corresponding colors. See https://handwiki.org/wiki/ANSI_escape_code#Colors for example. There nothing that this utility can do in these cases to prevent "wrong colors" by "non standard" themes.

You might also like...
Sniffer - a tool to quickly inspect csv and flat-file files for basic information
Sniffer - a tool to quickly inspect csv and flat-file files for basic information

sniffer sniffer is a tool to quickly inspect csv and flat-file files for basic information. Need to see how many rows are in a csv file? Want to see t

A cargo subcommand for checking and applying updates to installed executables

cargo-update A cargo subcommand for checking and applying updates to installed executables Documentation Manpage Installation Firstly, ensure you have

Use Git installed in Bash on Windows/Windows Subsystem for Linux (WSL) from Windows and Visual Studio Code (VSCode)

WSLGit This project provides a small executable that forwards all arguments to git running inside Bash on Windows/Windows Subsystem for Linux (WSL). T

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

Chemical structure generation for protein sequences as SMILES string.
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

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

Utility library for some Lenovo IdeaPad laptops. Supports IdeaPad Intel and AMD Models (15IIL05 and 15ARE05)

ideapad A Rust utility library for some Lenovo IdeaPad specific functionality. A Fair Warning This crate calls raw ACPI methods, which on the best cas

A CLI tool to get help with CLI tools 🐙
A CLI tool to get help with CLI tools 🐙

A CLI tool to get help with CLI tools 🐙 halp aims to help find the correct arguments for command-line tools by checking the predefined list of common

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

Vari 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 "co

Releases(v0.1.3)
Owner
Philipp Schuster
Hello, I'm Philipp. I'm studying computer science at TU Dresden and I love coding. I'm especially interested in operating systems and low-level code.
Philipp Schuster
Terminal text styling via ANSI escape sequences.

Iridescent Features iridescent is a library for styling terminal text easily. It supports basic ANSI sequences, Xterm-256 colors, and RGB. You can ope

Rob 2 Oct 20, 2022
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
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
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 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
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
A CLI tool that allow you to create a temporary new rust project using cargo with already installed dependencies

cargo-temp A CLI tool that allow you to create a new rust project in a temporary directory with already installed dependencies. Install Requires Rust

Yohan Boogaert 61 Oct 31, 2022
colorStyle is a library of styles for command-line text write in Rust.

Colorstyle colorStyle is a library of styles for command-line text. Inspired by flylog/colorstyle (golang) Example let text = colorstyle::green("gre

Code Translation 6 Nov 12, 2022
omekasy is a command line application that converts alphanumeric characters in your input to various styles defined in Unicode.

omekasy is a command line application that converts alphanumeric characters in your input to various styles defined in Unicode. omekasy means "dress up" in Japanese.

null 105 Nov 16, 2022
A simple solution for scoped styles in Leptos

Styled: Easy Styling for Leptos Components If you're looking for an easy way to apply scoped styles to your Leptos components, Styled is the Leptos ma

Eran Boodnero 8 Mar 5, 2023