Skip to main content

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 .flf font
  • ๐Ÿ“„ 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 figprint CLI 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
.smushing_rules SmushingRules flags for this font
.has_smushing_rule(rule) Check if a specific rule is set

FIGLetRenderer

Method Description
FIGLetRenderer.render(text, ...) Static method โ€” render and return ASCII art string
renderer.render_text(text) Instance method โ€” render using configured settings

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 ending
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.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

๐Ÿ”— 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:

  1. Search existing issues
  2. 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

byteforge_figlet-2.0.7.tar.gz (27.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

byteforge_figlet-2.0.7-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file byteforge_figlet-2.0.7.tar.gz.

File metadata

  • Download URL: byteforge_figlet-2.0.7.tar.gz
  • Upload date:
  • Size: 27.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for byteforge_figlet-2.0.7.tar.gz
Algorithm Hash digest
SHA256 0f883b839dbe2740f5b1b61a81cff62e3e6c5500d6ba0a531e9d12c2ddeb3329
MD5 9f15bf0a2e2e3baa80255714158ad780
BLAKE2b-256 84469a8509a6039aedb2b474aec6922d90b89f2ff6e0ac20e53954224b231a9c

See more details on using hashes here.

File details

Details for the file byteforge_figlet-2.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for byteforge_figlet-2.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 410b12c69df44fe5af569ced6bc9ffd7b078203059deec2eb12ee140561c96e2
MD5 20c6ca46ddd015b45259f19023d6476c
BLAKE2b-256 b7f32445710a6b66609afe9748ec2dab134018bde146855929bf58e81843342c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page