Projects STRLCPY cfonts Commits e8b9b4ef
🤬
  • ■ ■ ■ ■ ■ ■
    README.md
    skipped 6 lines
    7 7   ╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝ ╚══════╝
    8 8  ```
    9 9   
    10  -![cfont styles](./img/example1.png)
     10 +![cfont styles](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/example1.png)
    11 11   
    12  -<p align="center"><img src="./img/example2.png" alt="api example"></p>
     12 +<p align="center"><img src="https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/example2.png" alt="api example"></p>
    13 13  <p align="center">
    14 14   <a href="https://crates.io/crates/cfonts"><img src="https://img.shields.io/crates/v/cfonts.svg" alt="crates badge"></a>
    15 15   <a href="https://crates.io/crates/cfonts"><img src="https://docs.rs/cfonts/badge.svg" alt="crates docs tests"></a>
    skipped 8 lines
    24 24   
    25 25  ### Rust
    26 26   
    27  -Read more in the [Rust folder](./rust).
     27 +Read more in the [Rust folder](https://github.com/dominikwilkowski/cfonts/tree/released/rust).
    28 28   
    29 29  ### Nodejs
    30 30   
    31  -Read more in the [Nodejs folder](./nodejs).
     31 +Read more in the [Nodejs folder](https://github.com/dominikwilkowski/cfonts/tree/released/nodejs).
    32 32   
    33 33   
    34 34  ## Install
    skipped 123 lines
    158 158  $ cfonts --help
    159 159  ```
    160 160   
    161  -![Help command](./img/help.png)
     161 +![Help command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/help.png)
    162 162   
    163 163   
    164 164  #### -V, --version
    skipped 6 lines
    171 171  $ cfonts --version
    172 172  ```
    173 173   
    174  -![Version command](./img/version.png)
     174 +![Version command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/version.png)
    175 175   
    176 176   
    177 177  #### text
    skipped 7 lines
    185 185  $ cfonts "Hello world"
    186 186  ```
    187 187   
    188  -![Text command](./img/text.png)
     188 +![Text command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/text.png)
    189 189   
    190 190   
    191 191  #### -f, --font
    skipped 6 lines
    198 198  $ cfonts "text" --font "chrome"
    199 199  ```
    200 200   
    201  -![Font command](./img/font.png)
     201 +![Font command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/font.png)
    202 202   
    203 203  - `block` [colors: 2] _(default)_
    204  - ![block font style](./img/block.png)
     204 + ![block font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/block.png)
    205 205  - `slick` [colors: 2]
    206  - ![slick font style](./img/slick.png)
     206 + ![slick font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/slick.png)
    207 207  - `tiny` [colors: 1]
    208  - ![tiny font style](./img/tiny.png)
     208 + ![tiny font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/tiny.png)
    209 209  - `grid` [colors: 2]
    210  - ![grid font style](./img/grid.png)
     210 + ![grid font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/grid.png)
    211 211  - `pallet` [colors: 2]
    212  - ![pallet font style](./img/pallet.png)
     212 + ![pallet font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/pallet.png)
    213 213  - `shade` [colors: 2]
    214  - ![shade font style](./img/shade.png)
     214 + ![shade font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/shade.png)
    215 215  - `chrome` [colors: 3]
    216  - ![chrome font style](./img/chrome.png)
     216 + ![chrome font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/chrome.png)
    217 217  - `simple` [colors: 1]
    218  - ![simple font style](./img/simple.png)
     218 + ![simple font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/simple.png)
    219 219  - `simpleBlock` [colors: 1]
    220  - ![simple-block font style](./img/simple-block.png)
     220 + ![simple-block font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/simple-block.png)
    221 221  - `3d` [colors: 2]
    222  - ![3d font style](./img/3d.png)
     222 + ![3d font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/3d.png)
    223 223  - `simple3d` [colors: 1]
    224  - ![simple-3d font style](./img/simple-3d.png)
     224 + ![simple-3d font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/simple-3d.png)
    225 225  - `huge` [colors: 2]
    226  - ![huge font style](./img/huge.png)
     226 + ![huge font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/huge.png)
    227 227  - `console` [colors: 1]
    228  - ![console font style](./img/console.png)
     228 + ![console font style](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/console.png)
    229 229   
    230 230   
    231 231  #### -a, --align
    skipped 12 lines
    244 244  $ cfonts "text" --align "center"
    245 245  ```
    246 246   
    247  -![Align command](./img/align.png)
     247 +![Align command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/align.png)
    248 248   
    249 249   
    250 250  #### -c, --colors
    skipped 32 lines
    283 283  $ cfonts "text" --colors white,"#f80"
    284 284  ```
    285 285   
    286  -![Colors command](./img/colors.png)
     286 +![Colors command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/colors.png)
    287 287   
    288 288   
    289 289  #### -g, --gradient
    skipped 25 lines
    315 315  $ cfonts "text" --gradient red,"#f80"
    316 316  ```
    317 317   
    318  -![Gradient command](./img/gradient.png)
     318 +![Gradient command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/gradient.png)
    319 319   
    320 320   
    321 321  #### -i, --independent-gradient
    skipped 7 lines
    329 329  $ cfonts "text|next line" --gradient red,"#f80" --independent-gradient
    330 330  ```
    331 331   
    332  -![Independent gradient command](./img/independent-gradient.png)
     332 +![Independent gradient command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/independent-gradient.png)
    333 333   
    334 334   
    335 335  #### -t, --transition-gradient
    skipped 9 lines
    345 345  $ cfonts "text" --gradient red,"#f80",green,blue --transition-gradient
    346 346  ```
    347 347   
    348  -![Independent gradient command](./img/transition-gradient.png)
     348 +![Independent gradient command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/transition-gradient.png)
    349 349   
    350 350   
    351 351  #### -b, --background
    skipped 27 lines
    379 379  $ cfonts "text" --background "Green"
    380 380  ```
    381 381   
    382  -![Background command](./img/background.png)
     382 +![Background command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/background.png)
    383 383   
    384 384   
    385 385  #### -l, --letter-spacing
    skipped 6 lines
    392 392  $ cfonts "text" --letter-spacing 2
    393 393  ```
    394 394   
    395  -![Letter spacing command](./img/letter-spacing.png)
     395 +![Letter spacing command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/letter-spacing.png)
    396 396   
    397 397   
    398 398  #### -z, --line-height
    skipped 6 lines
    405 405  $ cfonts "text" --line-height 2
    406 406  ```
    407 407   
    408  -![Line height command](./img/line-height.png)
     408 +![Line height command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/line-height.png)
    409 409   
    410 410   
    411 411  #### -s, --spaceless
    skipped 6 lines
    418 418  $ cfonts "text" --spaceless
    419 419  ```
    420 420   
    421  -![Spaceless command](./img/spaceless.png)
     421 +![Spaceless command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/spaceless.png)
    422 422   
    423 423   
    424 424  #### -m, --max-length
    skipped 8 lines
    433 433  $ cfonts "text" --max-length 15
    434 434  ```
    435 435   
    436  -![Max length command](./img/max-length.png)
     436 +![Max length command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/max-length.png)
    437 437   
    438 438   
    439 439  #### -e, --env
    skipped 7 lines
    447 447  $ cfonts "text" --env browser
    448 448  ```
    449 449   
    450  -![Max length command](./img/env.png)
     450 +![Max length command](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/env.png)
    451 451   
    452 452   
    453 453  ## Consistency
    skipped 13 lines
    467 467   
    468 468  💡 `FORCE_COLOR` overrides `NO_COLOR` if both are set.
    469 469   
    470  -![Color consistency via env vars](./img/color-consistency.png)
     470 +![Color consistency via env vars](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/color-consistency.png)
    471 471   
    472 472   
    473 473  ## License
    skipped 3 lines
  • ■ ■ ■ ■ ■ ■
    nodejs/README.md
    skipped 6 lines
    7 7   ╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝ ╚══════╝ ╝╚╝ ╚═╝ ═╩╝ ╚═╝ ╚╝ ╚═╝
    8 8  ```
    9 9   
    10  -![cfont styles](../img/example1.png)
     10 +![cfont styles](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/example1.png)
    11 11   
    12  -<p align="center"><img src="../img/example2.png" alt="api example"></p>
     12 +<p align="center"><img src="https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/example2.png" alt="api example"></p>
    13 13  <p align="center">
    14 14   <a href="https://github.com/dominikwilkowski/cfonts/actions/workflows/testing.yml"><img src="https://github.com/dominikwilkowski/cfonts/actions/workflows/testing.yml/badge.svg" alt="build status"></a>
    15 15   <a href="https://www.npmjs.com/package/cfonts"><img alt="npm" src="https://img.shields.io/npm/v/cfonts"></a>
    skipped 63 lines
    79 79   
    80 80  ## CLI Usage
    81 81   
    82  -Read more in the [root repo](../).
     82 +Read more in the [root repo](https://github.com/dominikwilkowski/cfonts).
    83 83   
    84 84   
    85 85  ## Tests
    skipped 148 lines
  • ■ ■ ■ ■ ■
    rust/Cargo.toml
    1 1  [package]
    2 2  name = "cfonts"
    3  -version = "1.0.0"
     3 +version = "1.0.1"
    4 4  edition = "2021"
    5 5  authors = ["Dominik Wilkowski <[email protected]>"]
    6 6  license = "GPL-3.0-or-later"
    skipped 4 lines
    11 11  documentation = "https://docs.rs/cfonts/"
    12 12  keywords = ["fonts", "color", "console", "ascii", "ANSI"]
    13 13  categories = ["command-line-interface", "command-line-utilities", "graphics"]
    14  -include = ["/fonts", "/src", "!.DS_Store"]
    15 14   
    16 15  [dependencies]
    17 16  exitcode = "1.1.2"
    skipped 12 lines
  • ■ ■ ■ ■ ■ ■
    rust/README.md
    skipped 6 lines
    7 7   ╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝ ╚══════╝ ╩╚═ ╚═╝ ╚═╝ ╩
    8 8  ```
    9 9   
    10  -![cfont styles](../img/example1.png)
     10 +![cfont styles](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/example1.png)
    11 11   
    12  -<p align="center"><img src="../img/example2.png" alt="api example"></p>
     12 +<p align="center"><img src="https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/example2.png" alt="api example"></p>
    13 13  <p align="center">
    14 14   <a href="https://crates.io/crates/cfonts"><img src="https://img.shields.io/crates/v/cfonts.svg" alt="crates badge"></a>
    15 15   <a href="https://crates.io/crates/cfonts"><img src="https://docs.rs/cfonts/badge.svg" alt="crates docs tests"></a>
    skipped 96 lines
    112 112   
    113 113  ## CLI Usage
    114 114   
    115  -Read more in the [root repo](../).
     115 +Read more in the [root repo](https://github.com/dominikwilkowski/cfonts).
    116 116   
    117 117   
    118 118  ## Tests
    skipped 15 lines
    134 134   
    135 135  ## Release History
    136 136   
     137 +* 1.0.1 - Fixed font loading
    137 138  * 1.0.0 - Public release of rust API
    138 139  * 0.1.0 - alpha test
    139 140   
    skipped 6 lines
  • ■ ■ ■ ■
    rust/src/config.rs
    skipped 8 lines
    9 9  /// The `Fonts` enum includes all font options you have for the cfonts output
    10 10  ///
    11 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)]
     12 +#[derive(EnumIter, Debug, Clone, PartialEq, Eq, Hash)]
    13 13  pub enum Fonts {
    14 14   /// ![The "console" cfonts font](https://raw.githubusercontent.com/dominikwilkowski/cfonts/released/img/console.png)
    15 15   FontConsole,
    skipped 484 lines
  • ■ ■ ■ ■ ■ ■
    rust/src/font.rs
    skipped 2 lines
    3 3  use serde::Deserialize;
    4 4   
    5 5  use std::collections::HashMap;
    6  -use std::fs::read_to_string;
    7  -use std::path::Path;
    8 6   
    9 7  use crate::color::color;
    10 8  use crate::config::{Colors, Fonts, Options};
    skipped 22 lines
    33 31   pub chars: HashMap<String, Vec<String>>,
    34 32  }
    35 33   
     34 +/// Function to embed the data of our font files into our binary
     35 +///
     36 +/// ```rust
     37 +/// extern crate cfonts;
     38 +///
     39 +/// use cfonts::{ Options, Fonts };
     40 +/// use cfonts::font::{load_all_fonts, get};
     41 +///
     42 +/// let mut options = Options::default();
     43 +/// options.font = Fonts::FontChrome;
     44 +///
     45 +/// let fonts = load_all_fonts(); // our HashMap of all font files content
     46 +/// let this_font = get(&fonts, &options);
     47 +/// assert_eq!(this_font.name, String::from("chrome"));
     48 +/// ```
     49 +pub fn load_all_fonts() -> HashMap<Fonts, &'static str> {
     50 + let mut fonts = HashMap::new();
     51 + 
     52 + let font_content = include_str!("../fonts/console.json");
     53 + fonts.insert(Fonts::FontConsole, font_content);
     54 + 
     55 + let font_content = include_str!("../fonts/block.json");
     56 + fonts.insert(Fonts::FontBlock, font_content);
     57 + 
     58 + let font_content = include_str!("../fonts/simpleBlock.json");
     59 + fonts.insert(Fonts::FontSimpleBlock, font_content);
     60 + 
     61 + let font_content = include_str!("../fonts/simple.json");
     62 + fonts.insert(Fonts::FontSimple, font_content);
     63 + 
     64 + let font_content = include_str!("../fonts/3d.json");
     65 + fonts.insert(Fonts::Font3d, font_content);
     66 + 
     67 + let font_content = include_str!("../fonts/simple3d.json");
     68 + fonts.insert(Fonts::FontSimple3d, font_content);
     69 + 
     70 + let font_content = include_str!("../fonts/chrome.json");
     71 + fonts.insert(Fonts::FontChrome, font_content);
     72 + 
     73 + let font_content = include_str!("../fonts/huge.json");
     74 + fonts.insert(Fonts::FontHuge, font_content);
     75 + 
     76 + let font_content = include_str!("../fonts/shade.json");
     77 + fonts.insert(Fonts::FontShade, font_content);
     78 + 
     79 + let font_content = include_str!("../fonts/slick.json");
     80 + fonts.insert(Fonts::FontSlick, font_content);
     81 + 
     82 + let font_content = include_str!("../fonts/grid.json");
     83 + fonts.insert(Fonts::FontGrid, font_content);
     84 + 
     85 + let font_content = include_str!("../fonts/pallet.json");
     86 + fonts.insert(Fonts::FontPallet, font_content);
     87 + 
     88 + let font_content = include_str!("../fonts/tiny.json");
     89 + fonts.insert(Fonts::FontTiny, font_content);
     90 + 
     91 + fonts
     92 +}
     93 + 
    36 94  /// Function to get the data of the font chosen
    37 95  ///
    38 96  /// ```rust
    39 97  /// extern crate cfonts;
    40 98  ///
    41 99  /// use cfonts::{ Options, Fonts };
    42  -/// use cfonts::font::get;
     100 +/// use cfonts::font::{load_all_fonts, get};
    43 101  ///
    44 102  /// let mut options = Options::default();
    45 103  /// options.font = Fonts::FontChrome;
    46 104  ///
    47  -/// let this_font = get(&options);
     105 +/// let fonts = load_all_fonts();
     106 +/// let this_font = get(&fonts, &options);
    48 107  /// assert_eq!(this_font.name, String::from("chrome"));
    49 108  /// ```
    50 109  ///
    skipped 3 lines
    54 113  /// extern crate cfonts;
    55 114  ///
    56 115  /// use cfonts::{ Options, Fonts };
    57  -/// use cfonts::font::get;
     116 +/// use cfonts::font::{load_all_fonts, get};
    58 117  ///
    59 118  /// let mut options = Options::default();
    60 119  /// options.font = Fonts::FontConsole;
    61 120  ///
    62  -/// let this_font = get(&options);
     121 +/// let fonts = load_all_fonts();
     122 +/// let this_font = get(&fonts, &options);
    63 123  /// assert_eq!(this_font.chars.get("D").unwrap(), &vec![String::from("d")]);
    64 124  /// ```
    65  -pub fn get(options: &Options) -> Font {
     125 +pub fn get(fonts: &HashMap<Fonts, &'static str>, options: &Options) -> Font {
    66 126   d("font::get()", 5, Dt::Head, options, &mut std::io::stdout());
    67 127   d(&format!("font::get()\noptions.font{:?}", options.font), 5, Dt::Log, options, &mut std::io::stdout());
    68  - let filename = match options.font {
    69  - Fonts::FontBlock => "./fonts/block.json",
    70  - Fonts::FontSimpleBlock => "./fonts/simpleBlock.json",
    71  - Fonts::FontSimple => "./fonts/simple.json",
    72  - Fonts::Font3d => "./fonts/3d.json",
    73  - Fonts::FontSimple3d => "./fonts/simple3d.json",
    74  - Fonts::FontChrome => "./fonts/chrome.json",
    75  - Fonts::FontHuge => "./fonts/huge.json",
    76  - Fonts::FontShade => "./fonts/shade.json",
    77  - Fonts::FontSlick => "./fonts/slick.json",
    78  - Fonts::FontGrid => "./fonts/grid.json",
    79  - Fonts::FontPallet => "./fonts/pallet.json",
    80  - Fonts::FontTiny => "./fonts/tiny.json",
    81  - Fonts::FontConsole => "./fonts/console.json",
    82  - };
    83  - d(&format!("font::get() read font file at \"{}\"", filename), 5, Dt::Log, options, &mut std::io::stdout());
     128 + let data = fonts.get(&options.font).unwrap();
    84 129   
    85  - let data = read_to_string(Path::new(filename).as_os_str())
    86  - .unwrap_or(format!("Unable to read file \"{}\"", color(filename, Colors::Red)));
    87  - serde_json::from_str(&data).unwrap_or_else(|error| {
     130 + serde_json::from_str(data).unwrap_or_else(|error| {
    88 131   panic!(
    89 132   "JSON parsing error encountered for: \"{}\"\nError: {}",
    90  - color(filename, Colors::Red),
     133 + color(&format!("{:?}", options.font), Colors::Red),
    91 134   color(&format!("{}", error), Colors::Yellow)
    92 135   )
    93 136   })
    skipped 2 lines
  • ■ ■ ■ ■ ■
    rust/src/render.rs
    skipped 76 lines
    77 77   };
    78 78   d(&format!("render()\nterminal_width:{:?}", terminal_width), 1, Dt::Log, &options, &mut std::io::stdout());
    79 79   
    80  - let mut font = font::get(&options);
     80 + let fonts = font::load_all_fonts();
     81 + let mut font = font::get(&fonts, &options);
    81 82   let mut line_length = 0;
    82 83   let mut letter_count = 0;
    83 84   let mut lines = 0;
    skipped 149 lines
Please wait...
Page is in error, reload to recover