#style #color #crossterm #terminal #attributes

crossterm_style

A cross-platform library styling the terminal output

6 releases

✓ Uses Rust 2018 edition

new 0.3.3 May 20, 2019
0.3.2 May 15, 2019
0.3.1 Apr 11, 2019
0.2.0 Feb 22, 2019
0.1.0 Jan 27, 2019

#2 in Encoding

Download history 113/week @ 2019-02-04 145/week @ 2019-02-11 119/week @ 2019-02-18 118/week @ 2019-02-25 137/week @ 2019-03-04 478/week @ 2019-03-11 609/week @ 2019-03-18 619/week @ 2019-03-25 449/week @ 2019-04-01 445/week @ 2019-04-08 402/week @ 2019-04-15 596/week @ 2019-04-22 539/week @ 2019-04-29 461/week @ 2019-05-06 653/week @ 2019-05-13

1,900 downloads per month
Used in 3 crates (1 directly)

MIT license

55KB
912 lines

Crossterm Style | cross-platform styling.

Lines of Code Latest Version MIT docs Join us on Discord

This crate allows you to style te terminal cross-platform. It supports all UNIX and windows terminals down to windows 7 (not all terminals are tested see Tested Terminals for more info)

This crate is a sub-crate of crossterm to style te terminal, and can be use individually.

Other sub-crates are:

When you want to use other modules as well you might want to use crossterm with feature flags.

Table of contents:

Getting Started

This documentation is only for crossterm_style version 0.3 if you have an older version I suggest you check the Upgrade Manual. Also, check out the examples folders with detailed examples for all functionality of this crate.

Add the crossterm_style package to your Cargo.toml file.

[dependencies]
crossterm_style = "0.3"

And import the crossterm_style modules you want to use.

extern crate crossterm_style;

pub use crossterm_style::{color, style, Attribute, Color, ColorType, ObjectStyle, StyledObject, TerminalColor, Colorize, Styler};

Useful Links

Features

These are the features of this crate:

  • Cross-platform
  • Multithreaded (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: bold, italic, underscore and crossed word and more (Windows 10 and UNIX only)

Examples

The examples folder has more complete and verbose examples.

style font with attributes

use crossterm_style::{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();

style font with colors

use crossterm_style::{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);

style font with RGB and ANSI Value

// 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)));

Tested terminals

  • Windows Powershell
    • Windows 10 (pro)
  • Windows CMD
    • Windows 10 (pro)
    • Windows 8.1 (N)
  • Ubuntu Desktop Terminal
    • Ubuntu 17.10
  • (Arch, Manjaro) KDE Konsole
  • Linux Mint

This crate supports all Unix terminals and windows terminals down to Windows 7 but not all of them have been tested. If you have used this library for a terminal other than the above list without issues feel free to add it to the above list, I really would appreciate it.

Authors

  • Timon Post - Project Owner & creator

License

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

Dependencies

~575KB