Lumesh fmt Module

wiki libs

Lumesh Text Formatting Module Documentation

Module Path: text
Function Description: Provides text style control, ANSI escape sequence handling, string formatting, and other functionalities. Supports chaining calls:

fmt.bold(fmt.red "Error")  # Red bold text

Function Categories and Detailed Descriptions

1. ANSI Escape Sequence Handling
  1. fmt.strip
    Function: Remove all ANSI escape sequences from a string
    Parameters: input: string
    Return Value: Clean text content
    Example:

    fmt.strip "\x1b[31mHello\x1b[0m"  # => "Hello"

2. Text Style Control
  1. Basic Styles

    Function Effect ANSI Sequence
    fmt.bold Bold \x1b[1m
    fmt.faint Faint \x1b[2m
    fmt.italics Italics \x1b[3m
    fmt.underline Underline \x1b[4m
    fmt.blink Blink \x1b[5m
    fmt.invert Invert \x1b[7m
    fmt.strike Strikethrough \x1b[9m

    Common Parameter: input: string
    Example:

    fmt.underline "Important"  # Underlined text
  2. Standard Colors

    Function Color ANSI Sequence
    fmt.black Black \x1b[90m
    fmt.red Red \x1b[91m
    fmt.green Green \x1b[92m
    fmt.yellow Yellow \x1b[93m
    fmt.blue Blue \x1b[94m
    fmt.magenta Magenta \x1b[95m
    fmt.cyan Cyan \x1b[96m
    fmt.white White \x1b[97m
  3. Dark Mode

    Example:

    fmt.dark_red "Warning"  # Dark red text
    Function Color ANSI Sequence
    fmt.dark_black Dark Black \x1b[30m
    fmt.dark_red Dark Red \x1b[31m

3. String Formatting
  1. fmt.wrap
    Function: Automatically wrap text at specified column width
    Parameters:

    • columns: integer (maximum characters per line)
    • input: string
      Return Value: Wrapped text
      Example:
    fmt.wrap 20 "Long text that needs wrapping"
  2. fmt.href
    Function: Create a clickable hyperlink
    Parameters:

    • url: string
    • text: string
      Return Value: Hyperlink with ANSI sequences
      Example:
    fmt.href "https://example.com" "Click Here"
  3. Text Alignment

    Function Parameters Functionality
    fmt.pad_start length, [pad_char], input Left padding
    fmt.pad_end length, [pad_char], input Right padding
    fmt.center length, [pad_char], input Center padding

    Example:

    fmt.pad_start 10 "0" "123"   # => "0000000123"
    fmt.center 10 "Title" # => " Title "
  4. fmt.format
    Function: Template string formatting (similar to printf)
    Parameters:

    • template: string (contains {} placeholders)
    • arg1, arg2, ... (replacement parameters)
      Return Value: Formatted string
      Rules:
    • Replace {} placeholders in order
    • The number of parameters must match the number of placeholders
      Example:
    fmt.format "{} + {} = {}" 2 3 5  # => "2 + 3 = 5"

Combined Usage Example

fmt.format "{}: {}" \
fmt.bold(fmt.red "ALERT") \
(fmt.wrap 50 "Critical system failure detected. Immediate action required.")