A dead simple ANSI terminal color painting library for Rust.

Related tags

Command-line yansi
Overview

yansi

Build Status Current Crates.io Version Documentation

A dead simple ANSI terminal color painting library for Rust.

use yansi::Paint;

print!("{} light, {} light!", Paint::green("Green"), Paint::red("red").underline());

See the documentation for more.

Why?

Several terminal coloring libraries exist (ansi_term, colored, term_painter, to name a few), begging the question: why yet another? Here are a few reasons:

  • This library is much simpler: there are three types!
  • Unlike ansi_term or colored, any type implementing Display or Debug can be stylized, not only strings.
  • Styling can be enabled and disabled globally, on the fly.
  • Arbitrary items can be masked for selective disabling.
  • Styling can wrap any arbitrarily styled item.
  • Typically only one type needs to be imported: Paint.
  • Zero dependencies. It really is simple.
  • The name yansi is pretty short.

All that being said, this library borrows API ideas from the three libraries as well as implementation details from ansi_term.

License

yansi is licensed under either of the following, at your option:

Comments
  • Remove the `docify!` macro.

    Remove the `docify!` macro.

    This reduces the compile time for a non-incremental cargo check build by about 60%. It also reduces the amount of code and is easier to read because it uses standard Rust macros (concat and stringify) rather than a DSL.

    opened by nnethercote 5
  • Used parking_lot version is quite old

    Used parking_lot version is quite old

    Yansi uses parking_lot version 0.5, which is over 3 years old. Would it be possible to update it? I can see that the last update to Cargo.toml was a version bump, so I don't know if it would need to wait for something else?

    opened by janbaudisch 5
  • Global enable/disable encourages the wrong behavior

    Global enable/disable encourages the wrong behavior

    TTY detection is on a per-stream basis, so a user will need to check stdout and stderr and then change their Style appropriately. yansi's "easy path" is to globally enable/disable color which won't take into account which stream the user is writing to, encouraging people to write incorrect code.

    opened by epage 4
  • incorrect link to docs

    incorrect link to docs

    The link in the readme to the documentation goes to https://docs.rs/yansi/0.3.4/yansi/ , the resulting page says: "The requested resource does not exist"

    docs upstream 
    opened by Anton-4 4
  • Gracefully initialize/auto-detect behind the scenes?

    Gracefully initialize/auto-detect behind the scenes?

    For a CLI app, the user will need to support args and might have other constraints.

    However, passing color information to a deeply nested crate can be impractical. For example, Someone might use mockall which uses predicates which uses difference, and difference wants to print colored diffs, where appropriate.

    Alternatively, some times there isn't a good initialization point for a crate, like with tests. The above example is more likely to live in a test than in a bin.

    Depending on the approach, this might be a counter example to #17.

    Note: this is more brainstorming, I'm unsure how this will look.

    opened by epage 3
  • Encourage colored-output common practices

    Encourage colored-output common practices

    Providing a default path for getting people to follow common practices

    • Will help encourage people to do so
    • Ensure people consistently implement the semantics (including precedence levels)

    Common practices include:

    Since the CLI arg would involve integrating with another crate in the public API (like structopt / clap3), unsure whether that should be left to another crate to avoid coupling their breaking changes to yansi's.

    opened by epage 3
  • Docify crate

    Docify crate

    Would you consider creating a crate with the docify macro? It's pretty clever and it's something I've needed before when writing helper macros but settled for just ignoring docs on functions created with the macro in that case.

    opened by glfmn 3
  • Update docs to call out `Default` constructor for Style

    Update docs to call out `Default` constructor for Style

    Because new was the only constructor listed in the heading, I didn't check for a default and what it meant. It was only after digging through the source that I realized that this was an option and it did what I wanted (nothing).

    opened by epage 2
  • #[feature] may not be used on the stable release channel

    #[feature] may not be used on the stable release channel

    When I use Rocket, cargo run meet this error

    Compiling yansi v0.3.3
    error[E0554]: #[feature] may not be used on the stable release channel
     --> /root/.cargo/registry/src/github.com-1ecc6299db9ec823/yansi-0.3.3/src/lib.rs:1:32
      |
    1 | #![cfg_attr(feature="nightly", feature(const_fn))]
      |                                ^^^^^^^^^^^^^^^^^
    
    error: aborting due to previous error
    
    error: Could not compile `yansi`.
    
    To learn more, run the command again with --verbose.
    
    
    invalid 
    opened by sincerefly 2
  • Console coloring is not working in Windows 7

    Console coloring is not working in Windows 7

    My system info: Microsoft Windows 7 Ultimate 64bit

    Rust info: nightly-i686-pc-windows-gnu (default) rustc 1.21.0-nightly (f774bced5 2017-08-12)

    Cargo.toml: yansi = "0.3.3"

    main.rs: Paint::enable_windows_ascii(); print!("{} light, {} light!",
    Paint::green("Green"), Paint::red("red").underline());

    console output:

    vhh

    invalid 
    opened by zoumi 2
  • Error on stable channel

    Error on stable channel

    How to fix this problem?. this error occured when i try to install rocket

    error[E0554]: #[feature] may not be used on the stable release channel --> $HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/yansi-0.3.3/src/lib.rs:1:32 | 1 | #![cfg_attr(feature="nightly", feature(const_fn))] | ^^^^^^^^^^^^^^^^^^

    error: aborting due to previous error

    error: Could not compile yansi. Build failed, waiting for other jobs to finish... error: build failed

    thanks

    invalid 
    opened by susilolab 2
  • Migrate the crate to edition 2018

    Migrate the crate to edition 2018

    • Migrate the crate to edition 2018
    • Apply rustfmt and clippy to the code
    • Migrate travis CI to GitHub Actions
    • Add Style/Test/MSRV check into CI (Close #38)
    opened by koushiro 2
  • Document and test MSRV

    Document and test MSRV

    Hi, and thanks for the library! I'm the maintainer of pretty_assertions, and am looking and moving from ansi_term to yansi. I couldn't find a documented MSRV, but the build failures point to 1.54.0 as a likely candidate (stabilization of extended_key_value_attributes).

    This PR documents the MSRV and adds it to CI, along with a proposed policy (updating MSRV on minor versions is pretty standard I think?).

    Let me know if you think this is okay, or if any updates are required. I'd like to know what your thoughts are on frequency of the MSRV being updated?

    opened by tommilligan 0
  • Add a feature flag to automate Windows coloring

    Add a feature flag to automate Windows coloring

    Basically, do the following automatically:

    if !Paint::enable_windows_ascii() {
        Paint::disable()
    }
    

    The implementation should just check if painting is disabled via the already relaxed atomic bool and otherwise check a second atomic bool, also relaxes, to see if we've tried to enable Windows coloring already.

    enhancement 
    opened by SergioBenitez 5
  • Support const-fn Style

    Support const-fn Style

    The main limitation is trait support (Default, ==, etc). Hopefully this subset is sufficient for most needs. The main thing I can see adding is a Style::plain since Style::default can't be used.

    Fixes #16

    opened by epage 0
Owner
Sergio Benitez
Sergio Benitez
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
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
Style terminal outputs in a minimal, macro-based, and dead simple way.

sty ?? $\mathbb{\color{red}{Style \ } \color{lightblue}{terminal}\ \color{black}{outputs \ }\color{gray}{\ in\ a} \color{magenta}{\ minimal}\color{gra

斯人 5 Apr 18, 2024
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
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
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
Dead simple, memoized cargo subcommand to hoist cargo-built binaries into the current working directory, written in Rust.

cargo-hoist Dead simple cargo subcommand to hoist cargo-built binaries into scope. stable Install | User Docs | Crate Docs | Reference | Contributing

refcell.eth 6 Nov 9, 2023
Detects whether a terminal supports color, and gives details about that support

Detects whether a terminal supports color, and gives details about that support. It takes into account the NO_COLOR environment variable. This crate i

Kat Marchán 30 Dec 29, 2022
A dead simple functional testing tool for command line applications

Pharaoh : build that test pyramid! What it is Pharaoh is a dead simple, no permission needed, functional test runner for command line applications, wr

Kevin Sztern 17 Dec 13, 2021
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

Sam Brew 9 May 12, 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
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

null 6 Apr 4, 2023
The dead easy way to use config files in your rust project

Configr The dead easy way to use config files in your project This will load a config.toml file if it exists, otherwise it will create the needed fold

Carsten Kragelund Jørgensen 4 Jul 1, 2022
Rust no-BS Dead Man's Switch TUI

Dead Man's Switch This is a simple implementation of a Dead Man's Switch. Use at your own risk. Check the f****(as in friendly) code. Dead man's switc

Jose Storopoli 7 Apr 25, 2024
An abstract, safe, and concise color conversion library for rust nightly This requires the feature adt_const_params

colortypes A type safe color conversion library This crate provides many methods for converting between color types. Everything is implemented abstrac

Jacob 13 Dec 7, 2022
High-performance Javascript color gradient library powered by Rust + WebAssembly

colorgrad-js High-performance Javascript color gradient library powered by Rust + WebAssembly. No dependencies. Faster than d3-scale, chroma-js, culor

Nor Khasyatillah 168 Apr 25, 2023
Tiny color conversion library for TUI application builders

Definition of ANSI, RGB and HSL color types and all the conversions between them. There are many other color conversion crates. This one may be useful

Canop 8 Dec 15, 2022
A simple and efficient terminal UI implementation with ratatui.rs for getting quick insights from csv files right on the terminal

CSV-GREP csv-grep is an intuitive TUI application writting with ratatui.rs for reading, viewing and quickly analysing csv files right on the terminal.

Anthony Ezeabasili 16 Mar 10, 2024
Sanctity is an acronym for rust ansi16 color test utility

sanctity ?? sanctity is an acronym for rust ansi16 color test utility. It prints your own text or the default text in all of the 16 terminal colors.

null 1 Apr 6, 2022