cfonts/
config.rs

1//! The contents of this module is all about the configuration of this package
2extern crate strum;
3use strum::IntoEnumIterator;
4use strum_macros::EnumIter;
5
6use crate::color::Rgb;
7use crate::helpers::first_letter_to_lowercase;
8
9/// The `Fonts` enum includes all font options you have for the cfonts output
10///
11/// Find out more about what each font looks like in the [`Readme`](https://github.com/dominikwilkowski/cfonts/blob/released/README.md)
12#[derive(EnumIter, Debug, Clone, PartialEq, Eq, Hash)]
13pub enum Fonts {
14	/// ![The "console" cfonts font](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/console.png)
15	FontConsole,
16	/// ![The "block" cfonts font](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/block.png)
17	FontBlock,
18	/// ![The "simpleBlock" cfonts font](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/simple-block.png)
19	FontSimpleBlock,
20	/// ![The "simple" cfonts font](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/simple.png)
21	FontSimple,
22	/// ![The "3d" cfonts font](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/3d.png)
23	Font3d,
24	/// ![The "simple3d" cfonts font](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/simple-3d.png)
25	FontSimple3d,
26	/// ![The "chrome" cfonts font](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/chrome.png)
27	FontChrome,
28	/// ![The "huge" cfonts font](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/huge.png)
29	FontHuge,
30	/// ![The "shade" cfonts font](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/shade.png)
31	FontShade,
32	/// ![The "slick" cfonts font](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/slick.png)
33	FontSlick,
34	/// ![The "grid" cfonts font](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/grid.png)
35	FontGrid,
36	/// ![The "pallet" cfonts font](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/pallet.png)
37	FontPallet,
38	/// ![The "tiny" cfonts font](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/tiny.png)
39	FontTiny,
40}
41
42/// The `Colors` enum includes all foreground colors you can use
43///
44/// ![The color usage and output of cfonts](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/colors.png)
45///
46/// > 💡  Ansi color support is automatically detected and down-scaled if needed.
47/// Colors also respect both `NO_COLOR` and `FORCE_COLOR` env vars.
48#[derive(EnumIter, Debug, Clone, PartialEq, Eq)]
49pub enum Colors {
50	/// Uses the system font defined by your console
51	System,
52	Black,
53	Red,
54	Green,
55	Yellow,
56	Blue,
57	Magenta,
58	Cyan,
59	White,
60	Gray,
61	RedBright,
62	GreenBright,
63	YellowBright,
64	BlueBright,
65	MagentaBright,
66	CyanBright,
67	WhiteBright,
68	/// A color that randomizes it's colors from a set of bright candy-like color set.
69	Candy,
70	/// `Rgb` allows you to use colors outside the traditional ansi16 color set.
71	/// It's value is the [`Rgb`] enum that has a single value called `Val`.
72	Rgb(Rgb),
73}
74
75/// The `BgColors` enum includes all background colors you can use
76///
77/// ![The background color usage and output of cfonts](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/background.png)
78///
79/// > 💡  Ansi color support is automatically detected and down-scaled if needed.
80/// Colors also respect both `NO_COLOR` and `FORCE_COLOR` env vars.
81#[derive(EnumIter, Debug, Clone, PartialEq, Eq)]
82pub enum BgColors {
83	/// Use the system background defined in your console
84	Transparent,
85	Black,
86	Red,
87	Green,
88	Yellow,
89	Blue,
90	Magenta,
91	Cyan,
92	White,
93	Gray,
94	RedBright,
95	GreenBright,
96	YellowBright,
97	BlueBright,
98	MagentaBright,
99	CyanBright,
100	WhiteBright,
101	/// `Rgb` allows you to use colors outside the traditional ansi16 color set.
102	/// It's value is the [`Rgb`] enum that has a single value called `Val`.
103	Rgb(Rgb),
104}
105
106/// The `Env` enum includes all supported environment options.
107///
108/// ![The env option and it's output with cfonts](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/env.png)
109#[derive(EnumIter, Debug, Clone, PartialEq, Eq)]
110pub enum Env {
111	/// A cli environment means we render colors as ansi escape sequences
112	Cli,
113	/// A browser environment means we render colors as hex colors and output some
114	/// outer HTML to enable us to see the right white space
115	Browser,
116}
117
118/// The `Align` enum includes all supported alignment options.
119///
120/// ![The align option and it's output with cfonts](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/align.png)
121#[derive(EnumIter, Debug, Clone, PartialEq, Eq)]
122pub enum Align {
123	Left,
124	Center,
125	Right,
126	/// > 💡  Note that you can combine both Left/Center/Right alignments with Top/Bottom by using the spaceless option
127	Top,
128	/// > 💡  Note that you can combine both Left/Center/Right alignments with Top/Bottom by using the spaceless option
129	Bottom,
130}
131
132impl Fonts {
133	/// Implementing a list method for each enum so we can communicate in plain text what is supported
134	pub fn list() -> String {
135		let mut list = vec![];
136		for font in Fonts::iter() {
137			let mut name = format!("{:?}", font);
138			name = name.strip_prefix("Font").unwrap().to_string();
139			list.push(first_letter_to_lowercase(&name));
140		}
141		list.join(", ")
142	}
143}
144
145impl Colors {
146	/// Implementing a list method for each enum so we can communicate in plain text what is supported
147	pub fn list() -> String {
148		let mut list = vec![];
149		for font in Colors::iter() {
150			let name = format!("{:?}", font);
151			if name.starts_with("Rgb") {
152				list.push("Any hex color starting with #, e.g.: #ff8800 or #f80".to_string());
153			} else {
154				list.push(first_letter_to_lowercase(&name));
155			}
156		}
157		list.join(", ")
158	}
159}
160
161impl BgColors {
162	/// Implementing a list method for each enum so we can communicate in plain text what is supported
163	pub fn list() -> String {
164		let mut list = vec![];
165		for font in BgColors::iter() {
166			let name = format!("{:?}", font);
167			if name.starts_with("Rgb") {
168				list.push("Any hex color starting with #, e.g.: #ff8800 or #f80".to_string());
169			} else {
170				list.push(first_letter_to_lowercase(&name));
171			}
172		}
173		list.join(", ")
174	}
175}
176
177impl Env {
178	/// Implementing a list method for each enum so we can communicate in plain text what is supported
179	pub fn list() -> String {
180		let mut list = vec![];
181		for font in Env::iter() {
182			let name = format!("{:?}", font);
183			list.push(name.to_lowercase());
184		}
185		list.join(", ")
186	}
187}
188
189impl Align {
190	/// Implementing a list method for each enum so we can communicate in plain text what is supported
191	pub fn list() -> String {
192		let mut list = vec![];
193		for font in Align::iter() {
194			let name = format!("{:?}", font);
195			list.push(name.to_lowercase());
196		}
197		list.join(", ")
198	}
199}
200
201/// Presets for transitions - undocumented
202pub const GRADIENTS_PRIDE: [&str; 6] = ["#750787", "#004dff", "#008026", "#ffed00", "#ff8c00", "#e40303"];
203/// Presets for transitions - undocumented
204pub const GRADIENTS_AGENDER: [&str; 7] = [
205	"#000000", "#b9b9b9", "#ffffff", "#b8f483", "#ffffff", "#b9b9b9", "#000000",
206];
207/// Presets for transitions - undocumented
208pub const GRADIENTS_AROMANTIC: [&str; 5] = ["#3da542", "#a7d379", "#ffffff", "#a9a9a9", "#000000"];
209/// Presets for transitions - undocumented
210pub const GRADIENTS_ASEXUAL: [&str; 4] = ["#000000", "#a3a3a3", "#ffffff", "#800080"];
211/// Presets for transitions - undocumented
212pub const GRADIENTS_BISEXUAL: [&str; 5] = ["#d60270", "#d60270", "#9b4f96", "#0038a8", "#0038a8"];
213/// Presets for transitions - undocumented
214pub const GRADIENTS_GENDERFLUID: [&str; 5] = ["#ff75a2", "#ffffff", "#be18d6", "#000000", "#333ebd"];
215/// Presets for transitions - undocumented
216pub const GRADIENTS_GENDERQUEER: [&str; 3] = ["#b57edc", "#ffffff", "#4a8123"];
217/// Presets for transitions - undocumented
218pub const GRADIENTS_INTERSEX: [&str; 5] = ["#ffd800", "#ffd800", "#7902aa", "#ffd800", "#ffd800"];
219/// Presets for transitions - undocumented
220pub const GRADIENTS_LESBIAN: [&str; 5] = ["#d52d00", "#ff9a56", "#ffffff", "#d362a4", "#a30262"];
221/// Presets for transitions - undocumented
222pub const GRADIENTS_NONBINARY: [&str; 4] = ["#fcf434", "#ffffff", "#9c5cd4", "#2c2c2c"];
223/// Presets for transitions - undocumented
224pub const GRADIENTS_PANSEXUAL: [&str; 3] = ["#ff218c", "#ffd800", "#21b1ff"];
225/// Presets for transitions - undocumented
226pub const GRADIENTS_POLYSEXUAL: [&str; 3] = ["#f61cb9", "#07d569", "#1c92f6"];
227/// Presets for transitions - undocumented
228pub const GRADIENTS_TRANSGENDER: [&str; 5] = ["#5bcefa", "#f5a9b8", "#ffffff", "#f5a9b8", "#5bcefa"];
229
230/// The `Options` struct includes all options cfonts takes to control it's output
231#[derive(Debug, Clone, PartialEq, Eq)]
232pub struct Options {
233	/// The text to be converted
234	pub text: String,
235	/// The font to be used
236	/// ![The font option of cfonts](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/font.png)
237	pub font: Fonts,
238	/// The alignment of the text
239	/// ![The align option of cfonts](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/align.png)
240	pub align: Align,
241	/// The colors to be used
242	/// ![The colors option of cfonts](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/colors.png)
243	pub colors: Vec<Colors>,
244	/// The background color
245	/// ![The background option of cfonts](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/background.png)
246	pub background: BgColors,
247	/// The letter spacing of the text
248	/// ![The letter spacing option of cfonts](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/letter-spacing.png)
249	pub letter_spacing: u16,
250	/// The line height of the output
251	/// ![The line height option of cfonts](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/line-height.png)
252	pub line_height: u16,
253	/// An option to disable any empty lines immediately before and after the output
254	/// ![The spaceless option of cfonts](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/spaceless.png)
255	pub spaceless: bool,
256	/// The maximum amount of letters to be printed per line
257	/// ![The max length option of cfonts](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/max-length.png)
258	pub max_length: u16,
259	/// Colors to be printed gradients between
260	/// ![The gradient option of cfonts](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/gradient.png)
261	pub gradient: Vec<String>,
262	/// An option to enable independent gradients
263	/// ![The independent gradient option of cfonts](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/independent-gradient.png)
264	pub independent_gradient: bool,
265	/// An option to enable transitional gradients
266	/// ![The transition gradient option of cfonts](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/transition-gradient.png)
267	pub transition_gradient: bool,
268	/// The environment to render for
269	/// ![The env option of cfonts](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/env.png)
270	pub env: Env,
271	/// To show the help
272	/// ![The help option of cfonts](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/help.png)
273	pub help: bool,
274	/// To show the version
275	/// ![The version option of cfonts](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/version.png)
276	pub version: bool,
277	/// To print debug infos
278	pub debug: bool,
279	/// The depth of the debug infos
280	pub debug_level: u16,
281	/// To render string newlines properly in 'raw mode' in terminals
282	pub raw_mode: bool,
283}
284
285impl Default for Options {
286	/// The default values for each of the options so you don't have to pick each option every time
287	fn default() -> Self {
288		Options {
289			text: String::from(""),
290			font: Fonts::FontBlock,
291			align: Align::Left,
292			colors: vec![Colors::System],
293			background: BgColors::Transparent,
294			letter_spacing: 1,
295			line_height: 1,
296			spaceless: false,
297			max_length: 0,
298			gradient: Vec::new(),
299			independent_gradient: false,
300			transition_gradient: false,
301			raw_mode: false,
302			env: Env::Cli,
303			help: false,
304			version: false,
305			debug: false,
306			debug_level: 1,
307		}
308	}
309}
310
311/// The type of options our [`CLIOPTIONS`] can have
312#[derive(Debug, Clone, PartialEq, Eq)]
313pub enum OptionType {
314	/// There is only one text option which is for the text
315	Text,
316	/// Font option
317	Font,
318	/// Alignment option
319	Align,
320	/// Foreground color option
321	Colors,
322	/// Background color option
323	BgColor,
324	/// Gradient color option
325	Gradient,
326	/// Option where numbers are expected
327	Number,
328	/// Option where a boolean is expected
329	Bool,
330	/// Environment option
331	Env,
332}
333
334/// The struct of a single option inside our [`CLIOPTIONS`]
335#[derive(Debug, Clone, PartialEq, Eq)]
336pub struct CliOption<'a> {
337	/// The key of this option so we can address it later
338	pub key: &'a str,
339	/// The name of the option for it's description
340	pub name: &'a str,
341	/// The description of this option
342	pub description: &'a str,
343	/// The shortcut flag; e.g.: -a instead of --align
344	pub shortcut: &'a str,
345	/// An alternative shortcut flag in case where we have multiple
346	pub fallback_shortcut: &'a str,
347	/// An example of this option to be displayed in the help
348	pub example: &'a str,
349	/// The type of option
350	pub kind: OptionType,
351}
352
353/// The `CLIOPTIONS` define each of the flags our cli app respects.
354///
355/// It's also used to generate the help
356pub const CLIOPTIONS: [CliOption; 17] = [
357	CliOption {
358		key: "version",
359		name: "--version",
360		shortcut: "-v",
361		fallback_shortcut: "-V",
362		description: "Use to display the version of cfonts",
363		example: "--version",
364		kind: OptionType::Bool,
365	},
366	CliOption {
367		key: "help",
368		name: "--help",
369		shortcut: "-h",
370		fallback_shortcut: "",
371		description: "Use to display this help",
372		example: "--help",
373		kind: OptionType::Bool,
374	},
375	CliOption {
376		key: "font",
377		name: "--font",
378		shortcut: "-f",
379		fallback_shortcut: "",
380		description: "Use to define the font face",
381		example: "--font block",
382		kind: OptionType::Font,
383	},
384	CliOption {
385		key: "colors",
386		name: "--colors",
387		shortcut: "-c",
388		fallback_shortcut: "",
389		description: "Use to define the font color",
390		example: "--colors red,blue",
391		kind: OptionType::Colors,
392	},
393	CliOption {
394		key: "background",
395		name: "--background",
396		shortcut: "-b",
397		fallback_shortcut: "",
398		description: "Use to define background color",
399		example: "--background blue",
400		kind: OptionType::BgColor,
401	},
402	CliOption {
403		key: "align",
404		name: "--align",
405		shortcut: "-a",
406		fallback_shortcut: "",
407		description: "Use to align your text output",
408		example: "--align center",
409		kind: OptionType::Align,
410	},
411	CliOption {
412		key: "letter_spacing",
413		name: "--letter-spacing",
414		shortcut: "-l",
415		fallback_shortcut: "",
416		description: "Use to define your letter spacing",
417		example: "--letter-spacing 2",
418		kind: OptionType::Number,
419	},
420	CliOption {
421		key: "line_height",
422		name: "--line-height",
423		shortcut: "-z",
424		fallback_shortcut: "",
425		description: "Use to define your line height",
426		example: "--line-height 5",
427		kind: OptionType::Number,
428	},
429	CliOption {
430		key: "spaceless",
431		name: "--spaceless",
432		shortcut: "-s",
433		fallback_shortcut: "",
434		description: "Use to disable the padding around your output",
435		example: "--spaceless",
436		kind: OptionType::Bool,
437	},
438	CliOption {
439		key: "max_length",
440		name: "--max-length",
441		shortcut: "-m",
442		fallback_shortcut: "",
443		description: "Use to define the amount of maximum characters per line",
444		example: "--max-length 10",
445		kind: OptionType::Number,
446	},
447	CliOption {
448		key: "gradient",
449		name: "--gradient",
450		shortcut: "-g",
451		fallback_shortcut: "",
452		description: "Use to define a start and end color of a gradient",
453		example: "--gradient red,blue,green",
454		kind: OptionType::Gradient,
455	},
456	CliOption {
457		key: "independent_gradient",
458		name: "--independent-gradient",
459		shortcut: "-i",
460		fallback_shortcut: "",
461		description: "Use to define that a gradient is applied independently for each line",
462		example: "--gradient red,blue --independent-gradient",
463		kind: OptionType::Bool,
464	},
465	CliOption {
466		key: "transition_gradient",
467		name: "--transition-gradient",
468		shortcut: "-t",
469		fallback_shortcut: "",
470		description: "Use to define that a gradient is a transition between the colors",
471		example: "--gradient red,blue,green --transition-gradient",
472		kind: OptionType::Bool,
473	},
474	CliOption {
475		key: "raw_mode",
476		name: "--raw-mode",
477		shortcut: "-r",
478		fallback_shortcut: "",
479		description: "Use to enable proper newline rendering in raw mode in the terminal by adding \\r to line breaks",
480		example: "--raw-mode",
481		kind: OptionType::Bool,
482	},
483	CliOption {
484		key: "env",
485		name: "--env",
486		shortcut: "-e",
487		fallback_shortcut: "",
488		description: "Use to define what environment you run CFonts in.",
489		example: "--env browser",
490		kind: OptionType::Env,
491	},
492	CliOption {
493		key: "debug",
494		name: "--debug",
495		shortcut: "-d",
496		fallback_shortcut: "",
497		description: "Use to enable debug mode",
498		example: "--debug",
499		kind: OptionType::Bool,
500	},
501	CliOption {
502		key: "debug_level",
503		name: "--debug-level",
504		shortcut: "-x",
505		fallback_shortcut: "",
506		description: "Use to define the debug level. The higher, the less debug infos",
507		example: "--debug-level 2",
508		kind: OptionType::Number,
509	},
510];