1extern crate strum;
3use strum::IntoEnumIterator;
4use strum_macros::EnumIter;
5
6use crate::color::Rgb;
7use crate::helpers::first_letter_to_lowercase;
8
9#[derive(EnumIter, Debug, Clone, PartialEq, Eq, Hash)]
13pub enum Fonts {
14 FontConsole,
16 FontBlock,
18 FontSimpleBlock,
20 FontSimple,
22 Font3d,
24 FontSimple3d,
26 FontChrome,
28 FontHuge,
30 FontShade,
32 FontSlick,
34 FontGrid,
36 FontPallet,
38 FontTiny,
40}
41
42#[derive(EnumIter, Debug, Clone, PartialEq, Eq)]
49pub enum Colors {
50 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 Candy,
70 Rgb(Rgb),
73}
74
75#[derive(EnumIter, Debug, Clone, PartialEq, Eq)]
82pub enum BgColors {
83 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(Rgb),
104}
105
106#[derive(EnumIter, Debug, Clone, PartialEq, Eq)]
110pub enum Env {
111 Cli,
113 Browser,
116}
117
118#[derive(EnumIter, Debug, Clone, PartialEq, Eq)]
122pub enum Align {
123 Left,
124 Center,
125 Right,
126 Top,
128 Bottom,
130}
131
132impl Fonts {
133 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 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 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 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 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
201pub const GRADIENTS_PRIDE: [&str; 6] = ["#750787", "#004dff", "#008026", "#ffed00", "#ff8c00", "#e40303"];
203pub const GRADIENTS_AGENDER: [&str; 7] = [
205 "#000000", "#b9b9b9", "#ffffff", "#b8f483", "#ffffff", "#b9b9b9", "#000000",
206];
207pub const GRADIENTS_AROMANTIC: [&str; 5] = ["#3da542", "#a7d379", "#ffffff", "#a9a9a9", "#000000"];
209pub const GRADIENTS_ASEXUAL: [&str; 4] = ["#000000", "#a3a3a3", "#ffffff", "#800080"];
211pub const GRADIENTS_BISEXUAL: [&str; 5] = ["#d60270", "#d60270", "#9b4f96", "#0038a8", "#0038a8"];
213pub const GRADIENTS_GENDERFLUID: [&str; 5] = ["#ff75a2", "#ffffff", "#be18d6", "#000000", "#333ebd"];
215pub const GRADIENTS_GENDERQUEER: [&str; 3] = ["#b57edc", "#ffffff", "#4a8123"];
217pub const GRADIENTS_INTERSEX: [&str; 5] = ["#ffd800", "#ffd800", "#7902aa", "#ffd800", "#ffd800"];
219pub const GRADIENTS_LESBIAN: [&str; 5] = ["#d52d00", "#ff9a56", "#ffffff", "#d362a4", "#a30262"];
221pub const GRADIENTS_NONBINARY: [&str; 4] = ["#fcf434", "#ffffff", "#9c5cd4", "#2c2c2c"];
223pub const GRADIENTS_PANSEXUAL: [&str; 3] = ["#ff218c", "#ffd800", "#21b1ff"];
225pub const GRADIENTS_POLYSEXUAL: [&str; 3] = ["#f61cb9", "#07d569", "#1c92f6"];
227pub const GRADIENTS_TRANSGENDER: [&str; 5] = ["#5bcefa", "#f5a9b8", "#ffffff", "#f5a9b8", "#5bcefa"];
229
230#[derive(Debug, Clone, PartialEq, Eq)]
232pub struct Options {
233 pub text: String,
235 pub font: Fonts,
238 pub align: Align,
241 pub colors: Vec<Colors>,
244 pub background: BgColors,
247 pub letter_spacing: u16,
250 pub line_height: u16,
253 pub spaceless: bool,
256 pub max_length: u16,
259 pub gradient: Vec<String>,
262 pub independent_gradient: bool,
265 pub transition_gradient: bool,
268 pub env: Env,
271 pub help: bool,
274 pub version: bool,
277 pub debug: bool,
279 pub debug_level: u16,
281 pub raw_mode: bool,
283}
284
285impl Default for Options {
286 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#[derive(Debug, Clone, PartialEq, Eq)]
313pub enum OptionType {
314 Text,
316 Font,
318 Align,
320 Colors,
322 BgColor,
324 Gradient,
326 Number,
328 Bool,
330 Env,
332}
333
334#[derive(Debug, Clone, PartialEq, Eq)]
336pub struct CliOption<'a> {
337 pub key: &'a str,
339 pub name: &'a str,
341 pub description: &'a str,
343 pub shortcut: &'a str,
345 pub fallback_shortcut: &'a str,
347 pub example: &'a str,
349 pub kind: OptionType,
351}
352
353pub 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];