#color #style #traits

nightly colors

A library that helps you color and style your text

1 unstable release

Uses old Rust 2015

0.0.1 Nov 24, 2014

#281 in #style

MIT license

570KB
858 lines

Contains (WOFF font, 120KB) doc/Heuristica-Italic.woff, (WOFF font, 90KB) doc/FiraSans-Medium.woff, (WOFF font, 92KB) doc/FiraSans-Regular.woff, (WOFF font, 56KB) doc/SourceCodePro-Regular.woff, (WOFF font, 56KB) doc/SourceCodePro-Semibold.woff, (WOFF font, 49KB) doc/SourceSerifPro-Bold.woff and 1 more.

Colors

Colors is a library that helps you color and style your text. It's a port of the colors library from NodeJS/NPM, mostly undertaken as a learning exercise :).

Examples

use colors::Style; // Import this to add colors to your string types

println!("{}", "I'm now magically printed in green!".green());

If you prefer to not have the traits added to your &str and strings then just call style directly, like so:

use colors::{Styles,style};

println!("{}", style(Styles::Blue, "I'm now blue!"))

Although with the former style you get a nifty chaining syntax:

use colors::Style;
println!("{}", "Bolded, underlined, and red!".bold().underline().red());

Issues

  • You may have noticed a problem in the examples, we lose the native string substitution that Rusts "println!" macro comes with. This is pretty unfortunate and it looks like it's unavoidable. According to the documentation, the compiler requires that the passed value be a string literal in order to enforce validity checking. If you know of a work around please submit a pull request.

  • This whole technique is also pretty un-rusty. Dynamically allocating a bunch Strings in order to wrap them in fancy Unicode characters isn't going to be very efficient. As an alternative you can use the nifty TerminfoTerminal from Rusts standard library.

Missing from Port / Todo

  • Extra (silly) styles
  • Color themes
  • String substitution, for reasons given above

No runtime deps