Python FIGLet rendering library โ render text as ASCII art using .flf fonts
Project description
๐ BYTEFORGE FIGLET SUITE โ byteforge-figlet (Python Library)
โโโโโโโ โโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโ โโโโโโโ โโโโโโโ โโโโโโโโ
โโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโ
โโโโโโโโ โโโโโโโ โโโ โโโโโโ โโโโโโ โโโ โโโโโโโโโโโโโโ โโโโโโโโโโ
โโโโโโโโ โโโโโ โโโ โโโโโโ โโโโโโ โโโ โโโโโโโโโโโโโโ โโโโโโโโโ
โโโโโโโโ โโโ โโโ โโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โโโโโโโ โโโ โโโ โโโโโโโโโโโ โโโโโโโ โโโ โโโ โโโโโโโ โโโโโโโโ
โโโโโโโโโโโ โโโโโโโ โโโ โโโโโโโโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโ โโโ โโโโโโโโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโ โโโโโโ โโโโโโโ โโโโโโ โโโ โโโโโโโโโโโ โโโโโโ โโโ โโโโโโ
โโโโโโ โโโโโโ โโโโโโ โโโโโโ โโโ โโโโโโโโโโโ โโโโโโ โโโ โโโโโโ
โโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโ โโโโโโโโโโโโโโโโโโโโ โโโ โโโโโโโโ
โโโ โโโ โโโโโโโ โโโโโโโโโโโโโโโโ โโโ โโโโโโโโ โโโโโโโ โโโ โโโ โโโโโโโโ
byteforge-figlet A fast, spec-compliant FIGLet engine for Python โ zero dependencies.
๐ Overview
byteforge-figlet is a Python implementation of the FIGLet rendering engine used across the ByteForge FIGLet Suite.
It provides a robust and efficient implementation of the FIGLet specification, allowing you to create ASCII art from text using FIGLet fonts. It supports all standard FIGLet features including various smushing rules, layout modes, ANSI color preservation, and Unicode.
The library ships with the built-in small font so it works out of the box with no additional downloads.
โจ Features
- ๐ค Render FIGLet text using any
.flffont - ๐ Full FIGLet font (
.flf) file parsing and loading - ๐๏ธ Automatic handling of compressed/zipped font files
- ๐จ ANSI color support for terminal output
- ๐ Unicode support
- ๐ Paragraph formatting support
- โ๏ธ Supports Full Size, Kerning, and Smushing layout modes
- ๐ง Implements all official smushing rules
- ๐ฆ Default embedded font included โ works out of the box
- ๐ Zero dependencies โ stdlib only
- ๐ Python 3.9+
- ๐ป Includes a
figprintCLI command
Sample Output
_ _ _ _ _ _ _ _ _
| || |___| | |___ \ \ / /__ _ _| |__| | |
| __ / -_) | / _ \_ \ \/\/ / _ \ '_| / _` |_|
|_||_\___|_|_\___( ) \_/\_/\___/_| |_\__,_(_)
|/
๐ Installation
Install via pip:
pip install byteforge-figlet
๐ Quick Start
Basic Usage
from byteforge_figlet import FIGLetRenderer
print(FIGLetRenderer.render("Hello World!"))
Using a Custom Font
from byteforge_figlet import FIGFont, FIGLetRenderer
font = FIGFont.from_file("/path/to/myfont.flf")
print(FIGLetRenderer.render("Hello!", font=font))
Choosing a Layout Mode
from byteforge_figlet import FIGLetRenderer, LayoutMode
# Full Size โ no character overlap
print(FIGLetRenderer.render("Hi", mode=LayoutMode.FullSize))
# Kerning โ characters touch but don't overlap
print(FIGLetRenderer.render("Hi", mode=LayoutMode.Kerning))
# Smushing โ characters may merge (default)
print(FIGLetRenderer.render("Hi", mode=LayoutMode.Smushing))
Renderer Instance
from byteforge_figlet import FIGLetRenderer, LayoutMode
renderer = FIGLetRenderer(mode=LayoutMode.Kerning, line_separator="\n")
print(renderer.render_text("Hello\nWorld"))
๐ป CLI Usage
The figprint command is installed automatically with the package:
figprint "Hello World"
figprint "Hello World" --font /path/to/font.flf
figprint "Hello World" --mode kerning
figprint "Hello World" --mode full
figprint --help
Or run as a module:
python -m byteforge_figlet "Hello World"
๐ API Reference
FIGFont
| Method / Property | Description |
|---|---|
FIGFont.default |
The built-in small font (class property, cached) |
FIGFont.from_file(path) |
Load a font from a .flf file path |
FIGFont.from_stream(stream) |
Load a font from a binary stream |
FIGFont.from_text(text) |
Load a font from a string |
FIGFont.from_lines(lines) |
Load a font from a list of strings |
.height |
Character height in rows |
.hard_blank |
Hard blank character |
.characters |
dict mapping character code point โ glyph rows |
.smushing_rules |
SmushingRules flags for this font |
.print_direction |
0 = left-to-right, 1 = right-to-left |
.has_smushing_rule(rule) |
Check if a specific rule is set |
FIGLetRenderer
| Member | Description |
|---|---|
FIGLetRenderer.render(text, ...) |
Static method โ render and return ASCII art string |
renderer.render_text(text) |
Instance method โ render using configured settings |
.layout_mode |
Active LayoutMode |
.line_separator |
Line separator string (default os.linesep) |
.use_ansi_colors |
Whether to preserve ANSI color codes through rendering |
.paragraph_mode |
Whether blank lines produce separate FIGLet renders |
Constructor parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
font |
FIGFont | None |
built-in small |
Font to use |
mode |
LayoutMode |
Smushing |
Layout mode |
line_separator |
str | None |
os.linesep |
Line separator |
use_ansi_colors |
bool |
False |
Preserve ANSI color codes |
paragraph_mode |
bool |
True |
Treat \n as paragraph breaks |
LayoutMode
| Value | Description |
|---|---|
LayoutMode.FullSize (-1) |
No character overlap |
LayoutMode.Kerning (0) |
Minimal spacing, no merge |
LayoutMode.Smushing (1) |
Characters may merge (default) |
SmushingRules
| Flag | Value | Description |
|---|---|---|
SmushingRules.None |
0 | No smushing rules active |
SmushingRules.EqualCharacter |
1 | Two identical characters โ one |
SmushingRules.Underscore |
2 | Underscore replaced by hierarchy char |
SmushingRules.Hierarchy |
4 | Higher-ranked char wins |
SmushingRules.OppositePair |
8 | Opposing brackets โ | |
SmushingRules.BigX |
16 | /+\ โ |, \+/ โ Y, >+< โ X |
SmushingRules.HardBlank |
32 | Two hardblanks โ one hardblank |
๐ Font Support
- Standard
.flffont files - Compressed
.flffiles inside.ziparchives (auto-detected by PK magic bytes)
๐จ ANSI Color Support
The library preserves ANSI color codes through the rendering process, allowing you to create colorful FIGLet text in terminals:
from byteforge_figlet import FIGLetRenderer
renderer = FIGLetRenderer(use_ansi_colors=True)
colorful_text = '\x1b[31mRed\x1b[0m \x1b[32mGreen\x1b[0m \x1b[34mBlue\x1b[0m'
print(renderer.render_text(colorful_text))
๐ Paragraph Mode
When enabled (the default), blank lines in the input produce separate FIGLet renderings spaced by the font's character height:
from byteforge_figlet import FIGLetRenderer
renderer = FIGLetRenderer()
paragraphs = 'Paragraph 1\n\nParagraph 2'
print(renderer.render_text(paragraphs))
Output:
___ _ _
| _ \__ _ _ _ __ _ __ _ _ _ __ _ _ __| |_ / |
| _/ _` | '_/ _` / _` | '_/ _` | '_ \ ' \ | |
|_| \__,_|_| \__,_\__, |_| \__,_| .__/_||_| |_|
|___/ |_|
___ _ ___
| _ \__ _ _ _ __ _ __ _ _ _ __ _ _ __| |_ |_ )
| _/ _` | '_/ _` / _` | '_/ _` | '_ \ ' \ / /
|_| \__,_|_| \__,_\__, |_| \__,_| .__/_||_| /___|
|___/ |_|
๐ Unicode Support
The library fully supports Unicode characters. Characters not present in the font are skipped gracefully:
from byteforge_figlet import FIGLetRenderer
renderer = FIGLetRenderer()
print(renderer.render_text('Hello ๐ World!'))
Output:
_ _ _ _ __ __ _ _ _
| || |___| | |___ \ \ / /__ _ _| |__| | |
| __ / -_) | / _ \ \ \/\/ / _ \ '_| / _` |_|
|_||_\___|_|_\___/ \_/\_/\___/_| |_\__,_(_)
๐ Implementation Details
-
FIGFont โ Parses
.flffont files; supports loading from files, streams, strings, or line lists; handles ZIP-compressed font files; manages smushing rule configuration. -
FIGLetRenderer โ Converts input text to FIGLet output; implements character smushing logic; handles different layout modes; processes ANSI color codes in a single pre-pass; supports paragraph formatting.
-
LayoutMode โ Enumeration controlling how characters are combined during rendering.
-
SmushingRules โ Flags enumeration defining which character-combining rules are active.
โก Performance Considerations
- Default font is cached after the first load and reused across all calls
- ANSI color codes are handled in a single pre-pass, not during rendering
- Efficient string building throughout the rendering pipeline
๐ค Contributing
Contributions are welcome! To contribute:
- Fork the repository
- Create a feature branch
- Commit your changes
- Open a Pull Request
๐ ByteForge FIGLet Suite
| Component | Description |
|---|---|
| FIGLet (.NET) | Core C# library on NuGet |
| @byte-forge/figlet (TypeScript) | TypeScript library on npm |
| byteforge-figlet (Python) | Python library on PyPI |
| FIGPrint | .NET CLI tool |
| VS Extension | Visual Studio 2022+ extension |
| VS Code Extension | VS Code extension |
๐ License
This library is licensed under the MIT License โ see the LICENSE file for details.
๐ก Credits
- Original FIGLet concept by Frank, Ian & Glenn
- Implementations by Paulo Santos (ByteForge)
- FIGLet specification: figlet.org
Support
If you encounter any issues or have feature requests, please:
- Search existing issues
- Create a new issue if needed
Made with โค๏ธ by Paulo Santos
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file byteforge_figlet-2.0.9.tar.gz.
File metadata
- Download URL: byteforge_figlet-2.0.9.tar.gz
- Upload date:
- Size: 29.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd25e8c45bd0f48d6460e75427cc5169a765ba9476ffd845c0e7ca6a3b62a037
|
|
| MD5 |
984896c19d299da873d89761bd2f4939
|
|
| BLAKE2b-256 |
8084b6a7e377beb6b7a7d5e1a1a7b2295c2edd6ea200f19a2d5e1de3a36fa6e3
|
File details
Details for the file byteforge_figlet-2.0.9-py3-none-any.whl.
File metadata
- Download URL: byteforge_figlet-2.0.9-py3-none-any.whl
- Upload date:
- Size: 18.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c5733f5492852f556da878a4b92b6fe2d1ec41e98b97ad672949e068765c8a9
|
|
| MD5 |
9e33e2debf34f2799113eef9c6a934a7
|
|
| BLAKE2b-256 |
fd981dae33bd54d915cbc885574157544384402a66d4764ecf56a986fc39a3ac
|