#ansi #terminal #color

anstyle-stream

A simple cross platform library for writing colored text to a terminal

7 releases

0.2.2 Mar 16, 2023
0.2.1 Mar 15, 2023
0.1.2 Mar 13, 2023
0.0.1 Mar 8, 2023

#367 in Command-line interface

Download history 50/week @ 2023-03-06 1553/week @ 2023-03-13 187/week @ 2023-03-20 94/week @ 2023-03-27 117/week @ 2023-04-03 149/week @ 2023-04-10 153/week @ 2023-04-17 210/week @ 2023-04-24 338/week @ 2023-05-01

866 downloads per month
Used in winnow

MIT/Apache

175KB
3.5K SLoC

anstyle-stream

A simple cross platform library for writing colored text to a terminal.

Documentation License Crates Status

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

Auto-adapting [stdout] / [stderr] streams

[AutoStream] always accepts ANSI escape codes, adapting to the user's terminal's capabilities.

Benefits

  • Allows the caller to not be concerned with the terminal's capabilities
  • Semver safe way of passing styled text between crates as ANSI escape codes offer more compatibility than most crate APIs.

Example

#  #[cfg(feature = "auto")] {
use anstyle_stream::println;
use owo_colors::OwoColorize as _;

// Foreground colors
println!("My number is {:#x}!", 10.green());
// Background colors
println!("My number is not {}!", 4.on_red());
# }

And this will correctly handle piping to a file, etc

Dependencies

~0–5MB
~84K SLoC