littlejonny¶
Overview¶
Format output to a text table using unicode box characters.
In case you have been wondering, the name is a reference to https://xkcd.com/327/.
Classes¶
- class pymisclib.littlejonny.LineStyle(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)¶
Rendering style for lines.
- double = Namespace(down_and_horizontal='╦', down_and_left='╗', down_and_right='╔', horizontal='═', up_and_horizontal='╩', up_and_left='╝', up_and_right='╚', vertical='║', vertical_and_horizontal='╬', vertical_and_left='╣', vertical_and_right='╠')¶
- heavy = Namespace(down_and_horizontal='┳', down_and_left='┓', down_and_right='┏', horizontal='━', up_and_horizontal='┻', up_and_left='┛', up_and_right='┗', vertical='┃', vertical_and_horizontal='╋', vertical_and_left='┫', vertical_and_right='┣')¶
- light = Namespace(down_and_horizontal='┬', down_and_left='┐', down_and_right='┌', horizontal='─', up_and_horizontal='┴', up_and_left='┘', up_and_right='└', vertical='│', vertical_and_horizontal='┼', vertical_and_left='┤', vertical_and_right='├')¶
- class pymisclib.littlejonny.ColumnTable(_headings: list[str] = <factory>, _formats: list[str] = <factory>, _cells: list[list[~typing.Any]] = <factory>, _num_columns: int = 0, _num_rows: int = 0)¶
Table with data arranged by column.
- __init__(_headings: list[str] = <factory>, _formats: list[str] = <factory>, _cells: list[list[~typing.Any]] = <factory>, _num_columns: int = 0, _num_rows: int = 0) None¶
- set_table(headings: list[str], cell_formats: list[str], cells: list[list[str]])¶
Set the headings, the output_format of the cells, and the cell content.
The cells are specified column[row].
- set_table_transposed(headings: list[str], cell_formats: list[str], cells: list[list[str]])¶
The cells are specified row[column].
- property cell_formats: list[str]¶
Return headings.
- property headings: list[str]¶
Return headings.
- property num_columns¶
- property num_rows¶
Functions¶
- pymisclib.littlejonny.draw_box(x, y, style) list[str]¶
Construct a box of size x * y with style.
- pymisclib.littlejonny.print_lines(lines: list[str])¶
Print lines stored as a list of strings to stdout.
Example¶
from pymisclib.littlejonny import draw_box, print_lines, LineStyle, ColumnTable
print_lines(draw_box(5, 3, LineStyle.light))
print_lines(draw_box(1, 1, LineStyle.double))
print_lines(draw_box(40, 3, LineStyle.heavy))
ct1 = ColumnTable()
ct1.set_table_transposed(
headings=['First', 'Second', 'Third', 'Fourth'],
cell_formats=['3d', '08x', 's', '>s'],
cells=[[1, 0x12345678, 'abc def geh', 'this is a sample text'],
[2, 0xffffee01, '12345', 'Short'],
[12, -1, 'minus one', 'negative hex number'],
[123, 0, 'zero', 'Zero hexadecimal number'],
[1000, 23, 'First', 'The first column is too large.']]
)
print_lines(ct1.draw(LineStyle.light))
This will yield:
┌─────┐
│ │
│ │
│ │
└─────┘
╔═╗
║ ║
╚═╝
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ ┃
┃ ┃
┃ ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
┌───────┬──────────┬─────────────┬────────────────────────────────┐
│ First │ Second │ Third │ Fourth │
├───────┼──────────┼─────────────┼────────────────────────────────┤
│ 1 │ 12345678 │ abc def geh │ this is a sample text │
│ 2 │ ffffee01 │ 12345 │ Short │
│ 12 │ -0000001 │ minus one │ negative hex number │
│ 123 │ 00000000 │ zero │ Zero hexadecimal number │
│ 1000 │ 00000017 │ First │ The first column is too large. │
└───────┴──────────┴─────────────┴────────────────────────────────┘