def draw_frame(canvas: curses.window, start_row: int, start_column: int, text: str, negative: bool = False): """Draw multiline text fragment on canvas. Erase text instead of drawing if negative=True is specified.""" rows_number, columns_number = canvas.getmaxyx() for row, line in enumerate(text.splitlines(), round(start_row)): if row < 0: continue if row >= rows_number: break for column, symbol in enumerate(line, round(start_column)): if column < 0: continue if column >= columns_number: break if symbol == " ": continue # Check that current position it is not in a lower right corner of the window # Curses will raise exception in that case. Don`t ask why… # https://docs.python.org/3/library/curses.html#curses.window.addch if row == rows_number - 1 and column == columns_number - 1: continue symbol = symbol if not negative else " " canvas.addch(row, column, symbol)
def input_str(y, x, scr: c.window, max_len=0, prompt=''): res = '' len_count = 0 if prompt: scr.addstr(y, x, prompt) if max_len > 0: scr.addstr(y + int(bool(prompt)), x, '_' * max_len) while True: char = scr.get_wch() if char == '\n': break elif char in ('\b', '\x7f'): if len_count > 0: res = res[:-1] scr.addch(y + int(bool(prompt)), x + len_count - 1, '_') scr.refresh() len_count -= 1 elif len(char) == 1: res += char scr.addch(y + int(bool(prompt)), x + len_count, char) scr.refresh() len_count += 1 if 0 < max_len <= len_count: break return res