euporie.core.ft.table

Allow drawing tables as FormattedText.

Functions

align(ft[, how, width, style, placeholder, ...])

Align formatted text at a given width.

calculate_cell_width(cell[, render_count])

Compute the final width of a cell, including padding.

calculate_col_widths(cols, width, ...[, ...])

Calculate column widths given the available space.

cast(typ, val)

Cast a value to a type.

compute_align(cell[, render_count])

Compute the alignment of a cell.

compute_border_line(cell[, render_count])

Compute a cell's border line.

compute_border_style(cell[, render_count])

Compute the cell's final style for each of a cell's borders.

compute_border_visibility(cell[, render_count])

Compute a cell's border visibility.

compute_border_width(cell[, render_count])

Compute the width of a cell's borders.

compute_lines(cell, width[, render_count])

Wrap the cell's text to a given width.

compute_padding(cell[, render_count])

Compute a cell's padding.

compute_style(cell[, render_count])

Compute a cell's style string.

compute_text(cell[, render_count])

Compute a cell's input, converted to FormattedText.

fragment_list_width(fragments)

Return the character width of this text fragment list.

get_app_session()

get_grid_char(key)

Return the character represented by a combination of LineStyles.

get_horizontal_edge(n_bl, s_bl)

Calculate which character to use to divide horizontally adjacent cells.

get_node(nw_bl, ne_bl, se_bl, sw_bl)

Calculate which character to use at the intersection of four cells.

get_vertical_edge(w_bl, e_bl)

Calculate which character to use to divide vertically adjacent cells.

join_lines(fragments)

Join a list of lines of formatted text.

lru_cache([maxsize, typed])

Least-recently-used cache decorator.

max_line_width(ft)

Calculate the length of the longest line in formatted text.

pairwise(iterable)

Return successiver overlapping pairs from an iterable.

split_lines(fragments)

Take a single list of (style_str, text) tuples and yield one such list for each line.

tee(iterable[, n])

Returns a tuple of n independent iterators.

to_dimension(value)

Turn the given object into a Dimension object.

to_formatted_text(value[, style, auto_convert])

Convert the given value (which can be formatted text) into a list of text fragments.

to_plain_text(value)

Turn any kind of formatted text back into plain text.

wrap(ft, width[, style, placeholder, left, ...])

Wrap formatted text at a given width.

Classes

Cell([text, row, col, colspan, rowspan, ...])

A table cell.

Col([table, cells, align, style, padding, ...])

A column in a table.

DiBool([top, right, bottom, left])

A tuple of four bools with directions.

DiInt([top, right, bottom, left])

A tuple of four integers with directions.

DiLineStyle([top, right, bottom, left])

A description of a cell border: a LineStyle for each edge.

DiStr([top, right, bottom, left])

A tuple of four strings with directions.

Dimension([min, max, weight, preferred])

Specified dimension (width/height) of a user control or window.

DummyCol([table, cells, align, style, ...])

A dummy column - created to hold cells without an assigned column.

DummyRow([table, cells, align, style, ...])

A dummy row - created to hold cells without an assigned column.

DummyTable(*args, **kwargs)

A dummy table - created to hold rows and columns without an assigned table.

FormattedTextAlign(value[, names, module, ...])

Alignment of formatted text.

GridChar(north, east, south, west)

Repreentation of a grid node character.

LineStyle(name, rank[, parent, visible])

Define a line style which can be used to draw grids.

Row([table, cells, align, style, padding, ...])

A row in a table.

RowCol([table, cells, align, style, ...])

Base class for table rows and columns.

SpacerCell(expands, span_row_index, ...[, ...])

A dummy cell to virtually occupy space when colspan or rowspan are used.

Table([rows, cols, width, expand, align, ...])

A table.

defaultdict

defaultdict(default_factory=None, /, [...]) --> dict with default factory

partial

partial(func, *args, **keywords) - new function with partial application of the given arguments and keywords.

zip_longest

zip_longest(iter1 [,iter2 [...]], [fillvalue=None]) --> zip_longest object

