wasp_general.cli package

Submodules

wasp_general.cli.cli module

class wasp_general.cli.cli.WConsoleBase(command_set=None)[source]

Bases: wasp_general.cli.cli.WConsoleProto

command_set()[source]
exec(row)[source]
fin_session()[source]

WConsoleProto.fin_session() implementation. Commits current input row

Returns:None
handle_exception(e)[source]
handle_result(result)[source]
prompt()[source]

WConsoleProto.prompt() implementation

refresh_window()[source]

Shortcut for self.window().refresh() call

Returns:None
start_session()[source]

WConsoleProto.start_session() implementation. Sets cursor to 0 position before session

Returns:None
truncate(length)[source]

Shortcut for self.window().truncate_feedback(result) call

Parameters:length – same as length in WConsoleWindowProto.truncate_feedback()
Returns:None
window()[source]
write(result, cr=True)[source]

Shortcut for self.window().write_feedback(result) call

Parameters:
Returns:

None

class wasp_general.cli.cli.WConsoleDrawerProto[source]

Bases: object

Basic class that helps displaying console content

draw(window, prompt_show=True)[source]

Display console content on console window

Parameters:
Returns:

None

suitable(window, prompt_show=True)[source]

Check if this class can display console content

Parameters:
Returns:

bool (True if this class can draw console content, False - if it can not)

class wasp_general.cli.cli.WConsoleHistory[source]

Bases: object

Simple console history implementation

add(value)[source]

Add new record to history. Record will be added to the end

Parameters:value – new record
Returns:int record position in history
entry(position)[source]

Get record from history by record position

Parameters:position – record position
Returns:str
position(pos=None)[source]

Get current and/or set history cursor position

Parameters:pos – if value is not None, then current position is set to pos and new value is returned
Returns:int or None (if position have never been changed)
size()[source]

Returns history entries count

Returns:int
update(value, position)[source]

Change record in this history

Parameters:
  • value – new record to save
  • position – record position to change
Returns:

None

class wasp_general.cli.cli.WConsoleProto[source]

Bases: object

Basic class for console implementation. It has non-changeable and changeable history (WConsoleHistory). One stores previous entered rows, other one helps to entered new row by editing previous one.

exec(row)[source]

Must execute given command

Parameters:row – command to execute
Returns:None
fin_session()[source]

Finalize current session

Returns:None
history()[source]

Return changeable history

Returns:WConsoleHistory or None
history_mode(mode_value=None)[source]

Get and/or set current history mode.

History mode defines what row will be changed with WConsoleProto.update_row() or can be got by WConsoleProto.row() call. If history mode disabled, then WConsoleProto.update_row() and WConsoleProto.row() affects current row prompt. If history mode is enabled, then WConsoleProto.update_row() and WConsoleProto.row() affects current entry in history WConsoleHistory (entry at WConsoleHistory.position())

History mode is turned off by default.

Parameters:mode_value – True value enables history mode. False - disables. None - do nothing
Returns:bool
prompt()[source]

Return prompt, that would be printed before row. Prompt length must be the same within every session

Returns:str
prompt_show()[source]

Return flag, that shows, whether to display prompt and current command at the window end, or not

Returns:bool
refresh_window()[source]

Refresh current screen. Simple clear and redraw should work

Returns:None
row()[source]

Get row

Returns:str
start_session()[source]

Start new session and prepare environment for new row editing process

Returns:None
update_row(value)[source]

Change row

Parameters:value – new row
Returns:None
class wasp_general.cli.cli.WConsoleWindowBase(console, *drawers)[source]

Bases: wasp_general.cli.cli.WConsoleWindowProto

Basic class for console window implementation

refresh(prompt_show=True)[source]

Refresh current window. Clear current window and redraw it with one of drawers

Parameters:prompt_show – flag, that specifies, whether to show prompt and current row at the

windows end, or not

Returns:None
class wasp_general.cli.cli.WConsoleWindowProto(console)[source]

Bases: object

Basic class for console window implementation

clear()[source]

Clear window and remove every symbol it has

Returns:None
commit()[source]

Store current input row. Keep current input row as previous output

Returns:None
console()[source]

Return linked console

Returns:WConsoleProto
cursor(pos=None)[source]

Set and/or get relative cursor position. Defines cursor position in current input row.

Parameters:pos – if value is not None, then current cursor position is set to this value and the same value is returned
Returns:int
data(previous_data=False, prompt=False, console_row=False, console_row_to_cursor=False, console_row_from_cursor=False)[source]

Return output data. Flags specifies what data to append. If no flags was specified nul-length string returned

Parameters:
  • previous_data – If True, then previous output appends
  • prompt – If True, then console prompt appends. If console_row or console_row_to_cursor is True, then this value is omitted
  • console_row – If True, then console prompt and current input appends.
  • console_row_to_cursor – If True, then console prompt and current input till cursor appends. If console_row is True, then this value is omitted
  • console_row_from_cursor – If True, then current input from cursor appends. If console_row is True, then this value is omitted
Returns:

str

height()[source]

Get window height. If windows height was changed - window must be refreshed via WConsoleWindowProto.refresh()

Returns:int
list_data(previous_data=False, prompt=False, console_row=False, console_row_to_cursor=False, console_row_from_cursor=False)[source]

Return list of strings. Where each string is fitted to windows width. Parameters are the same as they are in WConsoleWindow.data() method

Returns:list of str
refresh(prompt_show=True)[source]

Refresh current window. Clear current window and redraw it with one of drawers

Parameters:prompt_show – flag, that specifies, whether to show prompt and current row at the

windows end, or not

