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