TIMEOUT_CONNECT = 5
TIMEOUT_LOOP = 0.1
CONN_RECV_BUFSIZE = 1024
-INPUT_PROMPT = '> '
KEYBINDINGS = {
'KEY_BACKSPACE': ('window.prompt.backspace',),
class PromptWidget(ScrollableWidget):
'Keyboard-controlled command input field.'
- _start_y: int
+ _y: int
+ _width: int
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self._history_idx = 0
def set_geometry(self, measurements: YX) -> None:
- self._start_y = measurements[0]
+ self._y, self._width = measurements
def append(self, to_append: str) -> None:
self._input_buffer += to_append
self.draw()
def draw(self) -> None:
- self._write_yx(YX(self._start_y, 0),
- f'{INPUT_PROMPT} {self._input_buffer}_')
+ cursor = '_'
+ prompt_template = '> '
+ prompt = f'{prompt_template}'
+ offset = 0
+ while True:
+ to_write = f'{prompt}{self._input_buffer[offset:]}{cursor}'
+ len_too_much = len(to_write) - self._width
+ if len_too_much <= 0:
+ break
+ offset += len_too_much
+ prompt = f'<{offset}|{prompt_template}…'
+ self._write_yx(YX(self._y, 0), to_write)
def _scroll(self, up: bool = True) -> None:
if up and -(self._history_idx) < len(self._history):