fspath.sui module

Simple user interface via terminal (win & *nix)

This module is in a very early stage, don’t use it!

class fspath.sui.ASCIITableFormatter(*cols)[source]

Bases: object

Simple ASCII table formatter

rows = [  {'foo': 'foo row 1', 'bar': 'bar row 1'}
          , {'foo': 'foo row 2', 'bar': 'bar row 2'} ]

table = ASCIITableFormatter(
    # <col-title>, <format sting>, <attribute name>
    ("Foo",   "%-12s", "foo")
    , ("Bar", "%-30s", "bar"))
SUI.echo(table(rows))
============ ==============================
Foo          Bar
============ ==============================
foo row 1    bar row 1
foo row 2    bar row 2
============ ==============================
col_end = ' '
col_head_end = ' '
col_head_start = ''
col_start = ''
escape(value)[source]

escape value

get_value(attr, row, default='?')[source]

get value from col (attr) and row

head_end = ''
head_start = '\n'
row_end = ''
row_start = '\n'
sep_end = ' '
sep_line = '='
sep_start = ''
table_end = ''
table_start = ''
class fspath.sui.HTMLTableFormatter(*cols)[source]

Bases: ASCIITableFormatter

Simple HTML table formatter

rows = [  {'foo': 'foo <row 1>', 'bar': 'bar <row 1>'}
          , {'foo': 'foo <row 2>', 'bar': 'bar <row 2>'} ]

table = HTMLTableFormatter(("Foo", "%s", "foo")
                         , ("Bar", "%s", "bar"))
SUI.echo(table(rows))
<table>
  <tr class='heading'>
    <th>Foo</th>
    <th>Bar</th>
  </tr>
  <tr>
    <td>foo &lt;row 1&gt;</td>
    <td>bar &lt;row 1&gt;</td>
  </tr>
  <tr>
    <td>foo &lt;row 2&gt;</td>
    <td>bar &lt;row 2&gt;</td>
  </tr>
</table>
ESCAPE = '<!--(set_escape)-->HTML<!--(end)-->\n#!'
col_end = '</td>'
col_head_end = '</th>'
col_head_start = '\n    <th>'
col_start = '\n    <td>'
escape(value)[source]

escape value

head_end = '\n  </tr>'
head_start = "\n  <tr class='heading'>"
row_end = '\n  </tr>'
row_start = '\n  <tr>'
sep_line = None
table_end = '\n</table>'
table_start = '\n<table>'
class fspath.sui.SimpleUserInterface(cli=None)[source]

Bases: object

Simple console based user interface (win & *nix)

NO = False
YES = True
classmethod ask(msg, default=None, count=None, echo=True, valid_chars='.', stop_char='\r')[source]

Ask via UI

classmethod ask_choice(msg, choices, default=0)[source]

Take a choice from a list via UI

classmethod ask_fspath(msg='enter path name: ', default=None)[source]

Ask for path name with [TAB] completion

classmethod ask_yes_no(msg, default='y')[source]

Ask Yes/No [YN] via UI

Returns True for Yes and False for No

classmethod echo(msg)[source]

write line to UI

classmethod fill_line(fill_char=' ')[source]

console, fill line with fill_char (default ‘ ‘)

classmethod get_input(count=None, echo=True, valid_chars='.', stop_char='\r')[source]

read input from UI

classmethod getchr()[source]

Get a single unicode character on Linux & Unix.

classmethod readkey()[source]

read keystroke

rst_indent = '    '
rst_levels = {'chapter': '=', 'part': '=', 'section': '-', 'subsection': '~'}
classmethod rst_p(text, level=0)[source]

write reST formated paragraph to UI

Parameters:

level (int) – indentaion level

classmethod rst_table(rows, *fmt, **kwargs)[source]

write reST formated table to UI

Uses ASCIITableFormatter for output. The argument *fmt is a list of tuple.

Parameters:
  • rows (list) – iterable type of dictionaries with the col/value

  • *fmt (list) – iterable type of tuples to format the table

  • level (int) – indentaion level

SUI.rst_table(
    test_rows
    # <col-title>, <format sting>, <attribute name>
    , ("Foo",      "%-12s",        "foo")
    , ("Bar",      "%-30s",        "bar"))
classmethod rst_title(title, level='chapter')[source]

write reST formated title to UI

Parameters:
  • title (str) – section’s title

  • level (str) – section’s structural level [part,chapter,section,subsection]

termios = <module 'termios' from '/usr/lib/python3.8/lib-dynload/termios.cpython-38-x86_64-linux-gnu.so'>
tty = <module 'tty' from '/usr/lib/python3.8/tty.py'>
ui_in = <_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>
ui_out = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
classmethod wait_key()[source]

wait until key pressed

classmethod write(msg)[source]

write to UI