Inline box rendering for replayable views of text content.
frames provides functions for formatting framed text from Content. Content represents a sequence rows consisting of a single column; the placement of str instances within the tuples contained by the sequence controls the alignment of the displayed text. A leading None within the instance causes a horizontal separator to be drawn according to the selected box theme.
Engineering
Somewhat of a warning. Raw (integer) indexes are commonly used within this module; the "themes" are regular strings, f_solid, and the indexes refer to the boundary character at that index within the theme. The included themes have identical character counts, but customized themes may have extensions in order to support transitions by stitch.
typing
itertools
functools
halves
halves = "\u258C\u2590"
charif
charif(characters)
Whether the character is a Unicode Box Drawing character.
Content
Content = typing.Sequence[
typing.Union[
# Left and Right text; use empty strings to disable a side.
typing.Tuple[str, str],
# Aligned center; only one field is allowed for centering.
typing.Tuple[str, None],
# Division (horizontal bar)
typing.Tuple[None],
# Division, custom horizontal.
typing.Tuple[None, str],
]
]
dlength
dlength(field)
dformat
dformat(context, field)
strings
strings(sequence)
Emit the formatted lines of a prepared sequence as str instances. Newline characters are not added to line.
keys
keys = [
'top-left-corner',
'top-horizontal-left',
'top-intersection',
'top-horizontal-right',
'top-right-corner',
'heading-vertical-open',
'space',
'heading-vertical-center',
'space',
'heading-vertical-close',
'left-intersection',
'body-horizontal-left',
'full-intersection',
'body-horizontal-right',
'right-intersection',
'body-vertical-open',
'space',
'body-vertical-center',
'space',
'body-vertical-close',
'bottom-left-corner',
'bottom-horizontal-left',
'bottom-intersection',
'bottom-horizontal-right',
'bottom-right-corner',
# Any extensions will be local to the frame theme.
]
corners
corners = [
'top-left-corner',
'top-right-corner',
'bottom-left-corner',
'bottom-right-corner',
]
f_ascii
f_ascii = (
'+' '-' '+' '-' '+'
'|' ' ' '|' ' ' '|'
'+' '-' '+' '-' '+'
'|' ' ' '|' ' ' '|'
'+' '-' '+' '-' '+'
)
f_bold
f_bold = (
'┏' '━' '┳' '━' '┓'
'┃' ' ' '┃' ' ' '┃'
'┣' '━' '╋' '━' '┫'
'┃' ' ' '┃' ' ' '┃'
'┗' '━' '┻' '━' '┛'
)
f_solid
f_solid = (
'┌' '─' '┬' '─' '┐'
'│' ' ' '│' ' ' '│'
'├' '─' '┼' '─' '┤'
'│' ' ' '│' ' ' '│'
'└' '─' '┴' '─' '┘'
)
f_double
f_double = (
'╔' '═' '╦' '═' '╗'
'║' ' ' '║' ' ' '║'
'╠' '═' '╬' '═' '╣'
'║' ' ' '║' ' ' '║'
'╚' '═' '╩' '═' '╝'
)
rounds
rounds=('╭' '╮' '╰' '╯')
_corner_adjustments
_corner_adjustments(space, selections)
round
round(theme, *corners)
Create a new theme based on theme applying rounded corners where specified in corners.
rdiagonal = round(f_solid, 'top-left', 'bottom-right')
width
width(sequence)
Calculate the sum of the lengths of each item in the sequence; excepting values starting with None representing a division.
prepare
prepare(theme, width, sequence)
Build sequences of strings providing the necessary formatting for the display of the framed data.
prepareParameters
align
align(left, right, offsets)
Vertically pad the two prepared images with empty records according to the describes offsets.
alignParameters
combinations
combinations = {
(5, 1): 12,
(1, 5): 12,
(4, 10): 12,
(4, 20): 12,
(14, 0): 12,
(14, 10): 12,
(14, 20): 12,
(24, 10): 12,
(24, 0): 12,
(4, 5): 14,
(14, 5): 14,
(24, 5): 14,
(5, 20): 10,
(5, 10): 10,
(5, 0): 10,
(5, 15): 15,
(4, 0): 2,
(0, 4): 2,
(5, 24): 19,
(24, 20): 22,
}
combine
combine(theme, mapping, borders)
Calculate the combined border for the given characters according to the theme, combination mapping using the adjacent borders.
stitch
stitch(aligned)
Connects prepared frames along the vertical borders.
Join two prepared frames so that intersections are properly combined. Both the left and right sides are modified in place respecting the boundaries.
If the two prepared frames are not of equal length (rows), align must be called on the two frames before being given to stitch.