API Reference

Core Classes and Functions

ASCIIColors

The main class for colored output and logging. Inherits all ANSI color constants.

class ascii_colors.ASCIIColors[source]

Bases: ANSI

Direct printing and logging state manager.

static print(text, color='\x1b[37m', style='', background='', end='\n', flush=False, file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, emit=True, markup=True)[source]

Print text with optional rich markup support.

Parameters:
  • text (str) – The text to print

  • color (str) – Foreground color ANSI code

  • style (str) – Style ANSI code (bold, italic, etc.)

  • background (str) – Background color ANSI code

  • end (str) – String to append at the end

  • flush (bool) – Whether to flush the output

  • file (Any) – Output stream

  • emit (bool) – Whether to actually print (False returns string only)

  • markup (bool) – Whether to parse rich markup tags like [red], [bold], etc.

Return type:

str

static multicolor(texts, colors, end='\n', flush=False, file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, emit=True, markup=True)[source]

Print multiple colored text segments with rich markup support.

Parameters:
  • texts (List[str]) – List of text segments

  • colors (List[str]) – List of colors (one per text segment)

  • end (str) – String to append at the end

  • flush (bool) – Whether to flush the output

  • file (Any) – Output stream

  • emit (bool) – Whether to actually print

  • markup (bool) – Whether to parse rich markup tags in each segment

Return type:

None

static highlight(text, subtext, color='\x1b[37m', highlight_color='\x1b[33m', whole_line=False, end='\n', flush=False, file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, markup=False)[source]

Highlight substrings in text with optional rich markup support.

Parameters:
  • text (str) – The text to process

  • subtext (str | List[str]) – String or list of strings to highlight

  • color (str) – Default text color

  • highlight_color (str) – Color for highlighted portions

  • whole_line (bool) – Whether to highlight entire lines containing subtext

  • end (str) – String to append at the end

  • flush (bool) – Whether to flush the output

  • file (Any) – Output stream

  • markup (bool) – Whether to parse rich markup tags in the text first

Return type:

None

static execute_with_animation(pending_text, func, *args, color=None, **kwargs)[source]
Parameters:
Return type:

_T

static confirm(question, default_yes=None, prompt_color='\x1b[33m', file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, markup=True)[source]

Ask a yes/no confirmation question with optional rich markup support.

Parameters:
  • question (str) – The question text

  • default_yes (bool | None) – Default answer if user just presses Enter

  • prompt_color (str) – Color for the prompt

  • file (Any) – Output stream

  • markup (bool) – Whether to parse rich markup tags in the question

Return type:

bool

static prompt(text, color='\x1b[32m', style='', hide_input=False, file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, markup=True)[source]

Prompt for user input with optional rich markup support.

Parameters:
  • text (str) – The prompt text

  • color (str) – Color for the prompt

  • style (str) – Style for the prompt

  • hide_input (bool) – Whether to hide the input (for passwords)

  • file (Any) – Output stream

  • markup (bool) – Whether to parse rich markup tags in the prompt text

Return type:

str

Direct color methods:

static red(t, **k)[source]
Parameters:

t (str)

static green(t, **k)[source]
Parameters:

t (str)

static yellow(t, **k)[source]
Parameters:

t (str)

static blue(t, **k)[source]
Parameters:

t (str)

static magenta(t, **k)[source]
Parameters:

t (str)

static cyan(t, **k)[source]
Parameters:

t (str)

static white(t, **k)[source]
Parameters:

t (str)

static orange(t, **k)[source]
Parameters:

t (str)

static bold(t, **k)[source]
Parameters:

t (str)

static italic(t, **k)[source]
Parameters:

t (str)

Logging methods:

classmethod debug(m, *a, **k)[source]
Parameters:

m (str)

classmethod info(m, *a, **k)[source]
Parameters:

m (str)

classmethod warning(m, *a, **k)[source]
Parameters:

m (str)

classmethod error(m, *a, **k)[source]
Parameters:

m (str)

classmethod critical(m, *a, **k)[source]
Parameters:

m (str)

Configuration methods:

