Module

_cells

Terminal display-cell width helpers.

Python string length counts code points, but terminals lay text out in display cells. Box drawing, CJK characters, combining marks, and ANSI escapes all make len(text)the wrong primitive for fixed-width terminal UI.

Functions

strip_ansi 1 str
Return *value* as text with ANSI SGR/control sequences removed.
def strip_ansi(value: object) -> str
Parameters
Name Type Description
value object
Returns
str
cell_width 1 int
Return the terminal display-cell width of *value*. This intentionally implemen…
def cell_width(value: object) -> int

Return the terminal display-cell width of value.

This intentionally implements the common wcwidth behavior we need without adding a runtime dependency: combining/control characters are zero-width, fullwidth/wide East Asian characters are two cells, and ambiguous-width symbols are treated as one cell for Western terminal defaults.

Parameters
Name Type Description
value object
Returns
int
cell_ljust 3 str
Left-justify *value* to display-cell *width*.
def cell_ljust(value: object, width: int, fill: str = ' ') -> str
Parameters
Name Type Description
value object
width int
fill str Default:' '
Returns
str
cell_rjust 3 str
Right-justify *value* to display-cell *width*.
def cell_rjust(value: object, width: int, fill: str = ' ') -> str
Parameters
Name Type Description
value object
width int
fill str Default:' '
Returns
str
cell_truncate 3 str
Truncate *value* to display-cell *width*, preserving ANSI-free text.
def cell_truncate(value: object, width: int, marker: str = '…') -> str
Parameters
Name Type Description
value object
width int
marker str Default:'…'
Returns
str
cell_fit 4 str
Truncate then left-pad *value* so it occupies exactly *width* cells.
def cell_fit(value: object, width: int, fill: str = ' ', marker: str = '…') -> str
Parameters
Name Type Description
value object
width int
fill str Default:' '
marker str Default:'…'
Returns
str
cell_fill 2 str
Return *fill* repeated/truncated to exactly *width* display cells.
def cell_fill(width: int, fill: str = ' ') -> str
Parameters
Name Type Description
width int
fill str Default:' '
Returns
str
_rule_tail 3 str
Return a fixed-width rule that fades instead of ending abruptly.
def _rule_tail(width: int, fill: str = '─', tail: str = '╌┄') -> str
Parameters
Name Type Description
width int
fill str Default:'─'
tail str Default:'╌┄'
Returns
str
rule_line 6 str
Return a display-cell exact horizontal rule.
def rule_line(value: object = '', width: int = 78, left: str = '╭', right: str = '╮', fill: str = '─', tail: str = '') -> str
Parameters
Name Type Description
value object Default:''
width int Default:78
left str Default:'╭'
right str Default:'╮'
fill str Default:'─'
tail str Default:''
Returns
str
divider_line 2 str
Return a display-cell exact closed-box divider.
def divider_line(value: object = '', width: int = 78) -> str
Parameters
Name Type Description
value object Default:''
width int Default:78
Returns
str
bottom_rule 2 str
Return a display-cell exact closed-box bottom rule.
def bottom_rule(value: object = '', width: int = 78) -> str
Parameters
Name Type Description
value object Default:''
width int Default:78
Returns
str
frame_line 4 str
Return a display-cell exact framed content row.
def frame_line(value: object = '', width: int = 78, left: str = '│', right: str = '│') -> str
Parameters
Name Type Description
value object Default:''
width int Default:78
left str Default:'│'
right str Default:'│'
Returns
str
rail_line 3 str
Return a display-cell exact open-card row with one left rail.
def rail_line(value: object = '', width: int = 78, rail: str = '│') -> str
Parameters
Name Type Description
value object Default:''
width int Default:78
rail str Default:'│'
Returns
str
open_rule 3 str
Return a cell-width exact open-card rule with a fading right edge.
def open_rule(value: object = '', width: int = 78, corner: str = '╭') -> str
Parameters
Name Type Description
value object Default:''
width int Default:78
corner str Default:'╭'
Returns
str
open_rule_divider 2 str
Return a cell-width exact open-card section divider.
def open_rule_divider(value: object = '', width: int = 78) -> str
Parameters
Name Type Description
value object Default:''
width int Default:78
Returns
str
open_rule_end 2 str
Return a cell-width exact open-card bottom rule.
def open_rule_end(value: object = '', width: int = 78) -> str
Parameters
Name Type Description
value object Default:''
width int Default:78
Returns
str
cell_meter 5 str
Return a display-cell exact meter.
def cell_meter(value: int, total: int, width: int = 10, filled: str = '█', empty: str = '░') -> str
Parameters
Name Type Description
value int
total int
width int Default:10
filled str Default:'█'
empty str Default:'░'
Returns
str