Provide a string and a style type for terminal formatted output.
I noticed that crates tend to either depend on ansi_term
directly,
and thus lack Windows console support (prior to Windows 10), or include
their own wrapping code around term
.
This crate is an attempt to create a nice usable wrap around term
everyone can use. It should just work with terminfo
terminals, Windows 10
virtual terminal support*, and the Windows console.
* Requires a personal term
branch, for now.
First, add the dependency to Cargo.toml
:
[dependencies]
term-string = { git = "https://github.com/rust-alt/term-string.git" }
// color is a re-exported module from term
use term_string::color::{GREEN, RED};
use term_string::{TermString, TermStyle};
// Create term styles
let style1 = TermStyle::bold() + TermStyle::fg(GREEN) + TermStyle::bg(RED);
let style2 = TermStyle::underline(true);
// Create term string from a style and a string value
let mut ts = TermString::new(style1, "style");
// "1" inherits style1
ts+= "1";
// " : " is un-styled
ts += TermString::from(" : ");
ts += TermString::new(style2, "This is text with style 2");
ts.println();
Linux | OSX |
---|---|
Windows | x86_64 | i686 |
---|---|---|
stable | ||
beta | ||
nightly |