classmethod set_log_level(level)[source]
Parameters:

level (LogLevel | int)

Return type:

None

classmethod add_handler(handler)[source]
Parameters:

handler (Handler)

Return type:

None

classmethod remove_handler(handler)[source]
Parameters:

handler (Handler)

Return type:

None

classmethod clear_handlers()[source]
Return type:

None

classmethod set_context(**kwargs)[source]
Parameters:

kwargs (Any)

Return type:

None

classmethod clear_context(*args)[source]
Parameters:

args (str)

Return type:

None

classmethod context(**kwargs)[source]
Parameters:

kwargs (Any)

Return type:

ContextManager[None]

classmethod get_thread_context()[source]
Return type:

Dict[str, Any]

classmethod set_log_level(level)[source]
Parameters:

level (LogLevel | int)

Return type:

None

classmethod add_handler(handler)[source]
Parameters:

handler (Handler)

Return type:

None

classmethod remove_handler(handler)[source]
Parameters:

handler (Handler)

Return type:

None

classmethod clear_handlers()[source]
Return type:

None

classmethod set_context(**kwargs)[source]
Parameters:

kwargs (Any)

Return type:

None

classmethod clear_context(*args)[source]
Parameters:

args (str)

Return type:

None

classmethod context(**kwargs)[source]
Parameters:

kwargs (Any)

Return type:

ContextManager[None]

classmethod get_thread_context()[source]
Return type:

Dict[str, Any]

classmethod debug(m, *a, **k)[source]
Parameters:

m (str)

classmethod info(m, *a, **k)[source]
Parameters:

m (str)

classmethod warning(m, *a, **k)[source]
Parameters:

m (str)

classmethod error(m, *a, **k)[source]
Parameters:

m (str)

classmethod critical(m, *a, **k)[source]
Parameters:

m (str)

static print(text, color='\x1b[37m', style='', background='', end='\n', flush=False, file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, emit=True, markup=True)[source]

Print text with optional rich markup support.

Parameters:
  • text (str) – The text to print

  • color (str) – Foreground color ANSI code

  • style (str) – Style ANSI code (bold, italic, etc.)

  • background (str) – Background color ANSI code

  • end (str) – String to append at the end

  • flush (bool) – Whether to flush the output

  • file (Any) – Output stream

  • emit (bool) – Whether to actually print (False returns string only)

  • markup (bool) – Whether to parse rich markup tags like [red], [bold], etc.

Return type:

str

static success(t, **k)[source]
Parameters:

t (str)

static fail(t, **k)[source]
Parameters:

t (str)

static red(t, **k)[source]
Parameters:

t (str)

static green(t, **k)[source]
Parameters:

t (str)

static yellow(t, **k)[source]
Parameters:

t (str)

static blue(t, **k)[source]
Parameters:

t (str)

static magenta(t, **k)[source]
Parameters:

t (str)

static cyan(t, **k)[source]
Parameters:

t (str)

static white(t, **k)[source]
Parameters:

t (str)

static orange(t, **k)[source]
Parameters:

t (str)

static bold(t, **k)[source]
Parameters:

t (str)

static italic(t, **k)[source]
Parameters:

t (str)

static multicolor(texts, colors, end='\n', flush=False, file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, emit=True, markup=True)[source]

Print multiple colored text segments with rich markup support.

Parameters:
  • texts (List[str]) – List of text segments

  • colors (List[str]) – List of colors (one per text segment)

  • end (str) – String to append at the end

  • flush (bool) – Whether to flush the output

  • file (Any) – Output stream

  • emit (bool) – Whether to actually print

  • markup (bool) – Whether to parse rich markup tags in each segment

Return type:

None

static highlight(text, subtext, color='\x1b[37m', highlight_color='\x1b[33m', whole_line=False, end='\n', flush=False, file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, markup=False)[source]

Highlight substrings in text with optional rich markup support.

