CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-clint

Python Command Line Interface Tools for colored output, progress bars, text formatting, and argument handling

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

text-output.mddocs/

Text Output and Formatting

Core text output functions with indentation context management, column formatting, and cross-platform terminal compatibility. Provides puts/puts_err functions for consistent output and indent context managers for nested text formatting with automatic newline handling.

Capabilities

Basic Output Functions

Core functions for printing text to stdout and stderr with consistent formatting and newline handling.

def puts(s='', newline=True, stream=STDOUT):
    """
    Prints given string to stdout with proper indentation.
    
    Parameters:
    - s: str, string to print (default: '')
    - newline: bool, whether to add newline (default: True)
    - stream: function, output stream function (default: STDOUT)
    """

def puts_err(s='', newline=True, stream=STDERR):
    """
    Prints given string to stderr with proper indentation.
    
    Parameters:
    - s: str, string to print (default: '')
    - newline: bool, whether to add newline (default: True)  
    - stream: function, output stream function (default: STDERR)
    """

Indentation Management

Context manager for nested text indentation with support for custom quotes and automatic indentation tracking.

def indent(indent=4, quote=''):
    """
    Indentation manager that returns an indentation context manager.
    
    Parameters:
    - indent: int, number of spaces to indent (default: 4)
    - quote: str, quote string to prepend (default: '')
    
    Returns:
    context manager for use with 'with' statement
    """

def dedent():
    """
    Dedent next strings, use only if you use indent otherwise than as a context.
    Removes the last indentation level from the global indent stack.
    """

Column Formatting

Advanced column formatting with automatic terminal width detection and text wrapping.

def columns(*cols, **kwargs):
    """
    Format text in columns with automatic width adjustment.
    
    Parameters:
    - cols: tuple of (string, width) pairs where width can be None for auto-expand
    - kwargs: dict, optional parameters including 'width' for manual console width
    
    Returns:
    str: formatted columnar text
    """

Text Formatters

Text width management functions for consistent formatting and alignment.

def max_width(string, cols, separator='\n'):
    """
    Returns text formatted to maximum width with word wrapping.
    
    Parameters:
    - string: str or ColoredString, text to format
    - cols: int, maximum width in characters
    - separator: str, line separator (default: '\n')
    
    Returns:
    str or ColoredString: formatted text with proper wrapping
    """

def min_width(string, cols, padding=' '):
    """
    Returns given string with right padding to minimum width.
    
    Parameters:
    - string: str or ColoredString, text to pad
    - cols: int, minimum width in characters
    - padding: str, padding character (default: ' ')
    
    Returns:
    str: padded text
    """

Stream Constants

Predefined stream functions for consistent output handling.

STDOUT = sys.stdout.write  # Standard output stream function
STDERR = sys.stderr.write  # Standard error stream function

Usage Examples

from clint.textui import puts, indent, columns

# Basic output
puts("Hello, world!")
puts_err("Error occurred")

# Nested indentation
puts("Root level")
with indent(4):
    puts("Level 1 indented")
    with indent(4):
        puts("Level 2 indented")
    puts("Back to level 1")
puts("Back to root")

# Email-style quoting
puts("Original message:")
with indent(4, quote='> '):
    puts("This is quoted text")
    puts("Multiple lines work too")

# Column formatting
text1 = "This is some long text that will be wrapped"
text2 = "This is other text that goes in the second column"
text3 = "Third column text here"

formatted = columns(
    (text1, 20),      # Fixed width of 20
    (text2, 25),      # Fixed width of 25  
    (text3, None)     # Auto-expand to fill remaining space
)
puts(formatted)

# Manual column width control
formatted_custom = columns(
    (text1, 30),
    (text2, None),
    width=100  # Force console width to 100
)
puts(formatted_custom)

Advanced Usage

from clint.textui.formatters import max_width, min_width
from clint.textui.colored import red

# Text wrapping with colored text
long_text = red("This is a very long red text that needs to be wrapped")
wrapped = max_width(long_text, 40)
puts(wrapped)

# Padding with minimum width
short_text = "Short"
padded = min_width(short_text, 20, padding='.')
puts(padded)  # Output: "Short..............."

# Complex indentation patterns
puts("Multi-level indentation example:")
with indent(2):
    puts("Level 1")
    with indent(3, quote='* '):
        puts("Bullet point 1")
        puts("Bullet point 2")
    with indent(3, quote='- '):
        puts("Different bullet style")
        puts("Another item")

Install with Tessl CLI

npx tessl i tessl/pypi-clint

docs

arguments.md

colored-text.md

english.md

index.md

progress.md

prompts.md

resources.md

text-output.md

utilities.md

validation.md

tile.json