termstyle is a library that aims to make it easy to build formatted and styled command line applications.
It supports the following "elements":
- styled-text
- italic
- bold
- colors
- tables: composed of styled text with identical width columns
Text can be constructed programatically by pushing tokens onto a vector and
then paint()
ing them, or by parsing a yaml file. This allows you to easily
write unit tests for your command line applications.
Example
Given the following config (written in yaml):
-
- "This is a regular string with a newline\n"
- "This does not have a newline, but "
-
- ", but this is NOT red!\n"
- "Bold is easy like this: "
-
- And so is multiple settings
- # long-form
t: |
bold AND green!
and even multiple lines :) :)
b: true
c: green
-
- "\nGrouping things in one line is necessary for tables\n"
- "Notice that some cells are grouped and some are not.\n\n"
-
-
table:
-
-
Use the following to render it:
let els = from_str.unwrap;
paint.unwrap;
Which gets rendered as:
You can also create the "stream of elements" using the types provided by the library. For more information, see the library docs.
LICENSE
The source code is Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.