class euporie.core.ft.table.Cell(text: AnyFormattedText = '', row: Row | None = None, col: Col | None = None, colspan: int = 1, rowspan: int = 1, width: int | None = None, align: FormattedTextAlign | None = None, style: str = '', padding: DiInt | int = 0, border_line: DiLineStyle | LineStyle = LineStyle(Thin), border_style: DiStr | str = '', border_visibility: DiBool | bool | None = True)

Bases: object

A table cell.

property border_line: DiLineStyle

The cell’s border line.

property border_style: DiStr

The cell’s border style.

property padding: DiInt

The cell’s padding.

class euporie.core.ft.table.Col(table: Table | None = None, cells: Sequence[Cell] | None = None, align: FormattedTextAlign | None = None, style: str = '', padding: DiInt | int = 0, border_line: DiLineStyle | LineStyle = LineStyle(None), border_style: DiStr | str = '', border_visibility: DiBool | bool | None = None)

Bases: RowCol

A column in a table.

add_cell(cell: Cell, index: int | None = None) None

Add a cell to the row/ column.

property border_line: DiLineStyle

The cell’s border line.

property border_style: DiStr

The cell’s border style.

property cells: list[euporie.core.ft.table.Cell]

List the cells in the row/column.

new_cell(*args: Any, **kwargs: Any) Cell

Create a new cell in this row/column.

property padding: DiInt

The cell’s padding.

span_type: str = 'rowspan'
class euporie.core.ft.table.DummyCol(table: Table | None = None, cells: Sequence[Cell] | None = None, align: FormattedTextAlign | None = None, style: str = '', padding: DiInt | int = 0, border_line: DiLineStyle | LineStyle = LineStyle(None), border_style: DiStr | str = '', border_visibility: DiBool | bool | None = None)

Bases: Col

A dummy column - created to hold cells without an assigned column.

add_cell(cell: Cell, index: int | None = None) None

Prevent cells being added to a dummy column.

property border_line: DiLineStyle

The cell’s border line.

property border_style: DiStr

The cell’s border style.

property cells: list[euporie.core.ft.table.Cell]

List the cells in the row/column.

new_cell(*args: Any, **kwargs: Any) Cell

Create a new cell in this row/column.

property padding: DiInt

The cell’s padding.

span_type: str = 'rowspan'
class euporie.core.ft.table.DummyRow(table: Table | None = None, cells: Sequence[Cell] | None = None, align: FormattedTextAlign | None = None, style: str = '', padding: DiInt | int = 0, border_line: DiLineStyle | LineStyle = LineStyle(None), border_style: DiStr | str = '', border_visibility: DiBool | bool | None = None)

Bases: Row

A dummy row - created to hold cells without an assigned column.

add_cell(cell: Cell, index: int | None = None) None

Prevent cells being added to a dummy row.

property border_line: DiLineStyle

The cell’s border line.

property border_style: DiStr

The cell’s border style.

property cells: list[euporie.core.ft.table.Cell]

List the cells in the row/column.

new_cell(*args: Any, **kwargs: Any) Cell

Create a new cell in this row/column.

property padding: DiInt

The cell’s padding.

span_type: str = 'colspan'
class euporie.core.ft.table.DummyTable(*args: Any, **kwargs: Any)

Bases: Table

A dummy table - created to hold rows and columns without an assigned table.

add_col(col: Col) None

Prevent columns being added to a dummy table.

add_row(row: Row) None

Prevent rows being added to a dummy table.

property border_line: DiLineStyle

The cell’s border line.

property border_style: DiStr

The cell’s border style.

calculate_cell_widths(width: AnyDimension | None = None) dict[Cell, int]

Calculate widths for each table cell, taking colspans into account.

calculate_col_widths(width: AnyDimension | None = None, min_col_width: int = 4) list[int]

Calculate the table’s column widths.

property cols: list[euporie.core.ft.table.Col]

A list of columns in the table.