Parameters:
  • text (str) – The text to process

  • subtext (str | List[str]) – String or list of strings to highlight

  • color (str) – Default text color

  • highlight_color (str) – Color for highlighted portions

  • whole_line (bool) – Whether to highlight entire lines containing subtext

  • end (str) – String to append at the end

  • flush (bool) – Whether to flush the output

  • file (Any) – Output stream

  • markup (bool) – Whether to parse rich markup tags in the text first

Return type:

None

static execute_with_animation(pending_text, func, *args, color=None, **kwargs)[source]
Parameters:
Return type:

_T

static confirm(question, default_yes=None, prompt_color='\x1b[33m', file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, markup=True)[source]

Ask a yes/no confirmation question with optional rich markup support.

Parameters:
  • question (str) – The question text

  • default_yes (bool | None) – Default answer if user just presses Enter

  • prompt_color (str) – Color for the prompt

  • file (Any) – Output stream

  • markup (bool) – Whether to parse rich markup tags in the question

Return type:

bool

static prompt(text, color='\x1b[32m', style='', hide_input=False, file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, markup=True)[source]

Prompt for user input with optional rich markup support.

Parameters:
  • text (str) – The prompt text

  • color (str) – Color for the prompt

  • style (str) – Style for the prompt

  • hide_input (bool) – Whether to hide the input (for passwords)

  • file (Any) – Output stream

  • markup (bool) – Whether to parse rich markup tags in the prompt text

Return type:

str

static rich_print(text, **kwargs)[source]

Print text with rich markup support.

Supports tags like [magenta], [bold], [success], [error], etc.

Examples

ASCIIColors.rich_print(“[magenta]Hello[/magenta] [bold]World[/bold]”) ASCIIColors.rich_print(“[success]Operation completed successfully[/success]”) ASCIIColors.rich_print(“[error]An error occurred[/error]”) ASCIIColors.rich_print(“[warning]Warning: deprecated feature[/warning]”) ASCIIColors.rich_print(“[info]Note: processing started[/info]”)

Parameters:
Return type:

None

static panel(content, title=None, border_style='', box='square', padding=(0, 1), width=None, color='', background='')[source]

Create a bordered panel around content. Returns string for printing.

New rich-style convenience method.

Parameters:
Return type:

str

static table(*headers, rows=None, title=None, box='square', show_lines=False, header_style='bold')[source]

Create a formatted table. Returns string for printing.

New rich-style convenience method.

Parameters:
Return type:

str

static tree(label, style='', guide_style='dim')[source]

Create a tree structure for display.

New rich-style convenience method. Returns a Tree object that can have children added.

Parameters:
Return type:

Tree

static syntax(code, language='python', line_numbers=False, theme=None)[source]

Syntax highlight code. Returns string for printing.

New rich-style convenience method.

Parameters:
Return type:

str

static markdown(markup)[source]

Render markdown to terminal. Returns string for printing.

New rich-style convenience method.

Parameters:

markup (str)

Return type:

str

static columns(*items, equal=False, width=None)[source]

Arrange items in columns. Returns string for printing.

New rich-style convenience method.

Parameters:
Return type:

str

static rule(title='', characters='─', style='', align='center')[source]

Print a horizontal rule with optional title.

New rich-style convenience method.

Parameters:
Return type:

None

static status(message, spinner='dots', spinner_style='green')[source]

Show a spinner status indicator.

New rich-style convenience method. Use as context manager.

Example

with ASCIIColors.status(“Processing…”):

do_work()

Parameters:
  • message (str)

  • spinner (str)

  • spinner_style (str)

Return type:

Status

static live(renderable, refresh_per_second=4)[source]

Create a live updating display.

New rich-style convenience method. Use as context manager.

Example

with ASCIIColors.live(some_renderable) as live:
while updating:

live.update(new_renderable)

Parameters:
  • renderable (Any)

  • refresh_per_second (float)

Return type:

Live

Constants

class ascii_colors.LogLevel(value)[source]

Bases: IntEnum

Enumeration defining standard logging levels.

DEBUG = 10
INFO = 20
WARNING = 30
ERROR = 40
CRITICAL = 50
CRITICAL = 50
ERROR = 40
WARNING = 30
INFO = 20
DEBUG = 10
NOTSET = 0

