Projects STRLCPY cfonts Commits 444ca7d2
🤬
  • ■ ■ ■ ■ ■ ■
    rust/Cargo.lock
    skipped 2 lines
    3 3  version = 3
    4 4   
    5 5  [[package]]
     6 +name = "assert_cmd"
     7 +version = "2.0.4"
     8 +source = "registry+https://github.com/rust-lang/crates.io-index"
     9 +checksum = "93ae1ddd39efd67689deb1979d80bad3bf7f2b09c6e6117c8d1f2443b5e2f83e"
     10 +dependencies = [
     11 + "bstr",
     12 + "doc-comment",
     13 + "predicates",
     14 + "predicates-core",
     15 + "predicates-tree",
     16 + "wait-timeout",
     17 +]
     18 + 
     19 +[[package]]
    6 20  name = "atty"
    7 21  version = "0.2.14"
    8 22  source = "registry+https://github.com/rust-lang/crates.io-index"
    skipped 5 lines
    14 28  ]
    15 29   
    16 30  [[package]]
     31 +name = "bstr"
     32 +version = "0.2.17"
     33 +source = "registry+https://github.com/rust-lang/crates.io-index"
     34 +checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"
     35 +dependencies = [
     36 + "lazy_static",
     37 + "memchr",
     38 + "regex-automata",
     39 +]
     40 + 
     41 +[[package]]
    17 42  name = "cfg-if"
    18 43  version = "1.0.0"
    19 44  source = "registry+https://github.com/rust-lang/crates.io-index"
    skipped 1 lines
    21 46   
    22 47  [[package]]
    23 48  name = "cfonts"
    24  -version = "1.0.3"
     49 +version = "1.0.4"
    25 50  dependencies = [
     51 + "assert_cmd",
    26 52   "enable-ansi-support",
    27 53   "exitcode",
    28 54   "rand",
    skipped 7 lines
    36 62  ]
    37 63   
    38 64  [[package]]
     65 +name = "difflib"
     66 +version = "0.4.0"
     67 +source = "registry+https://github.com/rust-lang/crates.io-index"
     68 +checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8"
     69 + 
     70 +[[package]]
     71 +name = "doc-comment"
     72 +version = "0.3.3"
     73 +source = "registry+https://github.com/rust-lang/crates.io-index"
     74 +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
     75 + 
     76 +[[package]]
     77 +name = "either"
     78 +version = "1.6.1"
     79 +source = "registry+https://github.com/rust-lang/crates.io-index"
     80 +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
     81 + 
     82 +[[package]]
    39 83  name = "enable-ansi-support"
    40 84  version = "0.1.2"
    41 85  source = "registry+https://github.com/rust-lang/crates.io-index"
    skipped 41 lines
    83 127  checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb"
    84 128   
    85 129  [[package]]
     130 +name = "itertools"
     131 +version = "0.10.3"
     132 +source = "registry+https://github.com/rust-lang/crates.io-index"
     133 +checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3"
     134 +dependencies = [
     135 + "either",
     136 +]
     137 + 
     138 +[[package]]
    86 139  name = "itoa"
    87 140  version = "1.0.1"
    88 141  source = "registry+https://github.com/rust-lang/crates.io-index"
    89 142  checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35"
    90 143   
    91 144  [[package]]
     145 +name = "lazy_static"
     146 +version = "1.4.0"
     147 +source = "registry+https://github.com/rust-lang/crates.io-index"
     148 +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
     149 + 
     150 +[[package]]
    92 151  name = "libc"
    93 152  version = "0.2.125"
    94 153  source = "registry+https://github.com/rust-lang/crates.io-index"
    95 154  checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b"
    96 155   
    97 156  [[package]]
     157 +name = "memchr"
     158 +version = "2.5.0"
     159 +source = "registry+https://github.com/rust-lang/crates.io-index"
     160 +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
     161 + 
     162 +[[package]]
    98 163  name = "once_cell"
    99 164  version = "1.10.0"
    100 165  source = "registry+https://github.com/rust-lang/crates.io-index"
    skipped 6 lines
    107 172  checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872"
    108 173   
    109 174  [[package]]
     175 +name = "predicates"
     176 +version = "2.1.1"
     177 +source = "registry+https://github.com/rust-lang/crates.io-index"
     178 +checksum = "a5aab5be6e4732b473071984b3164dbbfb7a3674d30ea5ff44410b6bcd960c3c"
     179 +dependencies = [
     180 + "difflib",
     181 + "itertools",
     182 + "predicates-core",
     183 +]
     184 + 
     185 +[[package]]
     186 +name = "predicates-core"
     187 +version = "1.0.3"
     188 +source = "registry+https://github.com/rust-lang/crates.io-index"
     189 +checksum = "da1c2388b1513e1b605fcec39a95e0a9e8ef088f71443ef37099fa9ae6673fcb"
     190 + 
     191 +[[package]]
     192 +name = "predicates-tree"
     193 +version = "1.0.5"
     194 +source = "registry+https://github.com/rust-lang/crates.io-index"
     195 +checksum = "4d86de6de25020a36c6d3643a86d9a6a9f552107c0559c60ea03551b5e16c032"
     196 +dependencies = [
     197 + "predicates-core",
     198 + "termtree",
     199 +]
     200 + 
     201 +[[package]]
    110 202  name = "proc-macro2"
    111 203  version = "1.0.37"
    112 204  source = "registry+https://github.com/rust-lang/crates.io-index"
    skipped 40 lines
    153 245  dependencies = [
    154 246   "getrandom",
    155 247  ]
     248 + 
     249 +[[package]]
     250 +name = "regex-automata"
     251 +version = "0.1.10"
     252 +source = "registry+https://github.com/rust-lang/crates.io-index"
     253 +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
    156 254   
    157 255  [[package]]
    158 256  name = "rustversion"
    skipped 98 lines
    257 355  ]
    258 356   
    259 357  [[package]]
     358 +name = "termtree"
     359 +version = "0.2.4"
     360 +source = "registry+https://github.com/rust-lang/crates.io-index"
     361 +checksum = "507e9898683b6c43a9aa55b64259b721b52ba226e0f3779137e50ad114a4c90b"
     362 + 
     363 +[[package]]
    260 364  name = "unicode-xid"
    261 365  version = "0.2.2"
    262 366  source = "registry+https://github.com/rust-lang/crates.io-index"
    263 367  checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
     368 + 
     369 +[[package]]
     370 +name = "wait-timeout"
     371 +version = "0.2.0"
     372 +source = "registry+https://github.com/rust-lang/crates.io-index"
     373 +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6"
     374 +dependencies = [
     375 + "libc",
     376 +]
    264 377   
    265 378  [[package]]
    266 379  name = "wasi"
    skipped 26 lines
  • ■ ■ ■ ■ ■
    rust/Cargo.toml
    1 1  [package]
    2 2  name = "cfonts"
    3  -version = "1.0.3"
     3 +version = "1.0.4"
    4 4  edition = "2021"
    5 5  authors = ["Dominik Wilkowski <[email protected]>"]
    6 6  license = "GPL-3.0-or-later"
    skipped 19 lines
    26 26   
    27 27  [dev-dependencies]
    28 28  temp-env = "0.2.0"
     29 +assert_cmd = "2.0.4"
    29 30   
  • ■ ■ ■ ■ ■
    rust/README.md
    skipped 133 lines
    134 134   
    135 135  ## Release History
    136 136   
     137 +* 1.0.4 - Fixed NO_COLOR not being respected in help, fixed color conversion rgb to ansi_256
    137 138  * 1.0.3 - Fixed NO_COLOR support when run without FORCE_COLOR
    138 139  * 1.0.2 - Fixed help and version flags in first position
    139 140  * 1.0.1 - Fixed font loading
    skipped 9 lines
  • ■ ■ ■ ■ ■ ■
    rust/src/cli.rs
    1 1  //! The contents of this module is all about cli specific functionality
    2  -use crate::color::color;
     2 +use std::env;
     3 + 
     4 +use crate::color::{color, get_term_color_support, TermColorSupport};
    3 5  use crate::config::{Align, BgColors, Colors, Env, Fonts, OptionType, Options, CLIOPTIONS};
    4 6  use crate::debug::{d, Dt};
    5 7  use crate::render::render;
    skipped 41 lines
    47 49   ..Options::default()
    48 50   });
    49 51   
     52 + let (bold_start, bold_end) = if get_term_color_support() == TermColorSupport::NoColor {
     53 + (String::from(""), String::from(""))
     54 + } else {
     55 + (String::from("\x1b[1m"), String::from("\x1b[22m"))
     56 + };
     57 + 
    50 58   output += "\n\n";
    51 59   output += &render_options.text;
    52 60   output += "\n\n";
    53 61   output += "This is a tool for sexy fonts in the console. Give your cli some love.\n";
    54 62   output += "\n";
    55 63   output += "Usage: cfonts \"<value>\" [option1] <input1> [option2] <input1>,<input2> [option3]\n";
    56  - output += "Example: \x1b[1m$ cfonts \"sexy font\" -f chrome -a center -c red,green,gray\x1b[22m\n";
     64 + output +=
     65 + &format!("Example: {}$ cfonts \"sexy font\" -f chrome -a center -c red,green,gray{}\n", bold_start, bold_end);
    57 66   output += "\n";
    58 67   output += "Options:\n";
    59 68   
    60 69   for option in CLIOPTIONS {
    61  - output += &format!("\n\x1b[1m{}, {}", option.name, option.shortcut);
     70 + output += &format!("\n{}{}, {}", bold_start, option.name, option.shortcut);
    62 71   if !option.fallback_shortcut.is_empty() {
    63 72   output += &format!(", {}", option.fallback_shortcut);
    64 73   }
    65  - output += "\x1b[22m\n";
     74 + output += &format!("{}\n", bold_end);
    66 75   output += &format!("{}\n", option.description);
    67  - output += &format!("\x1b[1m$\x1b[22m cfonts {}", option.example);
     76 + output += &format!("{}${} cfonts {}", bold_start, bold_end, option.example);
    68 77   match option.kind {
    69 78   OptionType::Font => {
    70 79   output += &color(&format!(" [ {} ]", Fonts::list()), Colors::Green).to_string();
    skipped 21 lines
  • ■ ■ ■ ■ ■ ■
    rust/src/color.rs
    skipped 510 lines
    511 511  /// use cfonts::color::{rgb_u8_2ansi_256,};
    512 512  ///
    513 513  /// assert_eq!(rgb_u8_2ansi_256(100, 200, 100), 114);
    514  -/// assert_eq!(rgb_u8_2ansi_256(255, 255, 255), 16);
    515  -/// assert_eq!(rgb_u8_2ansi_256(0, 0, 0), 231);
     514 +/// assert_eq!(rgb_u8_2ansi_256(255, 255, 255), 231);
     515 +/// assert_eq!(rgb_u8_2ansi_256(0, 0, 0), 16);
    516 516  /// assert_eq!(rgb_u8_2ansi_256(167, 5, 98), 126);
    517 517  /// ```
    518 518  pub fn rgb_u8_2ansi_256(r: u8, g: u8, b: u8) -> u8 {
    skipped 2 lines
    521 521   let blue = b as f64;
    522 522   
    523 523   if r == g && g == b {
    524  - if red > 8.0 {
     524 + if red < 8.0 {
    525 525   return 16;
    526 526   }
    527 527   if red > 248.0 {
    skipped 20 lines
    548 548  ///
    549 549  /// assert_eq!(rgb2ansi_256(&Rgb::Val(255, 0, 0), ColorLayer::Foreground), "\x1b[38;5;196m".to_string());
    550 550  /// assert_eq!(rgb2ansi_256(&Rgb::Val(255, 255, 0), ColorLayer::Foreground), "\x1b[38;5;226m".to_string());
    551  -/// assert_eq!(rgb2ansi_256(&Rgb::Val(255, 255, 255), ColorLayer::Foreground), "\x1b[38;5;16m".to_string());
     551 +/// assert_eq!(rgb2ansi_256(&Rgb::Val(255, 255, 255), ColorLayer::Foreground), "\x1b[38;5;231m".to_string());
    552 552  /// assert_eq!(rgb2ansi_256(&Rgb::Val(157, 5, 98), ColorLayer::Foreground), "\x1b[38;5;126m".to_string());
    553 553  ///
    554 554  /// assert_eq!(rgb2ansi_256(&Rgb::Val(255, 0, 0), ColorLayer::Background), "\x1b[48;5;196m".to_string());
    555 555  /// assert_eq!(rgb2ansi_256(&Rgb::Val(255, 255, 0), ColorLayer::Background), "\x1b[48;5;226m".to_string());
    556  -/// assert_eq!(rgb2ansi_256(&Rgb::Val(255, 255, 255), ColorLayer::Background), "\x1b[48;5;16m".to_string());
     556 +/// assert_eq!(rgb2ansi_256(&Rgb::Val(255, 255, 255), ColorLayer::Background), "\x1b[48;5;231m".to_string());
    557 557  /// assert_eq!(rgb2ansi_256(&Rgb::Val(157, 5, 98), ColorLayer::Background), "\x1b[48;5;126m".to_string());
    558 558  /// ```
    559 559  pub fn rgb2ansi_256(rgb: &Rgb, layer: ColorLayer) -> String {
    skipped 18 lines
    578 578  ///
    579 579  /// assert_eq!(rgb2ansi_16(&Rgb::Val(255, 0, 0), ColorLayer::Foreground), "\x1b[91m".to_string());
    580 580  /// assert_eq!(rgb2ansi_16(&Rgb::Val(255, 255, 0), ColorLayer::Foreground), "\x1b[93m".to_string());
    581  -/// assert_eq!(rgb2ansi_16(&Rgb::Val(255, 255, 255), ColorLayer::Foreground), "\x1b[0m".to_string());
     581 +/// assert_eq!(rgb2ansi_16(&Rgb::Val(255, 255, 255), ColorLayer::Foreground), "\x1b[97m".to_string());
    582 582  /// assert_eq!(rgb2ansi_16(&Rgb::Val(157, 5, 98), ColorLayer::Foreground), "\x1b[31m".to_string());
    583 583  ///
    584 584  /// assert_eq!(rgb2ansi_16(&Rgb::Val(255, 0, 0), ColorLayer::Background), "\x1b[101m".to_string());
    585 585  /// assert_eq!(rgb2ansi_16(&Rgb::Val(255, 255, 0), ColorLayer::Background), "\x1b[103m".to_string());
    586  -/// assert_eq!(rgb2ansi_16(&Rgb::Val(255, 255, 255), ColorLayer::Background), "\x1b[10m".to_string());
     586 +/// assert_eq!(rgb2ansi_16(&Rgb::Val(255, 255, 255), ColorLayer::Background), "\x1b[107m".to_string());
    587 587  /// assert_eq!(rgb2ansi_16(&Rgb::Val(157, 5, 98), ColorLayer::Background), "\x1b[41m".to_string());
    588 588  /// ```
    589 589  pub fn rgb2ansi_16(rgb: &Rgb, layer: ColorLayer) -> String {
    skipped 248 lines
  • ■ ■ ■ ■
    rust/src/font.rs
    skipped 8 lines
    9 9  use crate::debug::{d, Dt};
    10 10   
    11 11  /// The shape of our font data
    12  -#[derive(Debug, Deserialize)]
     12 +#[derive(Deserialize)]
    13 13  pub struct Font {
    14 14   /// The name of our font
    15 15   pub name: String,
    skipped 123 lines
  • ■ ■ ■ ■ ■ ■
    rust/tests/args_test.rs
    skipped 90 lines
    91 91   }
    92 92   
    93 93   #[test]
     94 + fn args_parse_errors_without_args_options() {
     95 + assert!(parse(vec!["path/to/bin".to_string()]).is_err());
     96 + }
     97 + 
     98 + #[test]
    94 99   fn args_parse_version_flags() {
    95 100   let mut options = Options::default();
    96 101   options.version = true;
    skipped 115 lines
    212 217   
    213 218   // stacked flags
    214 219   assert_eq!(parse(vec!["path/to/bin".to_string(), "my text".to_string(), "-hd".to_string(),]).unwrap(), options);
     220 + }
     221 + 
     222 + #[test]
     223 + fn args_parse_number_errors_without_number() {
     224 + assert!(parse(vec!["path/to/bin".to_string(), "my text".to_string(), "-l".to_string()]).is_err());
     225 + assert!(parse(vec![
     226 + "path/to/bin".to_string(),
     227 + "my text".to_string(),
     228 + "-l".to_string(),
     229 + "-1".to_string()
     230 + ])
     231 + .is_err());
    215 232   }
    216 233   
    217 234   #[test]
    skipped 517 lines
    735 752   "gRaY",
    736 753   "GRAY",
    737 754   background,
     755 + BgColors::Gray,
     756 + "-b",
     757 + "--background",
     758 + "grey",
     759 + "gReY",
     760 + "GREY",
     761 + background,
    738 762   BgColors::RedBright,
    739 763   "-b",
    740 764   "--background",
    skipped 301 lines
    1042 1066   "gRaY",
    1043 1067   "GRAY",
    1044 1068   colors,
     1069 + vec![Colors::Gray],
     1070 + "-c",
     1071 + "--colors",
     1072 + "grey",
     1073 + "gReY",
     1074 + "GREY",
     1075 + colors,
    1045 1076   vec![Colors::RedBright],
    1046 1077   "-c",
    1047 1078   "--colors",
    skipped 42 lines
    1090 1121   "whitebright",
    1091 1122   "wHiTeBrIgHt",
    1092 1123   "WHITEBRIGHT",
     1124 + colors,
     1125 + vec![Colors::Candy],
     1126 + "-c",
     1127 + "--colors",
     1128 + "candy",
     1129 + "CaNdY",
     1130 + "CANDY",
    1093 1131   );
    1094 1132   
    1095 1133   color_test!(
    skipped 67 lines
    1163 1201   "blue,#888,gray",
    1164 1202   "bLuE,#888888,gRaY",
    1165 1203   "BLUE,#888,GRAY",
     1204 + colors,
     1205 + vec![Colors::Blue, Colors::Rgb(Rgb::Val(136, 136, 136)), Colors::Gray],
     1206 + "-c",
     1207 + "--colors",
     1208 + "blue,#888,grey",
     1209 + "bLuE,#888888,gReY",
     1210 + "BLUE,#888,GREY",
    1166 1211   colors,
    1167 1212   vec![Colors::Blue, Colors::Rgb(Rgb::Val(136, 136, 136)), Colors::RedBright],
    1168 1213   "-c",
    skipped 546 lines
    1715 1760   "my text".to_string(),
    1716 1761   "-g".to_string(),
    1717 1762   "trans".to_string()
     1763 + ])
     1764 + .unwrap(),
     1765 + options
     1766 + );
     1767 + }
     1768 + 
     1769 + #[test]
     1770 + fn args_parse_ignored_unknown_arguments() {
     1771 + let options = Options::default();
     1772 + assert_eq!(
     1773 + parse(vec![
     1774 + "path/to/bin".to_string(),
     1775 + "".to_string(),
     1776 + "-u".to_string(),
     1777 + "--unknown".to_string()
    1718 1778   ])
    1719 1779   .unwrap(),
    1720 1780   options
    skipped 121 lines
  • ■ ■ ■ ■ ■ ■
    rust/tests/chars_test.rs
    skipped 252 lines
    253 253   assert_eq!(paint_letter(&letter, 2, &options), output);
    254 254   
    255 255   letter = vec![
     256 + String::from("<c1>red</c1><c2>green</c2><c1>red</c1>"),
     257 + String::from(""),
     258 + String::from("no color"),
     259 + ];
     260 + options.colors = vec![Colors::Red];
     261 + output = vec![
     262 + String::from("\x1b[31mred\x1b[39mgreen\x1b[31mred\x1b[39m"),
     263 + String::from(""),
     264 + String::from("no color"),
     265 + ];
     266 + assert_eq!(paint_letter(&letter, 2, &options), output);
     267 + 
     268 + letter = vec![
    256 269   String::from("<c1>red</c1><c1>red</c1><c1>red</c1><c1>red</c1><c1>red</c1><c1>red</c1>"),
    257 270   String::from("<c1>red</c1><c2>green</c2><c1>red</c1><c3>blue</c3>"),
    258 271   String::from("no color"),
    skipped 43 lines
    302 315   assert_eq!(paint_letter(&letter, 4, &options), output);
    303 316   
    304 317   letter = vec![
     318 + String::from("nothing"),
     319 + String::from("<c2>green</c2> <c1>red</c1>"),
     320 + String::from("<c1>red</c1>"),
     321 + ];
     322 + options.colors = vec![Colors::Red, Colors::Blue];
     323 + options.gradient = vec![String::from("#ff8800"), String::from("#0088ff")];
     324 + output = vec![String::from("nothing"), String::from("green red"), String::from("red")];
     325 + assert_eq!(paint_letter(&letter, 2, &options), output);
     326 + options.gradient = Vec::new();
     327 + 
     328 + letter = vec![
    305 329   String::from("<c1>red</c1>"),
    306 330   String::from("no color"),
    307 331   String::from("<c1>red</c1><c2>green</c2><c1>red</c1><c3>blue</c3>"),
    308 332   ];
    309 333   options.colors = vec![Colors::Red, Colors::Green, Colors::Blue];
     334 + options.env = Env::Browser;
     335 + output = vec![
     336 + String::from("<span style=\"color:#ea3223\">red</span>"),
     337 + String::from("no color"),
     338 + String::from("<span style=\"color:#ea3223\">red</span><span style=\"color:#377d22\">green</span><span style=\"color:#ea3223\">red</span><span style=\"color:#0020f5\">blue</span>"),
     339 + ];
     340 + assert_eq!(paint_letter(&letter, 3, &options), output);
     341 + 
     342 + letter = vec![
     343 + String::from("<c1>red</c1>"),
     344 + String::from("no color"),
     345 + String::from("<c1>red</c1><c2>green</c2><c1>red</c1><c3>blue</c3>"),
     346 + ];
     347 + options.colors = vec![Colors::Red, Colors::Green, Colors::Blue, Colors::Magenta];
    310 348   options.env = Env::Browser;
    311 349   output = vec![
    312 350   String::from("<span style=\"color:#ea3223\">red</span>"),
    skipped 120 lines
  • ■ ■ ■ ■ ■ ■
    rust/tests/cli_test.rs
     1 +extern crate cfonts;
     2 + 
     3 +use cfonts::cli::{help, version};
     4 +use cfonts::config::Options;
     5 + 
     6 +#[cfg(test)]
     7 +mod tests {
     8 + use super::*;
     9 + 
     10 + #[test]
     11 + fn version_works() {
     12 + let options = Options::default();
     13 + assert!(version(&options).contains('v'));
     14 + }
     15 + 
     16 + #[test]
     17 + fn help_works() {
     18 + let options = Options::default();
     19 + assert!(help(&options).contains("sexy fonts in the console"));
     20 + }
     21 +}
     22 + 
  • ■ ■ ■ ■ ■
    rust/tests/color_test.rs
    skipped 122 lines
    123 123   }
    124 124   
    125 125   #[test]
     126 + #[should_panic]
     127 + fn hex2rgb_should_panic() {
     128 + let options = Options::default();
     129 + hex2rgb("#", &options);
     130 + }
     131 + 
     132 + #[test]
    126 133   fn hsv2rsv_works() {
    127 134   let options = Options::default();
    128 135   assert_eq!(hsv2rsv(&Hsv::Val(0.0, 0.0, 0.0), &options), Rsv::Val(0.0, 0.0, 0.0));
    skipped 34 lines
    163 170   #[test]
    164 171   fn color2hex_works() {
    165 172   let options = Options::default();
    166  - assert_eq!(color2hex(&Colors::Red, &options), "#ea3223".to_string());
    167  - assert_eq!(color2hex(&Colors::Rgb(Rgb::Val(255, 0, 0)), &options), "#ff0000".to_string());
     173 + assert_eq!(color2hex(&Colors::System, &options), String::from("transparent"));
     174 + assert_eq!(color2hex(&Colors::Black, &options), String::from("#000000"));
     175 + assert_eq!(color2hex(&Colors::Red, &options), String::from("#ea3223"));
     176 + assert_eq!(color2hex(&Colors::Green, &options), String::from("#377d22"));
     177 + assert_eq!(color2hex(&Colors::Yellow, &options), String::from("#fffd54"));
     178 + assert_eq!(color2hex(&Colors::Blue, &options), String::from("#0020f5"));
     179 + assert_eq!(color2hex(&Colors::Magenta, &options), String::from("#ea3df7"));
     180 + assert_eq!(color2hex(&Colors::Cyan, &options), String::from("#74fbfd"));
     181 + assert_eq!(color2hex(&Colors::White, &options), String::from("#ffffff"));
     182 + assert_eq!(color2hex(&Colors::Gray, &options), String::from("#808080"));
     183 + assert_eq!(color2hex(&Colors::RedBright, &options), String::from("#ee776d"));
     184 + assert_eq!(color2hex(&Colors::GreenBright, &options), String::from("#8cf57b"));
     185 + assert_eq!(color2hex(&Colors::YellowBright, &options), String::from("#fffb7f"));
     186 + assert_eq!(color2hex(&Colors::BlueBright, &options), String::from("#6974f6"));
     187 + assert_eq!(color2hex(&Colors::MagentaBright, &options), String::from("#ee82f8"));
     188 + assert_eq!(color2hex(&Colors::CyanBright, &options), String::from("#8dfafd"));
     189 + 
     190 + assert_eq!(color2hex(&Colors::Rgb(Rgb::Val(255, 0, 0)), &options), String::from("#ff0000"));
     191 + 
     192 + let candy_color = [
     193 + String::from("#ea3223"),
     194 + String::from("#377d22"),
     195 + String::from("#fffd54"),
     196 + String::from("#ea3df7"),
     197 + String::from("#74fbfd"),
     198 + String::from("#ee776d"),
     199 + String::from("#8cf57b"),
     200 + String::from("#fffb7f"),
     201 + String::from("#6974f6"),
     202 + String::from("#ee82f8"),
     203 + String::from("#8dfafd"),
     204 + ];
     205 + assert!(candy_color.contains(&color2hex(&Colors::Candy, &options)));
    168 206   }
    169 207   
    170 208   #[test]
    171 209   fn bgcolor2hex_works() {
    172 210   let options = Options::default();
     211 + assert_eq!(bgcolor2hex(&BgColors::Rgb(Rgb::Val(255, 0, 0)), &options), String::from("#ff0000"));
     212 + 
     213 + assert_eq!(bgcolor2hex(&BgColors::Transparent, &options), "transparent".to_string());
     214 + assert_eq!(bgcolor2hex(&BgColors::Black, &options), "#000000".to_string());
    173 215   assert_eq!(bgcolor2hex(&BgColors::Red, &options), "#ea3223".to_string());
    174  - assert_eq!(bgcolor2hex(&BgColors::Rgb(Rgb::Val(255, 0, 0)), &options), "#ff0000".to_string());
     216 + assert_eq!(bgcolor2hex(&BgColors::Green, &options), "#377d22".to_string());
     217 + assert_eq!(bgcolor2hex(&BgColors::Yellow, &options), "#fffd54".to_string());
     218 + assert_eq!(bgcolor2hex(&BgColors::Blue, &options), "#0020f5".to_string());
     219 + assert_eq!(bgcolor2hex(&BgColors::Magenta, &options), "#ea3df7".to_string());
     220 + assert_eq!(bgcolor2hex(&BgColors::Cyan, &options), "#74fbfd".to_string());
     221 + assert_eq!(bgcolor2hex(&BgColors::White, &options), "#ffffff".to_string());
     222 + assert_eq!(bgcolor2hex(&BgColors::Gray, &options), "#808080".to_string());
     223 + assert_eq!(bgcolor2hex(&BgColors::RedBright, &options), "#ee776d".to_string());
     224 + assert_eq!(bgcolor2hex(&BgColors::GreenBright, &options), "#8cf57b".to_string());
     225 + assert_eq!(bgcolor2hex(&BgColors::YellowBright, &options), "#fffb7f".to_string());
     226 + assert_eq!(bgcolor2hex(&BgColors::BlueBright, &options), "#6974f6".to_string());
     227 + assert_eq!(bgcolor2hex(&BgColors::MagentaBright, &options), "#ee82f8".to_string());
     228 + assert_eq!(bgcolor2hex(&BgColors::CyanBright, &options), "#8dfafd".to_string());
    175 229   }
    176 230   
    177 231   #[test]
    skipped 12 lines
    190 244   #[test]
    191 245   fn rgb_u8_2ansi_256_works() {
    192 246   assert_eq!(rgb_u8_2ansi_256(100, 200, 100), 114);
    193  - assert_eq!(rgb_u8_2ansi_256(255, 255, 255), 16);
    194  - assert_eq!(rgb_u8_2ansi_256(0, 0, 0), 231);
     247 + assert_eq!(rgb_u8_2ansi_256(255, 255, 255), 231);
     248 + assert_eq!(rgb_u8_2ansi_256(0, 0, 0), 16);
    195 249   assert_eq!(rgb_u8_2ansi_256(167, 5, 98), 126);
    196 250   }
    197 251   
    skipped 1 lines
    199 253   fn rgb2ansi_256_works() {
    200 254   assert_eq!(rgb2ansi_256(&Rgb::Val(255, 0, 0), ColorLayer::Foreground), "\x1b[38;5;196m".to_string());
    201 255   assert_eq!(rgb2ansi_256(&Rgb::Val(255, 255, 0), ColorLayer::Foreground), "\x1b[38;5;226m".to_string());
    202  - assert_eq!(rgb2ansi_256(&Rgb::Val(255, 255, 255), ColorLayer::Foreground), "\x1b[38;5;16m".to_string());
     256 + assert_eq!(rgb2ansi_256(&Rgb::Val(255, 255, 255), ColorLayer::Foreground), "\x1b[38;5;231m".to_string());
    203 257   assert_eq!(rgb2ansi_256(&Rgb::Val(157, 5, 98), ColorLayer::Foreground), "\x1b[38;5;126m".to_string());
    204 258   
    205 259   assert_eq!(rgb2ansi_256(&Rgb::Val(255, 0, 0), ColorLayer::Background), "\x1b[48;5;196m".to_string());
    206 260   assert_eq!(rgb2ansi_256(&Rgb::Val(255, 255, 0), ColorLayer::Background), "\x1b[48;5;226m".to_string());
    207  - assert_eq!(rgb2ansi_256(&Rgb::Val(255, 255, 255), ColorLayer::Background), "\x1b[48;5;16m".to_string());
     261 + assert_eq!(rgb2ansi_256(&Rgb::Val(255, 255, 255), ColorLayer::Background), "\x1b[48;5;231m".to_string());
    208 262   assert_eq!(rgb2ansi_256(&Rgb::Val(157, 5, 98), ColorLayer::Background), "\x1b[48;5;126m".to_string());
    209 263   }
    210 264   
    skipped 1 lines
    212 266   fn rgb2ansi_16_works() {
    213 267   assert_eq!(rgb2ansi_16(&Rgb::Val(255, 0, 0), ColorLayer::Foreground), "\x1b[91m".to_string());
    214 268   assert_eq!(rgb2ansi_16(&Rgb::Val(255, 255, 0), ColorLayer::Foreground), "\x1b[93m".to_string());
    215  - assert_eq!(rgb2ansi_16(&Rgb::Val(255, 255, 255), ColorLayer::Foreground), "\x1b[0m".to_string());
     269 + assert_eq!(rgb2ansi_16(&Rgb::Val(255, 255, 255), ColorLayer::Foreground), "\x1b[97m".to_string());
    216 270   assert_eq!(rgb2ansi_16(&Rgb::Val(157, 5, 98), ColorLayer::Foreground), "\x1b[31m".to_string());
    217 271   
    218 272   assert_eq!(rgb2ansi_16(&Rgb::Val(255, 0, 0), ColorLayer::Background), "\x1b[101m".to_string());
    219 273   assert_eq!(rgb2ansi_16(&Rgb::Val(255, 255, 0), ColorLayer::Background), "\x1b[103m".to_string());
    220  - assert_eq!(rgb2ansi_16(&Rgb::Val(255, 255, 255), ColorLayer::Background), "\x1b[10m".to_string());
     274 + assert_eq!(rgb2ansi_16(&Rgb::Val(255, 255, 255), ColorLayer::Background), "\x1b[107m".to_string());
    221 275   assert_eq!(rgb2ansi_16(&Rgb::Val(157, 5, 98), ColorLayer::Background), "\x1b[41m".to_string());
    222 276   }
    223 277   
    skipped 15 lines
    239 293   assert_eq!(get_foreground_color(&Colors::Red), (String::from("\x1b[31m"), String::from("\x1b[39m")));
    240 294   assert_eq!(get_foreground_color(&Colors::Green), (String::from("\x1b[32m"), String::from("\x1b[39m")));
    241 295   assert_eq!(get_foreground_color(&Colors::Blue), (String::from("\x1b[34m"), String::from("\x1b[39m")));
     296 + 
     297 + let candy_color = [
     298 + String::from("\x1b[31m"),
     299 + String::from("\x1b[32m"),
     300 + String::from("\x1b[33m"),
     301 + String::from("\x1b[35m"),
     302 + String::from("\x1b[36m"),
     303 + String::from("\x1b[91m"),
     304 + String::from("\x1b[92m"),
     305 + String::from("\x1b[93m"),
     306 + String::from("\x1b[94m"),
     307 + String::from("\x1b[95m"),
     308 + String::from("\x1b[96m"),
     309 + ];
     310 + assert!(candy_color.contains(&get_foreground_color(&Colors::Candy).0));
    242 311   });
    243 312   }
    244 313   
    skipped 261 lines
  • ■ ■ ■ ■ ■ ■
    rust/tests/end-to-end_test.rs
    skipped 11 lines
    12 12   extern crate temp_env;
    13 13   
    14 14   use super::*;
    15  - use std::path::Path;
     15 + use assert_cmd::prelude::*;
    16 16   use std::process::Command;
    17 17   
    18 18   #[test]
    skipped 11 lines
    30 30   let no_color_val = if test.no_color { Some(appendix) } else { None };
    31 31   
    32 32   temp_env::with_vars(vec![("FORCE_COLOR", force_color_val), ("NO_COLOR", no_color_val)], || {
    33  - let output = Command::new(Path::new("target/release/cfonts").as_os_str())
    34  - .args(&test.args)
    35  - .output()
    36  - .expect("failed to execute process");
     33 + let output =
     34 + Command::cargo_bin("cfonts").unwrap().args(&test.args).output().expect("failed to execute process");
    37 35   
    38 36   assert_eq!(String::from_utf8_lossy(&output.stdout).to_string() + appendix, test.fixture.clone() + appendix);
    39 37   });
    skipped 1895 lines
  • ■ ■ ■ ■ ■ ■
    rust/tests/font_test.rs
     1 +extern crate cfonts;
     2 + 
     3 +use std::collections::HashMap;
     4 + 
     5 +use cfonts::config::{Fonts, Options};
     6 +use cfonts::font::get;
     7 + 
     8 +#[cfg(test)]
     9 +mod tests {
     10 + use super::*;
     11 + 
     12 + #[test]
     13 + #[should_panic]
     14 + fn get_works() {
     15 + let options = Options::default();
     16 + let mut fonts = HashMap::new();
     17 + let font_content = "your invalid font data";
     18 + fonts.insert(Fonts::FontConsole, font_content);
     19 + fonts.insert(Fonts::FontBlock, font_content);
     20 + fonts.insert(Fonts::FontSimpleBlock, font_content);
     21 + fonts.insert(Fonts::FontSimple, font_content);
     22 + fonts.insert(Fonts::Font3d, font_content);
     23 + fonts.insert(Fonts::FontSimple3d, font_content);
     24 + fonts.insert(Fonts::FontChrome, font_content);
     25 + fonts.insert(Fonts::FontHuge, font_content);
     26 + fonts.insert(Fonts::FontShade, font_content);
     27 + fonts.insert(Fonts::FontSlick, font_content);
     28 + fonts.insert(Fonts::FontGrid, font_content);
     29 + fonts.insert(Fonts::FontPallet, font_content);
     30 + fonts.insert(Fonts::FontTiny, font_content);
     31 + 
     32 + get(&fonts, &options);
     33 + }
     34 +}
     35 + 
  • ■ ■ ■ ■ ■ ■
    rust/tests/lib_test.rs
     1 +extern crate cfonts;
     2 + 
     3 +use cfonts::{say, Options};
     4 + 
     5 +#[cfg(test)]
     6 +mod tests {
     7 + use super::*;
     8 + 
     9 + #[test]
     10 + fn say_works() {
     11 + say(Options {
     12 + text: String::from("hello"),
     13 + ..Options::default()
     14 + });
     15 + }
     16 +}
     17 + 
Please wait...
Page is in error, reload to recover