draw_table_row(row_above: RowCol | None, row_below: RowCol | None, cell_widths: dict[Cell, int], col_widths: list[int], row_edge_visibility: bool, col_edge_visibilities: dict[int, bool]) Iterable[StyleAndTextTuples]

Draw a row in the table.

new_col(*args: Any, **kwargs: Any) Col

Create a new column in the table.

new_row(*args: Any, **kwargs: Any) Row

Create a new row in the table.

property padding: DiInt

The cell’s padding.

render(width: AnyDimension | None = None) StyleAndTextTuples

Draw the table, optionally at a given character width.

property rows: list[euporie.core.ft.table.Row]

A list of rows in the table.

sync_cols_to_rows() None

Enure cells in columns are present in the relevant rows.

sync_rows_to_cols() None

Enure cells in rows are present in the relevant columns.

property width: Dimension

The table’s width.

class euporie.core.ft.table.Row(table: Table | None = None, cells: Sequence[Cell] | None = None, align: FormattedTextAlign | None = None, style: str = '', padding: DiInt | int = 0, border_line: DiLineStyle | LineStyle = LineStyle(None), border_style: DiStr | str = '', border_visibility: DiBool | bool | None = None)

Bases: RowCol

A row in a table.

add_cell(cell: Cell, index: int | None = None) None

Add a cell to the row/ column.

property border_line: DiLineStyle

The cell’s border line.

property border_style: DiStr

The cell’s border style.

property cells: list[euporie.core.ft.table.Cell]

List the cells in the row/column.

new_cell(*args: Any, **kwargs: Any) Cell

Create a new cell in this row/column.

property padding: DiInt

The cell’s padding.

span_type: str = 'colspan'
class euporie.core.ft.table.RowCol(table: Table | None = None, cells: Sequence[Cell] | None = None, align: FormattedTextAlign | None = None, style: str = '', padding: DiInt | int = 0, border_line: DiLineStyle | LineStyle = LineStyle(None), border_style: DiStr | str = '', border_visibility: DiBool | bool | None = None)

Bases: object

Base class for table rows and columns.

add_cell(cell: Cell, index: int | None = None) None

Add a cell to the row/ column.

property border_line: DiLineStyle

The cell’s border line.

property border_style: DiStr

The cell’s border style.

property cells: list[euporie.core.ft.table.Cell]

List the cells in the row/column.

new_cell(*args: Any, **kwargs: Any) Cell

Create a new cell in this row/column.

property padding: DiInt

The cell’s padding.

span_type: str
class euporie.core.ft.table.SpacerCell(expands: Cell, span_row_index: int, span_col_index: int, text: AnyFormattedText = '', row: Row | None = None, col: Col | None = None, colspan: int = 1, rowspan: int = 1, width: int | None = None, align: FormattedTextAlign | None = None, style: str = '', padding: DiInt | int | None = None, border_line: DiLineStyle | LineStyle = LineStyle(None), border_style: DiStr | str = '', border_visibility: DiBool | bool | None = None)

Bases: Cell

A dummy cell to virtually occupy space when colspan or rowspan are used.

property border_line: DiLineStyle

The cell’s border line.

property border_style: DiStr

The cell’s border style.

property padding: DiInt

The cell’s padding.

class euporie.core.ft.table.Table(rows: Sequence[Row] | None = None, cols: Sequence[Col] | None = None, width: AnyDimension | None = None, expand: bool = False, align: FormattedTextAlign = FormattedTextAlign.LEFT, style: str = '', padding: DiInt | int | None = None, border_line: DiLineStyle | LineStyle = LineStyle(None), border_style: DiStr | str = '', border_visibility: DiBool | bool = False, background_style: str = '')

Bases: object

A table.

add_col(col: Col) None

Add a column to the table.

add_row(row: Row) None

Add a row to the table.

property border_line: DiLineStyle

The cell’s border line.

property border_style: DiStr

The cell’s border style.

calculate_cell_widths(width: AnyDimension | None = None) dict[Cell, int]

Calculate widths for each table cell, taking colspans into account.

