maestral.cli.output
This module provides classes and methods for beautifully formatted output to stdout. This includes printing tables and grids, formatting dates and eliding strings.
Module Contents
- maestral.cli.output.elide(text, width, placeholder='...', elide=Elide.Trailing)[source]
Elides a string to fit into the given width.
- maestral.cli.output.adjust(text, width, align=Align.Left)[source]
Pads a string with spaces up the desired width. Preserves ANSI color codes without counting them towards the width.
This function is similar to
str.ljust
andstr.rjust
.
- class maestral.cli.output.Field[source]
Base class to represent a field in a table.
- class maestral.cli.output.TextField(text, align=Align.Left, wraps=False, elide=Elide.Trailing, **style)[source]
Bases:
Field
A text field for a table.
- Parameters
- Elide
Truncation strategy: trailing, center or leading.
- class maestral.cli.output.DateField(dt, **style)[source]
Bases:
Field
A datetime field for a table. The formatting of the datetime will be adjusted depending on the available width. Does not currently support localisation.
- Parameters
dt (datetime.datetime) – Datetime to represent.
style – Styling passed on to
click.style()
when styling the text.
- class maestral.cli.output.Column(title, fields=(), align=Align.Left, wraps=False, elide=Elide.Trailing)[source]
A table column.
- Parameters
title (str | None) – Column title.
fields (Sequence) – Fields in the table. Any sequence of objects can be given and will be converted to
Field
instances as appropriate.align (Align) – How to align text inside the column. Will only be used for
TextField
.wraps (bool) – Whether to wrap fields to fit into the column width instead of truncating them. Will only be used for
TextField
.elide (Elide) – How to elide text which is too wide for a column. Will only be used for
TextField
.
- class maestral.cli.output.Table(columns, padding=2)[source]
A table which can be printed to stdout.
- Parameters
- append(self, row)[source]
Appends a new row to the table.
- Parameters
row (Sequence) – List of fields to append to each column. Length must match the number of columns.
- Return type
None
- format_lines(self, width=None)[source]
Iterator over formatted lines of the table. Fields may span multiple lines if they are set to wrap instead of truncate.
- class maestral.cli.output.Grid(fields=(), padding=2, align=Align.Left)[source]
A grid of fields which can be printed to stdout.
- Parameters
- maestral.cli.output.info(message, nl=True)[source]
Print an info message to stdout. Will be prefixed with a dash.