cfonts/
lib.rs

1//! # Cfonts - Sexy fonts for the console
2//!
3//! ```sh
4//! $ cfonts "hi there"
5//!
6//! ██╗  ██╗ ██╗     ████████╗ ██╗  ██╗ ███████╗ ██████╗  ███████╗
7//! ██║  ██║ ██║     ╚══██╔══╝ ██║  ██║ ██╔════╝ ██╔══██╗ ██╔════╝
8//! ███████║ ██║        ██║    ███████║ █████╗   ██████╔╝ █████╗
9//! ██╔══██║ ██║        ██║    ██╔══██║ ██╔══╝   ██╔══██╗ ██╔══╝
10//! ██║  ██║ ██║        ██║    ██║  ██║ ███████╗ ██║  ██║ ███████╗
11//! ╚═╝  ╚═╝ ╚═╝        ╚═╝    ╚═╝  ╚═╝ ╚══════╝ ╚═╝  ╚═╝ ╚══════╝
12//! ```
13//!
14//! 💡  This is a silly little command line tool for sexy fonts in the console. **Give your cli some love.**
15//!
16//! ---
17//! This library supports:
18//! - different fonts
19//! - multiple colors per font
20//! - color gradient
21//! - text alignment
22//! - letter spacing and line height options
23//!
24//! ## Usage
25//!
26//! Print directly to your console via the [`println!()`](https://doc.rust-lang.org/std/macro.println.html) macro:
27//!
28//! ```rust
29//! extern crate cfonts;
30//!
31//! use cfonts::{ say, Options };
32//!
33//! fn main() {
34//!     say(Options {
35//!         text: String::from("hello"),
36//!         ..Options::default()
37//!     });
38//! }
39//! ```
40//!
41//! Or use the output struct however you like:
42//!
43//! ```rust
44//! extern crate cfonts;
45//!
46//! use cfonts::{ render, Options, Fonts };
47//!
48//! fn main() {
49//!     let output = render(Options {
50//!         text: String::from("hello"),
51//!         font: Fonts::FontTiny,
52//!         ..Options::default()
53//!     });
54//!
55//!     assert_eq!(
56//!         output.text,
57//!         format!("{}{}{}",
58//!             "\n\n",
59//!             " █ █ █▀▀ █   █   █▀█\n",
60//!             " █▀█ ██▄ █▄▄ █▄▄ █▄█\n\n"
61//!         )
62//!     );
63//!
64//!     assert_eq!(output.vec, vec![
65//!         String::from("\n\n █ █ █▀▀ █   █   █▀█"),
66//!         String::from(    " █▀█ ██▄ █▄▄ █▄▄ █▄█\n\n"),
67//!     ]);
68//!
69//!     assert_eq!(output.lines, 1);
70//!
71//!     assert_eq!(output.options, Options {
72//!         text: String::from("hello"),
73//!         font: Fonts::FontTiny,
74//!         ..Options::default()
75//!     });
76//! }
77//! ```
78
79extern crate exitcode;
80
81pub mod args;
82pub mod chars;
83pub mod cli;
84pub mod color;
85pub mod config;
86pub mod debug;
87pub mod font;
88pub mod gradient;
89pub mod helpers;
90pub mod render;
91
92pub use color::Rgb;
93pub use config::{Align, BgColors, Colors, Env, Fonts, Options};
94use debug::{d, Dt};
95pub use render::render;
96
97/// The `say` function will print your cfonts output to `stdout`.
98///
99/// The way you pass it Options is the same as for [`render()`]
100///
101/// ```rust
102/// extern crate cfonts;
103///
104/// use cfonts::{ say, Options, Align, BgColors, Colors, Env, Fonts, Rgb };
105///
106/// fn main() {
107///     say(Options {
108///         text: String::from("hello"),
109///         font: Fonts::FontSlick,
110///         colors: vec![Colors::Red, Colors::Rgb(Rgb::Val(20, 216, 79))],
111///         background: BgColors::BlueBright,
112///         align: Align::Center,
113///         letter_spacing: 1,
114///         line_height: 2,
115///         spaceless: true,
116///         max_length: 15,
117///         gradient: vec![String::from("#ff8800"), String::from("#88ff00")],
118///         independent_gradient: false,
119///         transition_gradient: false,
120///         env: Env::Browser,
121///         ..Options::default()
122///     });
123/// }
124/// ```
125pub fn say(options: Options) {
126	d("say()", 1, Dt::Head, &options, &mut std::io::stdout());
127	d(&format!("say() Options:\n{:#?}", options), 2, Dt::Log, &options, &mut std::io::stdout());
128
129	let render_options = render(options);
130	println!("{}", render_options.text);
131}