2019-01-28 07:16:14 +11:00
# Crossterm Style | cross-platform styling.
2019-04-11 07:46:30 +10:00
![Lines of Code][s7] [![Latest Version][s1]][l1] [![MIT][s2]][l2] [![docs][s3]][l3] [![Join us on Discord][s5]][l5]
2019-01-28 07:16:14 +11:00
[s1]: https://img.shields.io/crates/v/crossterm_style.svg
[l1]: https://crates.io/crates/crossterm_style
[s2]: https://img.shields.io/badge/license-MIT-blue.svg
[l2]: ./LICENSE
[s3]: https://docs.rs/crossterm_style/badge.svg
[l3]: https://docs.rs/crossterm_style/
2019-04-11 07:46:30 +10:00
[s5]: https://img.shields.io/discord/560857607196377088.svg?logo=discord
2019-04-12 01:37:06 +10:00
[l5]: https://discord.gg/K4nyTDB
2019-01-28 07:16:14 +11:00
2019-03-11 10:09:41 +11:00
[s7]: https://travis-ci.org/TimonPost/crossterm.svg?branch=master
2019-01-28 07:16:14 +11:00
2019-06-22 02:10:46 +10:00
This crate allows you to style the terminal cross-platform.
2019-01-28 07:16:14 +11:00
It supports all UNIX and windows terminals down to windows 7 (not all terminals are tested see [Tested Terminals ](#tested-terminals ) for more info)
2019-06-22 02:10:46 +10:00
This crate is a sub-crate of [crossterm ](https://crates.io/crates/crossterm ) to style the terminal, and can be use individually.
2019-01-28 07:16:14 +11:00
Other sub-crates are:
- [Crossterm Input ](https://crates.io/crates/crossterm_input )
- [Crossterm Terminal ](https://crates.io/crates/crossterm_terminal )
- [Crossterm Screen ](https://crates.io/crates/crossterm_screen )
- [Crossterm Cursor ](https://crates.io/crates/crossterm_cursor )
2019-05-16 01:53:55 +10:00
When you want to use other modules as well you might want to use crossterm with [feature flags ](https://timonpost.github.io/crossterm/docs/feature_flags.html ).
2019-01-28 07:16:14 +11:00
## Table of contents:
- [Getting started ](#getting-started )
- [Useful links ](#useful-links )
- [Features ](#features )
- [Examples ](#examples )
- [Tested Terminals ](#tested-terminals )
- [Notice ](#notice )
- [Contributing ](#contributing )
- [Authors ](#authors )
- [License ](#license )
## Getting Started
2019-04-11 07:46:30 +10:00
This documentation is only for `crossterm_style` version `0.3` if you have an older version I suggest you check the [Upgrade Manual ](https://github.com/TimonPost/crossterm/blob/master/docs/UPGRADE.md ). Also, check out the [examples ](https://github.com/TimonPost/crossterm/tree/master/crossterm_style/examples ) folders with detailed examples for all functionality of this crate.
2019-01-28 07:16:14 +11:00
Add the `crossterm_style` package to your `Cargo.toml` file.
```
[dependencies]
2019-04-11 07:46:30 +10:00
crossterm_style = "0.3"
2019-01-28 07:16:14 +11:00
```
2019-04-11 07:46:30 +10:00
2019-01-28 07:16:14 +11:00
And import the `crossterm_style` modules you want to use.
```rust
extern crate crossterm_style;
2019-04-11 07:46:30 +10:00
pub use crossterm_style::{color, style, Attribute, Color, ColorType, ObjectStyle, StyledObject, TerminalColor, Colorize, Styler};
2019-01-28 07:16:14 +11:00
```
### Useful Links
- [Documentation ](https://docs.rs/crossterm_input/ )
- [Crates.io ](https://crates.io/crates/crossterm_input )
2019-05-16 01:53:55 +10:00
- [Book ](https://timonpost.github.io/crossterm/docs/styling.html )
2019-04-11 07:46:30 +10:00
- [Examples ](./examples )
2019-01-28 07:16:14 +11:00
## Features
These are the features of this crate:
- Cross-platform
2019-04-11 07:46:30 +10:00
- Multithreaded (send, sync)
- Detailed Documentation
- Few Dependencies
2019-01-28 07:16:14 +11:00
- Styled output
2019-04-11 07:46:30 +10:00
- 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)
2019-05-16 01:53:55 +10:00
- Text Attributes: bold, italic, underscore and crossed word and [more ](https://timonpost.github.io/crossterm/docs/styling.html#attributes ) (Windows 10 and UNIX only)
2019-07-26 03:57:14 +10:00
2019-01-28 07:16:14 +11:00
## Examples
2019-04-11 07:46:30 +10:00
The [examples ](./examples ) folder has more complete and verbose examples.
2019-02-23 01:20:24 +11:00
2019-06-22 02:10:46 +10:00
_style text with attributes_
2019-02-23 01:20:24 +11:00
```rust
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();
```
2019-06-22 02:10:46 +10:00
_style text with colors_
2019-02-23 01:20:24 +11:00
```rust
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);
```
2019-06-22 02:10:46 +10:00
_style text with RGB and ANSI Value_
2019-02-23 01:20:24 +11:00
```rust
// custom rgb value (Windows 10 and UNIX systems)
println!("{} some colored text", Colored::Fg(Color::Rgb {
2019-01-28 07:16:14 +11:00
r: 10,
g: 10,
b: 10
}));
// custom ansi color value (Windows 10 and UNIX systems)
2019-02-23 01:20:24 +11:00
println!("{} some colored text", Colored::Fg(Color::AnsiValue(10)));
2019-01-28 07:16:14 +11:00
```
2019-04-11 07:46:30 +10:00
2019-01-28 07:16:14 +11:00
## 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
2019-04-11 07:46:30 +10:00
This project is licensed under the MIT License - see the [LICENSE.md ](./LICENSE ) file for details