calculate_col_widths(width: AnyDimension | None = None, min_col_width: int = 4) list[int]

Calculate the table’s column widths.

property cols: list[euporie.core.ft.table.Col]

A list of columns in the table.

draw_table_row(row_above: RowCol | None, row_below: RowCol | None, cell_widths: dict[Cell, int], col_widths: list[int], row_edge_visibility: bool, col_edge_visibilities: dict[int, bool]) Iterable[StyleAndTextTuples]

Draw a row in the table.

new_col(*args: Any, **kwargs: Any) Col

Create a new column in the table.

new_row(*args: Any, **kwargs: Any) Row

Create a new row in the table.

property padding: DiInt

The cell’s padding.

render(width: AnyDimension | None = None) StyleAndTextTuples

Draw the table, optionally at a given character width.

property rows: list[euporie.core.ft.table.Row]

A list of rows in the table.

sync_cols_to_rows() None

Enure cells in columns are present in the relevant rows.

sync_rows_to_cols() None

Enure cells in rows are present in the relevant columns.

property width: Dimension

The table’s width.

euporie.core.ft.table.calculate_cell_width(cell: Cell, render_count: int = 0) int

Compute the final width of a cell, including padding.

euporie.core.ft.table.calculate_col_widths(cols: tuple[euporie.core.ft.table.Col], width: Dimension, expand_to_width: bool, min_col_width: int = 2, render_count: int = 0) list[int]

Calculate column widths given the available space.

Reduce the widest column until we fit in available width, or expand cells to to fill the available width.

Parameters:
  • cols – A list of columns in the table

  • width – The desired width of the table

  • expand_to_width – Whether the column should expand to fill the available width

  • min_col_width – The minimum width allowed for a column

  • render_count – The number of times the app has been rendered

Returns:

List of new column widths

euporie.core.ft.table.compute_align(cell: Cell, render_count: int = 0) FormattedTextAlign

Compute the alignment of a cell.

euporie.core.ft.table.compute_border_line(cell: Cell, render_count: int = 0) DiLineStyle

Compute a cell’s border line.

euporie.core.ft.table.compute_border_style(cell: Cell, render_count: int = 0) DiStr

Compute the cell’s final style for each of a cell’s borders.

euporie.core.ft.table.compute_border_visibility(cell: Cell, render_count: int = 0) DiBool

Compute a cell’s border visibility.

euporie.core.ft.table.compute_border_width(cell: Cell, render_count: int = 0) DiInt

Compute the width of a cell’s borders.

euporie.core.ft.table.compute_lines(cell: Cell, width: int, render_count: int = 0) list[StyleAndTextTuples]

Wrap the cell’s text to a given width.

Parameters:
  • cell – The cell whose lines to compute

  • width – The width at which to wrap the cell’s text.

  • render_count – The number of times the application has been rendered

Returns:

A list of lines of formatted text

euporie.core.ft.table.compute_padding(cell: Cell, render_count: int = 0) DiInt

Compute a cell’s padding.

euporie.core.ft.table.compute_style(cell: Cell, render_count: int = 0) str

Compute a cell’s style string.

euporie.core.ft.table.compute_text(cell: Cell, render_count: int = 0) StyleAndTextTuples

Compute a cell’s input, converted to FormattedText.

euporie.core.ft.table.get_horizontal_edge(n_bl: DiLineStyle, s_bl: DiLineStyle) str

Calculate which character to use to divide horizontally adjacent cells.

euporie.core.ft.table.get_node(nw_bl: DiLineStyle, ne_bl: DiLineStyle, se_bl: DiLineStyle, sw_bl: DiLineStyle) str

Calculate which character to use at the intersection of four cells.

euporie.core.ft.table.get_vertical_edge(w_bl: DiLineStyle, e_bl: DiLineStyle) str

Calculate which character to use to divide vertically adjacent cells.

euporie.core.ft.table.pairwise(iterable: Iterable[PairT]) Iterator[tuple[PairT, PairT]]

Return successiver overlapping pairs from an iterable.