Level Constants

ascii_colors.DEBUG = 10
ascii_colors.INFO = 20
ascii_colors.WARNING = 30
ascii_colors.ERROR = 40
ascii_colors.CRITICAL = 50
ascii_colors.NOTSET = 0

ANSI Color Constants

All available as class attributes on ASCIIColors:

Styles:
  • style_bold, style_dim, style_italic, style_underline

  • style_blink, style_reverse, style_hidden, style_strikethrough

Colors:
  • color_black, color_red, color_green, color_yellow

  • color_blue, color_magenta, color_cyan, color_white, color_orange

  • Bright variants: color_bright_*

  • Background colors: color_bg_* and color_bg_bright_*

Reset:
  • color_reset

Logging Components

Formatters

class ascii_colors.Formatter(fmt=None, datefmt=None, style='%', include_source=False, **kwargs)[source]

Bases: object

Base class for formatting log records into textual representations.

Parameters:
  • fmt (str | None)

  • datefmt (str | None)

  • style (str)

  • include_source (bool)

  • kwargs (Any)

__init__(fmt=None, datefmt=None, style='%', include_source=False, **kwargs)[source]
Parameters:
  • fmt (str | None)

  • datefmt (str | None)

  • style (str)

  • include_source (bool)

  • kwargs (Any)

format(level, message, timestamp, exc_info, logger_name='root', **kwargs)[source]
Parameters:
Return type:

str

format_exception(exc_info)[source]
Parameters:

exc_info (Tuple)

Return type:

str

format(level, message, timestamp, exc_info, logger_name='root', **kwargs)[source]
Parameters:
Return type:

str

format_exception(exc_info)[source]
Parameters:

exc_info (Tuple)

Return type:

str

class ascii_colors.JSONFormatter(fmt=None, datefmt=None, style='%', json_ensure_ascii=False, json_indent=None, json_separators=None, json_sort_keys=False, include_fields=None, include_source=False, **kwargs)[source]

Bases: Formatter

Formats log records into JSON strings.

Parameters:
  • fmt (Dict[str, str] | None)

  • datefmt (str | None)

  • style (str)

  • json_ensure_ascii (bool)

  • json_indent (int | None)

  • json_separators (Tuple | None)

  • json_sort_keys (bool)

  • include_fields (List[str] | None)

  • include_source (bool)

  • kwargs (Any)

__init__(fmt=None, datefmt=None, style='%', json_ensure_ascii=False, json_indent=None, json_separators=None, json_sort_keys=False, include_fields=None, include_source=False, **kwargs)[source]
Parameters:
  • fmt (Dict[str, str] | None)

  • datefmt (str | None)

  • style (str)

  • json_ensure_ascii (bool)

  • json_indent (int | None)

  • json_separators (Tuple | None)

  • json_sort_keys (bool)

  • include_fields (List[str] | None)

  • include_source (bool)

  • kwargs (Any)

format(level, message, timestamp, exc_info, logger_name='root', **kwargs)[source]
Parameters:
Return type:

str

format(level, message, timestamp, exc_info, logger_name='root', **kwargs)[source]
Parameters:
Return type:

str

Handlers

class ascii_colors.Handler(level=10, formatter=None)[source]

Bases: ABC

Abstract base class for all log handlers.

Parameters:
setLevel(level)[source]
Parameters:

level (LogLevel | int)

Return type:

None

getLevel()[source]
Return type:

int

setFormatter(formatter)[source]
Parameters:

formatter (Formatter)

Return type:

None

handle(level, message, timestamp, exc_info, logger_name='root', **kwargs)[source]
Parameters:
Return type:

None

abstractmethod emit(level, formatted_message)[source]
Parameters:
Return type:

None

close()[source]
Return type:

None

handle_error(message)[source]
Parameters:

message (str)

class ascii_colors.ConsoleHandler(level=10, formatter=None, stream=None)[source]

Bases: Handler

Handles logging records by writing them to a stream (typically console).

Parameters:
emit(level, formatted_message)[source]
Parameters:
Return type:

