2 KiB
2 KiB
FIGlet Font Examples
The figlet-rs crate supports multiple fonts. Here are some examples of how to use different fonts:
Using Different Fonts
use figlet_rs::FIGfont;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Standard font (built-in)
let standard = FIGfont::standard()?;
if let Some(fig) = standard.convert("Standard") {
println!("{}", fig);
}
// You can also load custom fonts from files
// Download fonts from: http://www.figlet.org/fontdb.cgi
// Example with a custom font file:
// let font = FIGfont::from_file("path/to/font.flf")?;
// if let Some(fig) = font.convert("Custom") {
// println!("{}", fig);
// }
Ok(())
}
Popular FIGlet Fonts
Some popular fonts you might want to try (download from figlet.org):
- standard - The default, classic font (built-in)
- banner - Large block letters (similar to the Unix
bannercommand) - big - Large letters
- block - Blocky style
- bubble - Rounded bubble letters
- digital - Digital/LED style
- lean - Slanted letters
- mini - Compact font
- script - Cursive style
- shadow - Letters with shadows
- slant - Slanted text
- small - Small letters
Example Output (Standard Font)
_ _ _ _
| | | | ___| | | ___
| |_| |/ _ \ | |/ _ \
| _ | __/ | | (_) |
|_| |_|\___|_|_|\___/
Adding Custom Fonts to Your Project
- Download fonts from http://www.figlet.org/fontdb.cgi
- Place
.flffiles in afonts/directory in your project - Load them with
FIGfont::from_file("fonts/yourfont.flf") - If using Nix, include the font files in your Docker image
Alternative: Multiple Text Styles
You can also create multiple banner styles in your application:
fn print_banner(text: &str) {
let font = FIGfont::standard().unwrap();
if let Some(figure) = font.convert(text) {
println!("{}", figure);
}
}
fn main() {
print_banner("HELLO");
print_banner("WORLD");
}