9. pypsi.format - Stream output formatting¶
Provides functions and classes for dealing with command line input and output.
-
class
pypsi.format.
Column
(text='', mode=0)[source]¶ Bases:
object
A table column.
Parameters: -
Grow
= 1¶ Size mode to have the column grow to the maximum width it can have
-
Shrink
= 0¶ Size mode to have the column shrink to its contents
-
-
class
pypsi.format.
FixedColumnTable
(widths)[source]¶ Bases:
object
A table that has preset column widths.
Parameters: widths (list) – the list of column widths (int)
-
class
pypsi.format.
Table
(columns, width=80, spacing=1, header=True)[source]¶ Bases:
object
Variable width table.
Parameters: - columns (multiple) – a list of either class:Column instances or a single int defining how many columns to create
- width (int) – the maximum width of the entire table
- spacing (int) – the amount of space characters to display between columns
- header (bool) – whether to display header row with the column names
-
pypsi.format.
file_size_str
(value)[source]¶ Get the human readable file size string from a number. This will convert a value of 1024 to 1Kb and 1048576 to 1Mb.
Parameters: value (int) – the value to convert Returns str: the human readable file size string
-
pypsi.format.
get_lines
(txt)[source]¶ Break text to individual lines.
Returns tuple: a tuple containing the next line and whether the line contained a newline charater.
-
pypsi.format.
highlight
(target, term, color='1;32')[source]¶ Find and highlight a term inside of a block of text.
Parameters: Returns str: the input string with all occurrences of the term highlighted