None

close()[source]
Return type:

None

ascii_colors.StreamHandler

alias of ConsoleHandler

class ascii_colors.FileHandler(filename, mode='a', encoding='utf-8', delay=False, level=10, formatter=None)[source]

Bases: Handler

Handles logging records by writing them to a file.

Parameters:
emit(level, formatted_message)[source]
Parameters:
Return type:

None

close()[source]
Return type:

None

flush()[source]
Return type:

None

class ascii_colors.RotatingFileHandler(filename, mode='a', maxBytes=0, backupCount=0, encoding='utf-8', delay=False, level=10, formatter=None)[source]

Bases: FileHandler

Handles logging to a file, rotating it when it reaches a certain size.

Parameters:
emit(level, formatted_message)[source]
Parameters:
Return type:

None

do_rollover()[source]
Return type:

None

class ascii_colors.handlers[source]

Bases: object

class RotatingFileHandler(filename, mode='a', maxBytes=0, backupCount=0, encoding='utf-8', delay=False, level=10, formatter=None)

Bases: FileHandler

Handles logging to a file, rotating it when it reaches a certain size.

Parameters:
do_rollover()
Return type:

None

emit(level, formatted_message)
Parameters:
Return type:

None

class FileHandler(filename, mode='a', encoding='utf-8', delay=False, level=10, formatter=None)

Bases: Handler

Handles logging records by writing them to a file.

Parameters:
close()
Return type:

None

emit(level, formatted_message)
Parameters:
Return type:

None

flush()
Return type:

None

StreamHandler

alias of ConsoleHandler

Standard Library Compatibility

ascii_colors.getLogger(name=None)[source]

Get a logger with the specified name.

This function mirrors logging.getLogger() for drop-in compatibility.

Parameters:

name (str | None)

Return type:

_AsciiLoggerAdapter

ascii_colors.basicConfig(*, filename=None, filemode='a', format=None, datefmt=None, style='%', level=None, stream=None, handlers=None, force=False)[source]

Configure basic logging.

Mirrors logging.basicConfig() for drop-in compatibility.

Parameters:
Return type:

None

ascii_colors.shutdown()[source]

Shutdown the logging system.

Return type:

None

ascii_colors.trace_exception(ex, enhanced=False, max_width=None)[source]

Logs the traceback of a given exception.

Parameters:
Return type:

None

ascii_colors.get_trace_exception(ex, enhanced=True, max_width=None)[source]

Formats an exception and its traceback into a string.

Parameters:
Return type:

str

ascii_colors.strip_ansi(text)[source]

Removes ANSI escape sequences from a string.

Parameters:

text (str)

Return type:

str

Interactive Components

ProgressBar

class ascii_colors.ProgressBar(iterable=None, total=None, desc='', unit='it', ncols=None, bar_format=None, leave=True, mininterval=0.15, color='\x1b[32m', style='', background='', bar_style='fill', **kwargs)[source]

Bases: object

Customizable progress bar similar to tqdm.

__init__(iterable=None, total=None, desc='', unit='it', ncols=None, bar_format=None, leave=True, mininterval=0.15, color='\x1b[32m', style='', background='', bar_style='fill', **kwargs)[source]
update(n=1)[source]
close()[source]
update(n=1)[source]
close()[source]

Questionary Compatibility

Drop-in replacement for the questionary library.

class ascii_colors.questionary.Question(message, default=None, validate=None, style=None, **kwargs)[source]

Bases: object

Base class for all question types.

Parameters:
ask(patch_stdout=False, kbi_msg='Cancelled by user')[source]

Ask the question and return the answer.

Parameters:
  • patch_stdout (bool)

  • kbi_msg (str)

Return type:

Any

unsafe_ask(patch_stdout=False)[source]

Ask without catching KeyboardInterrupt.

Parameters:

patch_stdout (bool)

Return type:

Any

skip_if(condition, default=None)[source]

Skip this question if condition is true.

Parameters:
Return type:

Question

ask(patch_stdout=False, kbi_msg='Cancelled by user')[source]

