CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pyfiglet

Pure Python implementation of FIGlet for creating ASCII art text from regular text using various fonts

Pending
Overview
Eval results
Files

text-rendering.mddocs/

Text Rendering

Core functionality for converting plain text into ASCII art using FIGlet fonts. This module provides both simple utility functions and programmatic access to text rendering capabilities.

Capabilities

Basic Text Conversion

Converts text to ASCII art using the specified font and options. This is the most commonly used function for simple text-to-ASCII art conversion.

def figlet_format(text: str, font: str = "standard", **kwargs) -> FigletString:
    """
    Convert text to ASCII art using specified font.
    
    Parameters:
    - text (str): Text to convert to ASCII art
    - font (str): Font name to use (default: "standard")
    - direction (str): Text direction ("auto", "left-to-right", "right-to-left") 
    - justify (str): Text justification ("auto", "left", "center", "right")
    - width (int): Output width in characters (default: 80)
    
    Returns:
    FigletString: ASCII art representation of the text
    
    Raises:
    FontNotFound: If the specified font cannot be located
    FontError: If there is a problem parsing the font file
    CharNotPrinted: If width is insufficient to print a character
    """

Usage Example

import pyfiglet

# Basic usage with default font
result = pyfiglet.figlet_format("Hello")
print(result)

# Using a different font
result = pyfiglet.figlet_format("Hello", font="big")
print(result)

# With additional formatting options
result = pyfiglet.figlet_format(
    "Centered Text", 
    font="slant", 
    justify="center",
    width=60
)
print(result)

Direct Console Output

Prints ASCII art text directly to stdout with optional color support. Useful for terminal applications that need immediate colored output.

def print_figlet(text: str, font: str = "standard", colors: str = ":", **kwargs) -> None:
    """
    Print ASCII art text directly to stdout with color support.
    
    Parameters:
    - text (str): Text to convert and print
    - font (str): Font name to use (default: "standard")  
    - colors (str): Color specification in "foreground:background" format
    - direction (str): Text direction ("auto", "left-to-right", "right-to-left")
    - justify (str): Text justification ("auto", "left", "center", "right") 
    - width (int): Output width in characters (default: 80)
    
    Returns:
    None: Prints to stdout
    
    Raises:
    FontNotFound: If the specified font cannot be located
    FontError: If there is a problem parsing the font file
    InvalidColor: If color specification is invalid
    """

Usage Example

import pyfiglet

# Basic printing
pyfiglet.print_figlet("Hello World")

# With colors (red text on blue background)
pyfiglet.print_figlet("Colored Text", colors="red:blue")

# Only foreground color
pyfiglet.print_figlet("Red Text", colors="red:")

# Only background color  
pyfiglet.print_figlet("Blue Background", colors=":blue")

# RGB colors
pyfiglet.print_figlet("RGB Text", colors="255;100;50:0;0;255")

Color Specifications

The colors parameter accepts several formats:

  • Named colors: Use COLOR_CODES keys (RED, GREEN, BLUE, YELLOW, etc.)
  • RGB format: "R;G;B" values from 0-255
  • Foreground only: "color:" (trailing colon)
  • Background only: ":color" (leading colon)
  • Both: "foreground:background"

Available named colors: BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, LIGHT_GRAY, DEFAULT, DARK_GRAY, LIGHT_RED, LIGHT_GREEN, LIGHT_YELLOW, LIGHT_BLUE, LIGHT_MAGENTA, LIGHT_CYAN, WHITE, RESET

Text Direction and Justification

  • Direction: Controls text flow direction, typically determined by font properties when set to "auto"
  • Justification: Controls text alignment within the specified width
  • Width: Sets maximum output width for line breaking and justification

Return Type

Both functions work with FigletString, an enhanced string type that supports ASCII art manipulation methods like reverse(), flip(), and whitespace normalization.

Install with Tessl CLI

npx tessl i tessl/pypi-pyfiglet

docs

advanced-rendering.md

cli.md

color-support.md

font-management.md

index.md

string-manipulation.md

text-rendering.md

tile.json