81 lines
2 KiB
Markdown
81 lines
2 KiB
Markdown
# FIGlet Font Examples
|
|
|
|
The `figlet-rs` crate supports multiple fonts. Here are some examples of how to use different fonts:
|
|
|
|
## Using Different Fonts
|
|
|
|
```rust
|
|
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 `banner` command)
|
|
- **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
|
|
|
|
1. Download fonts from http://www.figlet.org/fontdb.cgi
|
|
2. Place `.flf` files in a `fonts/` directory in your project
|
|
3. Load them with `FIGfont::from_file("fonts/yourfont.flf")`
|
|
4. 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:
|
|
|
|
```rust
|
|
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");
|
|
}
|
|
```
|