cfx.display¶
Formatting helpers for rendering Config instances as text or HTML tables.
This module is intentionally not re-exported from the top-level package. Import directly when needed:
from cfx.display import make_table, as_table
Public API¶
- textwrap_cell, textwrap_row
Text/terminal table cell and row helpers.
- wrap_cell, wrap_row
HTML tag helpers with optional attribute support.
- make_table
Unified table builder - produces either a fixed-width text table or an HTML
<table>from a list of(config, name, value, doc)rows.- as_table
Full config renderer for
__str__(format"text") and_repr_html_(format"html").- as_inline_string
Compact
ClassName(k=v, ...)one-liner for__repr__.- config_tree
Tree diagram of a config hierarchy with wrapped docstrings.
- table_rows
Extract
(field_name, current_value, doc)3-tuples from a flat config.- flat_table_rows
Extract
(class_name, field_name, value, doc)4-tuples recursively.
Functions¶
|
Reformat a paragraph to fit into no more than |
|
Given a list of paragraphs, wraps each paragraph at max_widths columns. |
|
Wrap content in an HTML tag. |
|
Wrap a list of strings in an HTML tag. |
|
Extract |
|
Extract |
|
Render a compact tree diagram of a config hierarchy. |
|
Format |
|
Render a |
|
Render a |
Module Contents¶
- cfx.display.textwrap_cell(text, max_w)[source]¶
Reformat a paragraph to fit into no more than
max_wcolumns.By default, tabs in ‘text’ are expanded with string.expandtabs(), and all other whitespace characters (including newline) are converted to space. An empty string produces a single-element list
[""]so that callers never receive an empty list.
- cfx.display.textwrap_row(row, max_widths)[source]¶
Given a list of paragraphs, wraps each paragraph at max_widths columns.
- Parameters:
- row
tuple[str] Cell strings, one per column.
- max_widths
tuple[int] Column width limits, one per column.
- row
- Returns:
- wrapped:
list[list[str]] One list-of-lines per column.
- wrapped:
- cfx.display.wrap_cell(content, tag='td', attrs=None)[source]¶
Wrap content in an HTML tag.
Given a string and a tag, returns <tag> content </tag>. The attributes, when provided, are unrolled as html tag attributes, f.e.: <tag id=1> content </tag>
- cfx.display.table_rows(cfg)[source]¶
Extract
(field_name, current_value, doc)tuples from cfg.- Parameters:
- cfg
Config Any
Configinstance.
- cfg
- Returns:
- rows:
list[tuple] 3-tuples of
(key, formatted_value, doc).
- rows:
- cfx.display.flat_table_rows(cfg)[source]¶
Extract
(class_name, key, value, doc)tuples from cfg recursively.Walks cfg and all nested sub-configs depth-first, prepending the class name as a leading column so all fields across the whole hierarchy can be rendered in a single unified table.
- Parameters:
- cfg
Config Any
Configinstance, flat or nested.
- cfg
- Returns:
- rows
list[tuple] 4-tuples of
(class_name, key, formatted_value, doc).
- rows
- cfx.display.config_tree(cfg, width=79, _cont='', _branch='')[source]¶
Render a compact tree diagram of a config hierarchy.
Each node shows the class name and its docstring (preserved as-is, not reflowed). Sub-configs are connected with unicode box-drawing characters.
- Parameters:
- cfg
Config Root config instance.
- width
int, optional Kept for API compatibility; no longer used internally. Default
79.- _cont
str Internal: continuation prefix for docstring lines and child prefixes. Do not pass manually.
- _branch
str Internal: prefix for this node’s first line (e.g.
"├─ "). Do not pass manually.
- cfg
- Returns:
- tree
str Multi-line tree string.
- tree
- cfx.display.make_table(rows, format='text', max_config_width=25, max_key_width=20, max_value_width=25, max_desc_width=50, table_attrs=None)[source]¶
Format
(config, name, value, doc)rows as a text or HTML table.- Parameters:
- rows
list[tuple] Each tuple is
(config_class, key, value, description).- format
str, optional "text"for a fixed-width terminal table;"html"for a<table>string. Default"text".- max_config_width
int, optional Max width for the Config column. Ignored in HTML mode.
- max_key_width
int, optional Max width for the Key column. Ignored in HTML mode.
- max_value_width
int, optional Max width for the Value column. Ignored in HTML mode.
- max_desc_width
int, optional Max width for the Description column. Ignored in HTML mode.
- table_attrs
dictorNone, optional HTML attributes added to the
<table>tag, e.g.{"class": "my-table", "id": "pipeline-config"}. Only used whenformat="html". DefaultNone.
- rows
- Returns:
- table:
str Fixed-width text table or
<table>...</table>HTML string.
- table:
- cfx.display.as_table(cfg, format='text', table_attrs=None)[source]¶
Render a
Configinstance as a full text or HTML table.Produces a tree diagram of the config hierarchy (with wrapped docstrings) followed by a single unified table with a leading Config column. Works for flat, nested, and mixed flat+nested configs.
- Parameters:
- Returns:
- table
str Tree diagram followed by the unified field table.
- table