Ask the question and return the answer.

Parameters:
  • patch_stdout (bool)

  • kbi_msg (str)

Return type:

Any

unsafe_ask(patch_stdout=False)[source]

Ask without catching KeyboardInterrupt.

Parameters:

patch_stdout (bool)

Return type:

Any

skip_if(condition, default=None)[source]

Skip this question if condition is true.

Parameters:
Return type:

Question

ascii_colors.questionary.Text

alias of PromptText

class ascii_colors.questionary.Password(message, default='', validate=None, style=None, **kwargs)[source]

Bases: PromptText

Password input (hidden).

Parameters:
class ascii_colors.questionary.Confirm(message, default=True, style=None, **kwargs)[source]

Bases: Question

Yes/No confirmation question.

Parameters:
class ascii_colors.questionary.Select(message, choices, default=None, style=None, **kwargs)[source]

Bases: Question

Single selection from list.

Parameters:
class ascii_colors.questionary.Checkbox(message, choices, default=None, style=None, **kwargs)[source]

Bases: Question

Multiple selection from list.

Parameters:
ask(patch_stdout=False, kbi_msg='Cancelled by user')[source]

Ask the question and return the answer.

Parameters:
  • patch_stdout (bool)

  • kbi_msg (str)

Return type:

Any

skip_if(condition, default=None)[source]

Skip this question if condition is true.

Parameters:
Return type:

Checkbox

unsafe_ask(patch_stdout=False)[source]

Ask without catching KeyboardInterrupt.

Parameters:

patch_stdout (bool)

Return type:

List[Any]

class ascii_colors.questionary.Autocomplete(message, choices, default='', validate=None, style=None, **kwargs)[source]

Bases: PromptText

Text input with autocomplete suggestions.

Parameters:
class ascii_colors.questionary.Form(questions)[source]

Bases: object

Group of questions to ask in sequence.

Parameters:

questions (List[Question])

ask(patch_stdout=False, kbi_msg='Cancelled by user')[source]

Ask all questions and return answers dict.

Parameters:
  • patch_stdout (bool)

  • kbi_msg (str)

Return type:

Dict[str, Any]

ask(patch_stdout=False, kbi_msg='Cancelled by user')[source]

Ask all questions and return answers dict.

Parameters:
  • patch_stdout (bool)

  • kbi_msg (str)

Return type:

Dict[str, Any]

Validation

class ascii_colors.questionary.Validator(message='invalid input')[source]

Bases: object

Base class for input validators.

Parameters:

message (str)

classmethod from_callable(func, message='invalid input')[source]
Parameters:
validate(document)[source]

Validate the input. Raise ValidationError if invalid.

Parameters:

document (str)

Return type:

None

class ascii_colors.questionary.ValidationError(message='invalid input')[source]

Bases: Exception

Exception raised when validation fails.

Parameters:

message (str)

Convenience Functions

ascii_colors.questionary.text(message, default='', validate=None, style=None, **kwargs)[source]

Create a text input question.

Parameters:
Return type:

PromptText

ascii_colors.questionary.password(message, default='', validate=None, style=None, **kwargs)[source]

Create a password input question.

Parameters:
Return type:

Password

ascii_colors.questionary.confirm(message, default=True, style=None, **kwargs)[source]

Create a yes/no confirmation question.

Parameters:
Return type:

Confirm

ascii_colors.questionary.select(message, choices, default=None, style=None, **kwargs)[source]

Create a single-select question.

Parameters:
Return type:

Select

ascii_colors.questionary.checkbox(message, choices, default=None, style=None, **kwargs)[source]

Create a multi-select checkbox question.

Parameters:
Return type:

Checkbox

ascii_colors.questionary.autocomplete(message, choices, default='', validate=None, style=None, **kwargs)[source]

Create an autocomplete text input question.

Parameters:
Return type:

Autocomplete

ascii_colors.questionary.form(*questions)[source]

Create a form from multiple questions.

Parameters:

questions (Question)

Return type:

Form

ascii_colors.questionary.ask(questions)

Group of questions to ask in sequence.

