#color #terminal-colors #crossterm #attributes #style #terminal #ansi-colors

deprecated crossterm_style

A cross-platform library styling the terminal output

11 releases (4 breaking)

0.5.2 Oct 21, 2019
0.4.1 Aug 2, 2019
0.4.0 Jul 26, 2019
0.2.0 Feb 22, 2019

#32 in #crossterm

Download history 233/week @ 2023-11-27 156/week @ 2023-12-04 195/week @ 2023-12-11 264/week @ 2023-12-18 161/week @ 2023-12-25 130/week @ 2024-01-01 385/week @ 2024-01-08 318/week @ 2024-01-15 291/week @ 2024-01-22 194/week @ 2024-01-29 251/week @ 2024-02-05 260/week @ 2024-02-12 236/week @ 2024-02-19 358/week @ 2024-02-26 306/week @ 2024-03-04 141/week @ 2024-03-11

1,081 downloads per month

MIT license

55KB
866 lines

Lines of Code Latest Version MIT docs Join us on Discord

Crossterm Style

The crossterm_style crate is deprecated and no longer maintained. The GitHub repository will be archived soon. All the code is being moved to the crossterm crate. You can learn more in the Merge sub-crates to the crossterm crate issue.

This crate allows you to work with the terminal colors and text attributes. It supports all UNIX and Windows terminals down to Windows 7 (not all terminals are tested, see the Tested Terminals for more info).

crossterm_style is a sub-crate of the crossterm crate. You can use it directly, but it's highly recommended to use the crossterm crate with the style feature enabled.

Features

  • Cross-platform
  • Multi-threaded (send, sync)
  • Detailed documentation
  • Few dependencies
  • Styled output
    • Foreground color (16 base colors)
    • Background color (16 base colors)
    • 256 (ANSI) color support (Windows 10 and UNIX only)
    • RGB color support (Windows 10 and UNIX only)
    • Text attributes like bold, italic, underscore, crossed word, etc.

Getting Started

Click to show Cargo.toml.
[dependencies]
# All crossterm features are enabled by default.
crossterm = "0.11"

Attributes

use crossterm::{Colored, Color, Colorize, Styler, Attribute};

// pass any `Attribute` value to the formatting braces.
println!("{} Underlined {} No Underline", Attribute::Underlined, Attribute::NoUnderline);

// you could also call different attribute methods on a `&str` and keep on chaining if needed.
let styled_text = "Bold Underlined".bold().underlined();
println!("{}", styled_text);

// old-way but still usable
let styled_text = style("Bold Underlined").bold().underlined();

Colors

use crossterm::{Colored, Color, Colorize};

println!("{} Red foreground color", Colored::Fg(Color::Red));
println!("{} Blue background color", Colored::Bg(Color::Blue));

// you can also call different coloring methods on a `&str`.
let styled_text = "Bold Underlined".red().on_blue();
println!("{}", styled_text);

// old-way but still usable
let styled_text = style("Bold Underlined").with(Color::Red).on(Color::Blue);

RGB Colors and ANSI Values

use crossterm::{Colored, Color, Colorize};

// custom rgb value (Windows 10 and UNIX systems)
println!("{} some colored text", Colored::Fg(Color::Rgb {
    r: 10,
    g: 10,
    b: 10
}));

// custom ansi color value (Windows 10 and UNIX systems)
println!("{} some colored text", Colored::Fg(Color::AnsiValue(10)));

Other Resources

Authors

  • Timon Post - Project Owner & creator

License

This project is licensed under the MIT License - see the LICENSE file for details

Dependencies

~31–445KB