smartcols API Reference

Note

str represents both the types str and unicode. It is not compatible with the bytes type.

Warning

Don’t try to use copy.copy() or copy.deepcopy(), it’s not implemented and can break things.

Cell

class smartcols.Cell

Cell.

There is no way to create cell, only way to get this object is from smartcols.Line.

Title

class smartcols.Title

Title.

There is no way to create title, only way to get this object is from smartcols.Table.

Column

class smartcols.Column(self, name=None)

Column.

Parameters

name (str) – Column name

Line

class smartcols.Line(self, parent=None)

Line.

Parameters

parent (smartcols.Line) – Parent line (used if table has column with tree-output)

Get cell

>>> table = smartcols.Table()
>>> column = table.new_column("FOO")
>>> line = table.new_line()
>>> line[column]
<smartcols.Cell object at 0x7f8fb6cc9900>

Set text to cell

>>> table = smartcols.Table()
>>> column = table.new_column("FOO")
>>> line = table.new_line()
>>> line[column] = "bar"

Symbols

class smartcols.Symbols(self)

Symbols.

Table

class smartcols.Table(self)

Table.

Create and print table

>>> table = smartcols.Table()
>>> column_name = table.new_column("NAME")
>>> column_age = table.new_column("AGE")
>>> column_age.right = True
>>> ln = table.new_line()
>>> ln[column_name] = "Igor Gnatenko"
>>> ln[column_age] = "18"
>>> print(table)
NAME          AGE
Igor Gnatenko  18

Useful Functions

smartcols.init_debug(mask=0)

Initialize debugging features. If mask equals to 0, then this function reads the LIBSMARTCOLS_DEBUG environment variable to get mask.

Don’t call this function multiple times.

Parameters

mask (int) – Debug mask (0xffff to enable full debugging)

smartcols.cmpstr_cells(c1, c2, data=None)

Shorthand wrapper around strcmp(). data is ignored.

Parameters
smartcols.wrapnl_chunksize(cl, data, userdata=None)

Split string by newline character and return size of the largest chunk.

Parameters
  • cl (smartcols.Column) – (unused) Column

  • data (str) – String

  • userdata (object or None) – (unused) Additional data

Returns

Size of the largest chunk

Return type

int

smartcols.wrapnl_nextchunk(cl, data, userdata=None)

wrapnl_chunksize(cl, data, userdata=None)

Parameters
  • cl (smartcols.Column) – (unused) Column

  • data (str) – String

  • userdata (object or None) – (unused) Additional data

Returns

Chunk text and separator

Return type

tuple

Enumerations used by functions

class smartcols.CellPosition

Cell position. Currently used only in smartcols.Title.

left
Align text to the left.
center
Align text to the center.
right
Align text to the right.
class smartcols.TermForce

Control terminal output usage.

auto
Automatically detect if terminal or non-terminal output.
never
Force to use stdout as non-terminal output.
always
Force to use stdout as terminal output.