Returns:None
set_cursor(y, x)[source]

Set input cursor in window to specified coordinates. 0, 0 - is top left coordinates

Parameters:
  • y – vertical coordinates, 0 - top, bottom - positive value
  • x – horizontal coordinates, 0 - left, right - positive value
Returns:

split(data)[source]

Split data into list of string, each (self.width() - 1) length or less. If nul-length string specified then empty list is returned

Parameters:data – data to split
Returns:list of str
truncate_feedback(length)[source]

Remove data from feedback (removes text from previous output)

Parameters:length – string length to remove (including required cr-characters)
Returns:None
width()[source]

Get window width. If windows width was changed - window must be refreshed via WConsoleWindowProto.refresh()

Returns:int
write_data(data, start_position=0)[source]

Write data from the specified line

Parameters:
  • data – string to write, each one on new line
  • start_position – starting line
Returns:

write_feedback(feedback, cr=True)[source]

Store feedback. Keep specified feedback as previous output

Parameters:
  • feedback – data to store
  • cr – whether to write carriage return to the end or not
Returns:

None

write_line(line_index, line)[source]

Write string on specified line

Parameters:
  • line_index – line index to display
  • line – string to display (must fit windows width)
Returns:

wasp_general.cli.curses module

class wasp_general.cli.curses.WCursesConsole(command_set=None)[source]

Bases: wasp_general.cli.cli.WConsoleBase

screen()[source]
start()[source]
stop()[source]
window()[source]
class wasp_general.cli.curses.WCursesKeyAction(key)[source]

Bases: object

action(console_meta)[source]
class wasp_general.cli.curses.WCursesKeyBackspace[source]

Bases: wasp_general.cli.curses.WCursesKeyAction

action(console_meta)[source]
class wasp_general.cli.curses.WCursesKeyDelete[source]

Bases: wasp_general.cli.curses.WCursesKeyAction

action(console_meta)[source]
class wasp_general.cli.curses.WCursesKeyDown[source]

Bases: wasp_general.cli.curses.WCursesKeyAction

action(console_meta)[source]
class wasp_general.cli.curses.WCursesKeyLeft[source]

Bases: wasp_general.cli.curses.WCursesKeyAction

action(console_meta)[source]
class wasp_general.cli.curses.WCursesKeyResize[source]

Bases: wasp_general.cli.curses.WCursesKeyAction

action(console_meta)[source]
class wasp_general.cli.curses.WCursesKeyRight[source]

Bases: wasp_general.cli.curses.WCursesKeyAction

action(console_meta)[source]
class wasp_general.cli.curses.WCursesKeyUp[source]

Bases: wasp_general.cli.curses.WCursesKeyAction

action(console_meta)[source]
class wasp_general.cli.curses.WCursesWindow(console)[source]

Bases: wasp_general.cli.cli.WConsoleWindowBase

class BigWindowDrawer[source]

Bases: wasp_general.cli.cli.WConsoleDrawerProto

WConsoleWindowProto.DrawerProto implementation. Suites if content and even current row doesn’t fit window width and height

draw(window, prompt_show=True)[source]

WConsoleWindowProto.DrawerProto.draw() method implementation

suitable(window, prompt_show=True)[source]

WConsoleWindowProto.DrawerProto.suitable() method implementation

class EmptyWindowDrawer[source]

Bases: wasp_general.cli.cli.WConsoleDrawerProto

WConsoleWindowProto.DrawerProto implementation. Suites if there is nothing to display

draw(window, prompt_show=True)[source]

WConsoleWindowProto.DrawerProto.draw() method implementation

suitable(window, prompt_show=True)[source]

WConsoleWindowProto.DrawerProto.suitable() method implementation

class ScrolledWindowDrawer[source]

Bases: wasp_general.cli.cli.WConsoleDrawerProto

WConsoleWindowProto.DrawerProto implementation. Suites if content doesn’t fit window width and height but current row fits

draw(window, prompt_show=True)[source]

WConsoleWindowProto.DrawerProto.draw() method implementation

suitable(window, prompt_show=True)[source]

WConsoleWindowProto.DrawerProto.suitable() method implementation

class SmallWindowDrawer[source]

Bases: wasp_general.cli.cli.WConsoleDrawerProto

WConsoleWindowProto.DrawerProto implementation. Suites if there is content and content fits window width and height

draw(window, prompt_show=True)[source]

WConsoleWindowProto.DrawerProto.draw() method implementation

suitable(window, prompt_show=True)[source]

WConsoleWindowProto.DrawerProto.suitable() method implementation

clear()[source]
height()[source]
refresh(prompt_show=True)[source]
set_cursor(y, x)[source]
width()[source]
write_line(line_index, line)[source]

wasp_general.cli.curses_commands module

class wasp_general.cli.curses_commands.WEmptyCommand(*command_tokens)[source]

Bases: wasp_general.command.command.WCommand

match(*command_tokens, **command_env)[source]
class wasp_general.cli.curses_commands.WExitCommand(console)[source]

Bases: wasp_general.command.command.WCommand

console()[source]
match(*command_tokens, **command_env)[source]

wasp_general.cli.formatter module

class wasp_general.cli.formatter.WConsoleTableFormatter(*table_headers)[source]

Bases: object

add_row(*cells)[source]
static cells_length(*cells)[source]
format(delimiter=None)[source]
wasp_general.cli.formatter.data_size_formatter(size)[source]
wasp_general.cli.formatter.local_datetime_formatter(dt)[source]
wasp_general.cli.formatter.na_formatter(value, str_fn=None, none_value=None)[source]

Module contents