def _render(self, highlight_color: VtColors, nav_color: VtColors) -> None: """TODO""" length = len(self.items) dummy, columns = screen_size() restore_cursor() for idx in range(self.show_from, self.show_to): selector = self.UNSELECTED if idx < length: # When the number of items is lower than the max_rows, skip the other lines option_line = str(self.items[idx])[0:int(columns)] vt_print('%EL2%\r') # Erase current line before repaint # Print the selector if the index is currently selected if idx == self.sel_index: vt_print(highlight_color.code()) selector = self.SELECTED fmt = " {:>" + str(len( str(length))) + "}{:>" + str(1 + len(str(selector))) + "} {}" sysout(fmt.format(idx + 1, selector, option_line)) # Check if the text fits the screen and print it, otherwise print '...' if len(option_line) >= int(columns): sysout("%CUB(4)%%EL0%...%NC%", end='') else: break sysout(self.NAV_FMT.format(nav_color.placeholder(), self.NAV_ICONS, str(length)), end='') self.re_render = False
def restore_terminal(clear_screen: bool = True): """Clear terminal and restore default attributes""" if clear_screen: vt_print('%HOM%%ED2%%MOD(0)%') set_auto_wrap() set_show_cursor() set_enable_echo() sysout('%NC%')
def mi_print(size: int = 0, text: str = None, prepend: str = None, end: str = '') -> None: fmt = ('{}' if prepend else '') + "{:<" + str(size) + "} : " if prepend: vt_print(fmt.format(prepend, text), end=end) else: vt_print(fmt.format(text or ''), end=end)
def _print_cell(self, idx: int, item: DashboardItem, cell_template: List[List[str]]) -> None: """TODO""" num_cols, num_rows = len(cell_template[0]), len(cell_template) for row in range(0, num_rows): for col in range(0, num_cols): vt_print( f'{item.icon if cell_template[row][col] == self.ICN else cell_template[row][col]}' ) vt_print(f'%CUD(1)%%CUB({num_cols})%') if idx > 0 and (idx + 1) % self.items_per_line == 0: vt_print(f'%CUD(1)%%CUB({num_cols * self.items_per_line})%' ) # Break the line elif idx + 1 < len(self.items): vt_print(f'%CUU({num_rows})%%CUF({num_cols})%' ) # Continue with the same line
def restore_cursor(): """Restore cursor position and attributes""" vt_print(Vt100.restore_cursor())
def save_cursor(): """Save cursor position and attributes""" vt_print(Vt100.save_cursor())
def set_show_cursor(show_cursor: bool = True): """Show or hide cursor in the terminal :param show_cursor: whether to show or hide he cursor """ vt_print(Vt100.set_show_cursor(show_cursor))
def set_auto_wrap(auto_wrap: bool = True) -> None: """Set auto-wrap mode in the terminal :param auto_wrap: whether auto_wrap is set or not """ vt_print(Vt100.set_auto_wrap(auto_wrap))
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ TODO Purpose of the file @project: HSPyLib hspylib.demo.cli.vt100 @file: vt100_demo.py @created: Tue, 4 May 2021 @author: <B>H</B>ugo <B>S</B>aporetti <B>J</B>unior" @site: https://github.com/yorevs/hspylib @license: MIT - Please refer to <https://opensource.org/licenses/MIT> Copyright 2021, HSPyLib team """ from hspylib.modules.cli.vt100.vt_codes import vt_print if __name__ == '__main__': vt_print('%CSV%') vt_print('%MOD(1;35)%HUGO%MOD(0)%\n') vt_print('%MOD(1;33)%HUGO%MOD(0)%\n') vt_print('%CUU(2)%') vt_print('%MOD(1;36)%GE%MOD(0)%\n') vt_print('%USC%HIDDEN_TEXT\n') vt_print('%SSC%VISIBLE_TEXT\n') vt_print('%CRE%') vt_print('Done')