Commit 84d4e2f2 authored by Moritz Sokoll's avatar Moritz Sokoll 🦀
Browse files

added newer way for coloring (deprecated old one)

parent 88a82b92
[package]
name = "btui"
version = "0.1.1"
version = "0.2.1"
edition = "2018"
authors = ["Moritz Sokoll <moritz@sokoll.com>"]
license-file = "COPYING"
......
......@@ -5,5 +5,5 @@
## Usage
Add this to your `Cargo.toml` dependency list:
```toml
btui = "0.1.1"
btui = "0.2.1"
```
pub mod colors {
/// enum to represent colored text
#[deprecated(
since = "0.2.1",
note = "older bulkier way of writing colored text. Please use `Color` instead"
)]
pub enum ColoredText {
Black(String),
Red(String),
......@@ -12,6 +16,10 @@ pub mod colors {
}
/// enum to represent a background color
#[deprecated(
since = "0.2.1",
note = "older bulkier way of writing colored text. Please use `Color` instead"
)]
pub enum ColoredBg {
Black,
Red,
......@@ -22,6 +30,19 @@ pub mod colors {
Cyan,
White,
}
/// enum to represent any color
pub enum Color {
Black,
Red,
Green,
Yellow,
Blue,
Magenta,
Cyan,
White,
Reset,
}
}
pub mod formatting {
......@@ -37,6 +58,10 @@ pub mod formatting {
/// # Returns
///
/// the formatted text with escape characters to be printed to the terminal
#[deprecated(
since = "0.2.1",
note = "older bulkier way for coloring. Use `print`'s functions instead"
)]
pub fn format(text: Vec<Variant<ColoredText, ColoredBg>>) -> String {
let mut out: String = String::new();
......@@ -69,4 +94,65 @@ pub mod formatting {
out.push_str("\x1b[0m");
out
}
/// new module for colored output
pub mod print {
use crate::ft::colors::Color;
/// change foreground color
///
/// # Arguments
/// *`col`: color to use
///
/// # Returns
/// the color code to be printed to the terminal
///
/// # Example
/// ```rust
/// use btui::ft::formatting::print::fg;
/// use btui::colors::Color;
/// println!("{}test{}", fg(Color::Red), fg(Color::Reset));
/// ```
pub fn fg(col: Color) -> String {
match col {
Color::Black => String::from("\x1b[30m"),
Color::Red => String::from("\x1b[31m"),
Color::Green => String::from("\x1b[32m"),
Color::Yellow => String::from("\x1b[33m"),
Color::Blue => String::from("\x1b[34m"),
Color::Magenta => String::from("\x1b[35m"),
Color::Cyan => String::from("\x1b[36m"),
Color::White => String::from("\x1b[37m"),
Color::Reset => String::from("\x1b[0m"),
}
}
/// change background color
///
/// # Arguments
/// *`col`: color to use
///
/// # Returns
/// the color code to be printed to the terminal
///
/// # Example
/// ```rust
/// use btui::ft::formatting::print::bg;
/// use btui::colors::Color;
/// println!("{}test{}", bg(Color::Red), bg(Color::Reset));
/// ```
pub fn bg(col: Color) -> String {
match col {
Color::Black => String::from("\x1b[40m"),
Color::Red => String::from("\x1b[41m"),
Color::Green => String::from("\x1b[42m"),
Color::Yellow => String::from("\x1b[43m"),
Color::Blue => String::from("\x1b[44m"),
Color::Magenta => String::from("\x1b[45m"),
Color::Cyan => String::from("\x1b[46m"),
Color::White => String::from("\x1b[47m"),
Color::Reset => String::from("\x1b[0m"),
}
}
}
}
......@@ -4,7 +4,7 @@
//! with btui you can create beautiful text user interfaces for the terminal.
//! To get started add `btui` as a dependency to your project:
//! ```toml
//! btui = "0.1.1"
//! btui = "0.2.1"
//! ```
pub mod ft;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment