From: Christian Heller Date: Sat, 7 Jun 2025 16:40:31 +0000 (+0200) Subject: In input prompt show only what fits into window width, inform about cutoff. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/static/%22https:/validator.w3.org/todo?a=commitdiff_plain;p=ircplom In input prompt show only what fits into window width, inform about cutoff. --- diff --git a/ircplom.py b/ircplom.py index b754b82..1ca94fd 100755 --- a/ircplom.py +++ b/ircplom.py @@ -18,7 +18,6 @@ PORT = 6667 TIMEOUT_CONNECT = 5 TIMEOUT_LOOP = 0.1 CONN_RECV_BUFSIZE = 1024 -INPUT_PROMPT = '> ' KEYBINDINGS = { 'KEY_BACKSPACE': ('window.prompt.backspace',), @@ -444,7 +443,8 @@ class ScrollableWidget(Widget): 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) @@ -452,7 +452,7 @@ class PromptWidget(ScrollableWidget): 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 @@ -460,8 +460,18 @@ class PromptWidget(ScrollableWidget): 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):