flexget.terminal module#

class flexget.terminal.TerminalTable(*args, table_type=None, **kwargs)[source]#

Bases: Table

A data table suited for CLI output, created via its sent parameters.

For example:

header = ['Col1', 'Col2']
table_data = [header]
for item in iterable:
    table_data.append([item.attribute1, item.attribute2])
table = TerminalTable('plain', table_data)
print table.output

Optional values are setting table title, and supplying wrap_columns list and drop_column list. If table does not fit into terminal any columns listed in wrap_columns will be tried to wrap and if resulting columns are below MIN_WIDTH(10) columns listed in drop_column will be removed from output.

Example:

header = ['Col1', 'Col2']
table_data = [header]
for item in iterable:
    table_data.append([item.attribute1, item.attribute2])
table = TerminalTable('plain', table_data, 'Table title', wrap_columns=[1,2],
                      drop_columns=[4,2])
print table.output
Parameters:

table_type (str | None) – A string matching TABLE_TYPES keys.

class Column(header='', footer='', header_style='', footer_style='', style='', justify='left', vertical='top', overflow='ellipsis', width=None, min_width=None, max_width=None, ratio=None, no_wrap=False, highlight=False, _index=0, _cells=<factory>)#

Bases: object

Defines a column within a ~Table.

Args:

title (Union[str, Text], optional): The title of the table rendered at the top. Defaults to None. caption (Union[str, Text], optional): The table caption rendered below. Defaults to None. width (int, optional): The width in characters of the table, or None to automatically fit. Defaults to None. min_width (Optional[int], optional): The minimum width of the table, or None for no minimum. Defaults to None. box (box.Box, optional): One of the constants in box.py used to draw the edges (see Box), or None for no box lines. Defaults to box.HEAVY_HEAD. safe_box (Optional[bool], optional): Disable box characters that don’t display on windows legacy terminal with raster fonts. Defaults to True. padding (PaddingDimensions, optional): Padding for cells (top, right, bottom, left). Defaults to (0, 1). collapse_padding (bool, optional): Enable collapsing of padding around cells. Defaults to False. pad_edge (bool, optional): Enable padding of edge cells. Defaults to True. show_header (bool, optional): Show a header row. Defaults to True. show_footer (bool, optional): Show a footer row. Defaults to False. show_edge (bool, optional): Draw a box around the outside of the table. Defaults to True. show_lines (bool, optional): Draw lines between every row. Defaults to False. leading (int, optional): Number of blank lines between rows (precludes show_lines). Defaults to 0. style (Union[str, Style], optional): Default style for the table. Defaults to “none”. row_styles (List[Union, str], optional): Optional list of row styles, if more than one style is given then the styles will alternate. Defaults to None. header_style (Union[str, Style], optional): Style of the header. Defaults to “table.header”. footer_style (Union[str, Style], optional): Style of the footer. Defaults to “table.footer”. border_style (Union[str, Style], optional): Style of the border. Defaults to None. title_style (Union[str, Style], optional): Style of the title. Defaults to None. caption_style (Union[str, Style], optional): Style of the caption. Defaults to None. title_justify (str, optional): Justify method for title. Defaults to “center”. caption_justify (str, optional): Justify method for caption. Defaults to “center”. highlight (bool, optional): Highlight cell contents (if str). Defaults to False.

Parameters:
  • header (RenderableType)

  • footer (RenderableType)

  • header_style (str | Style)

  • footer_style (str | Style)

  • style (str | Style)

  • justify (JustifyMethod)

  • vertical (VerticalAlignMethod)

  • overflow (OverflowMethod)

  • width (int | None)

  • min_width (int | None)

  • max_width (int | None)

  • ratio (int | None)

  • no_wrap (bool)

  • highlight (bool)

  • _index (int)

  • _cells (List[RenderableType])

copy()#

Return a copy of this Column.

Return type:

Column

_cells: List[RenderableType]#
_index: int = 0#

Index of column.

property cells: Iterable[RenderableType]#

Get all cells in the column, not including header.

property flexible: bool#

Check if this column is flexible.

footer: RenderableType = ''#

RenderableType: Renderable for the footer (typically a string)

footer_style: str | Style = ''#

StyleType: The style of the footer.

header: RenderableType = ''#

RenderableType: Renderable for the header (typically a string)

header_style: str | Style = ''#

StyleType: The style of the header.

highlight: bool = False#

bool: Apply highlighter to column. Defaults to False.

justify: JustifyMethod = 'left'#

str: How to justify text within the column (“left”, “center”, “right”, or “full”)

max_width: int | None = None#

Optional[int]: Maximum width of column, or None for no maximum. Defaults to None.

min_width: int | None = None#

Optional[int]: Minimum width of column, or None for no minimum. Defaults to None.

no_wrap: bool = False#

bool: Prevent wrapping of text within the column. Defaults to False.

overflow: OverflowMethod = 'ellipsis'#

str: Overflow method.

ratio: int | None = None#

Optional[int]: Ratio to use when calculating column width, or None (default) to adapt to column contents.

style: str | Style = ''#

StyleType: The style of the column.

vertical: VerticalAlignMethod = 'top'#

str: How to vertically align content (“top”, “middle”, or “bottom”)

width: int | None = None#

Optional[int]: Width of the column, or None (default) to auto calculate width.

TABLE_TYPES = {'double': {'box': Box(...)}, 'github': {'box': Box(...)}, 'heavy-head': {'box': Box(...)}, 'plain': {'box': Box(...)}, 'porcelain': {'box': Box(...), 'pad_edge': False, 'padding': 0, 'show_edge': False, 'title': None}, 'single': {'box': Box(...)}}#
class flexget.terminal._Console(*args, **kwargs)[source]#

Bases: Console

_print(*args, **kwargs)[source]#

Be the real parent print function, which can be called internally.

print(*args, **kwargs)[source]#

Also capture calls directly to console.print.

Return type:

None

rule(title='', *, characters='─', style='rule.line', align='left', indent=3)[source]#

Draw a line with optional centered title.

Args:

title (str, optional): Text to render over the rule. Defaults to “”. characters (str, optional): Character(s) to form the line. Defaults to “─”. style (str, optional): Style of line. Defaults to “rule.line”. align (str, optional): How to align the title, one of “left”, “center”, or “right”. Defaults to “center”.

Parameters:
  • title (rich.text.TextType)

  • characters (str)

  • style (str | rich.console.Style)

  • align (rich.text.AlignMethod)

  • indent (int)

Return type:

None

flexget.terminal._patchable_console(*args, **kwargs)[source]#
flexget.terminal.capture_console(filelike)[source]#
Parameters:

filelike (TextIO)

Return type:

Iterator

flexget.terminal.colorize(color, text)[source]#

Override Color.colorize by setting the default auto colors value to True, since it’s the more common use case.

When output isn’t TTY just return text

Parameters:
  • color (str) – Color tag to use

  • text (str) – Text to color

Returns:

Colored text or text

Return type:

str

flexget.terminal.disable_colors()[source]#

Disables colors to the terminal.

flexget.terminal.get_console_output()[source]#
Return type:

TextIO | None

flexget.terminal.word_wrap(text, max_length)[source]#

Be a helper method designed to return a wrapped string.

Parameters:
  • text (str) – Text to wrap

  • max_length (int) – Maximum allowed string length

Returns:

Wrapped text or original text

Return type:

str