figlet-rs 1.0.0

Rust implementation of FIGlet to create ascii art
Documentation

figlet-rs

CI docs crates.io

A Rust library for FIGlet and Toilet fonts to generate ascii art.

The default rendering behavior follows the font's built-in FIGlet layout settings, including horizontal kerning and smushing. The current output is tested against fixtures generated from local figlet and toilet binaries, but running tests does not require either tool to be installed.

Example

use figlet_rs::{FIGlet, Toilet};

fn main() {
    let standard_font = FIGlet::standard().unwrap();
    let small_font = FIGlet::small().unwrap();
    let big_font = FIGlet::big().unwrap();
    let slant_font = FIGlet::slant().unwrap();
    let smblock_font = Toilet::smblock().unwrap();
    let mono12_font = Toilet::mono12().unwrap();
    let future_font = Toilet::future().unwrap();
    let wideterm_font = Toilet::wideterm().unwrap();
    let mono9_font = Toilet::mono9().unwrap();

    println!("{}", standard_font.convert("Hello Rust").unwrap());
    println!("{}", small_font.convert("Test").unwrap());
    println!("{}", big_font.convert("Test").unwrap());
    println!("{}", slant_font.convert("Test").unwrap());
    println!("{}", smblock_font.convert("Toilet").unwrap());
    println!("{}", mono12_font.convert("Test").unwrap());
    println!("{}", future_font.convert("Test").unwrap());
    println!("{}", wideterm_font.convert("Test").unwrap());
    println!("{}", mono9_font.convert("Test").unwrap());
}

Output:

 _   _      _ _         ____            _
| | | | ___| | | ___   |  _ \ _   _ ___| |_
| |_| |/ _ \ | |/ _ \  | |_) | | | / __| __|
|  _  |  __/ | | (_) | |  _ <| |_| \__ \ |_
|_| |_|\___|_|_|\___/  |_| \_\\__,_|___/\__|


 _____       _
|_   _|__ __| |_
  | |/ -_|_-<  _|
  |_|\___/__/\__|


 _______        _
|__   __|      | |
   | | ___  ___| |_
   | |/ _ \/ __| __|
   | |  __/\__ \ |_
   |_|\___||___/\__|



  ______          __
 /_  __/__  _____/ /_
  / / / _ \/ ___/ __/
 / / /  __(__  ) /_
/_/  \___/____/\__/


▀▛▘  ▗▜    ▐
 ▌▞▀▖▄▐ ▞▀▖▜▀
 ▌▌ ▌▐▐ ▛▀ ▐ ▖
 ▘▝▀ ▀▘▘▝▀▘ ▀


 ▄▄▄▄▄▄▄▄
 ▀▀▀██▀▀▀                        ██
    ██      ▄████▄   ▄▄█████▄  ███████
    ██     ██▄▄▄▄██  ██▄▄▄▄ ▀    ██
    ██     ██▀▀▀▀▀▀   ▀▀▀▀██▄    ██
    ██     ▀██▄▄▄▄█  █▄▄▄▄▄██    ██▄▄▄
    ▀▀       ▀▀▀▀▀    ▀▀▀▀▀▀      ▀▀▀▀



╺┳╸┏━╸┏━┓╺┳╸
 ┃ ┣╸ ┗━┓ ┃
 ╹ ┗━╸┗━┛ ╹

Test


▄▄▄▄▄▄▄                 ▄
   █     ▄▄▄    ▄▄▄   ▄▄█▄▄
   █    █▀  █  █   ▀    █
   █    █▀▀▀▀   ▀▀▀▄    █
   █    ▀█▄▄▀  ▀▄▄▄▀    ▀▄▄


Load A Font File

use figlet_rs::{FIGlet, Toilet};

fn main() {
    let figlet_font = FIGlet::from_file("resources/small.flf").unwrap();
    let toilet_font = Toilet::from_file("resources/smblock.tlf").unwrap();

    println!("{}", figlet_font.convert("Test").unwrap());
    println!("{}", toilet_font.convert("Toilet").unwrap());
}

The FIGlet output matches:

figlet -f resources/small.flf Test

The Toilet output matches:

toilet -d resources -f smblock.tlf Toilet

Built-in Fonts

The crate bundles these fonts as built-in APIs:

FIGlet:

  • FIGlet::standard() loads resources/standard.flf
  • FIGlet::small() loads resources/small.flf
  • FIGlet::big() loads resources/big.flf
  • FIGlet::slant() loads resources/slant.flf

Toilet:

  • Toilet::smblock() loads resources/smblock.tlf
  • Toilet::mono12() loads resources/mono12.tlf
  • Toilet::future() loads resources/future.tlf
  • Toilet::wideterm() loads resources/wideterm.tlf
  • Toilet::mono9() loads resources/mono9.tlf

Use FIGlet::from_file(...) to load custom .flf files.

Use Toilet::from_file(...) to load custom .tlf files, including zip-packaged .tlf files.

Testing

Fixtures live in tests/fixtures. They are committed to the repository so cargo test stays stable in environments without local figlet or toilet binaries.

If you want to refresh the FIGlet fixtures on a machine that already has figlet, run:

./scripts/generate_figlet_fixtures.sh

If you want to refresh the Toilet fixtures on a machine that already has toilet, run:

./scripts/generate_toilet_fixtures.sh

License

rs-figlet is distributed under the terms of the Apache License (Version 2.0).

See LICENSE-APACHE and COPYRIGHT for details.