Parameters:

questions (List[Question])

Module-Level Access

For drop-in replacement of questionary:

ascii_colors.questionary: _QuestionaryModule

Module-like object with all questionary functions and classes as attributes.

Example usage:

from ascii_colors import questionary

name = questionary.text("Your name?").ask()
color = questionary.select("Favorite color?", choices=["Red", "Blue"]).ask()

Utility Functions

ascii_colors.get_trace_exception(ex, enhanced=True, max_width=None)[source]

Formats an exception and its traceback into a string.

Get a formatted string representation of an exception and its traceback.

Parameters:
  • ex (BaseException) – The exception to format

  • enhanced (bool) – If True, use enhanced formatting with colors and box drawing

  • max_width (int | None) – Maximum width for output (auto-detected if None)

Returns:

Formatted traceback string

Return type:

str

ascii_colors.strip_ansi(text)[source]

Removes ANSI escape sequences from a string.

Remove ANSI escape sequences from a string.

Parameters:

text (str) – String potentially containing ANSI codes

Returns:

Clean string without ANSI codes

Return type:

str

Internal Classes

These classes are primarily for internal use but may be useful for advanced customization.

class ascii_colors._AsciiLoggerAdapter(name)[source]

Bases: object

Adapter that provides standard logging.Logger interface using ASCIIColors backend.

Adapter class that provides the standard logging.Logger interface while using ascii_colors backend.

Parameters:

name (str)

isEnabledFor(level)[source]

Check if this logger is enabled for the specified level.

This is a standard logging.Logger method that checks whether a message at the given level would actually be logged.

Parameters:

level (int) – The log level to check (e.g., DEBUG, INFO, WARNING)

Returns:

True if the logger is enabled for the given level, False otherwise

Return type:

bool

setLevel(level)[source]

Set the logging level.

Parameters:

level (int | LogLevel)

Return type:

None

getEffectiveLevel()[source]

Get the effective level for this logger.

Return type:

int

debug(msg, *args, **kwargs)[source]

Log a debug message.

Parameters:

msg (str)

Return type:

None

info(msg, *args, **kwargs)[source]

Log an info message.

Parameters:

msg (str)

Return type:

None

warning(msg, *args, **kwargs)[source]

Log a warning message.

Parameters:

msg (str)

Return type:

None

warn(msg, *args, **kwargs)[source]

Deprecated alias for warning.

Parameters:

msg (str)

Return type:

None

error(msg, *args, **kwargs)[source]

Log an error message.

Parameters:

msg (str)

Return type:

None

critical(msg, *args, **kwargs)[source]

Log a critical message.

Parameters:

msg (str)

Return type:

None

fatal(msg, *args, **kwargs)[source]

Log a fatal message (alias for critical).

Parameters:

msg (str)

Return type:

None

exception(msg, *args, **kwargs)[source]

Log an exception message with traceback.

Parameters:

msg (str)

Return type:

None

log(level, msg, *args, **kwargs)[source]

Log a message at the specified level.

Parameters:
Return type:

None

addHandler(hdlr)[source]

Add a handler to this logger.

Parameters:

hdlr (Handler)

Return type:

None

removeHandler(hdlr)[source]

Remove a handler from this logger.

Parameters:

hdlr (Handler)

Return type:

None

hasHandlers()[source]

Check if this logger has any handlers.

Return type:

bool

filter(record)[source]

Filter method (stub for compatibility).

Parameters:

record (Any)

Return type:

bool

handle(record)[source]

Handle a log record.

Parameters:

record (Any)

Return type:

None

findCaller(stack_info=False, stacklevel=1)[source]

Find the caller (stub for compatibility).

Parameters:
  • stack_info (bool)

  • stacklevel (int)

Return type:

Tuple

getChild(suffix)[source]

Get a child logger.

Parameters:

suffix (str)

Return type:

_AsciiLoggerAdapter

property root: bool

Check if this is the root logger.

class ascii_colors._QuestionaryModule[source]

Bases: object

Module-like object for drop-in questionary compatibility.

Module-like object for questionary compatibility.