self._write = write
self._history: list[str] = []
- @abstractmethod
def append(self, to_append: str) -> None:
- 'Append to widget content.'
+ 'Append to scrollable history.'
+ self._history += [to_append]
@abstractmethod
def _scroll(self, up=True) -> None:
self._wrapped_idx = idx_their_last - len(self._wrapped)
def append(self, to_append: str) -> None:
- self._history += [to_append]
+ super().append(to_append)
n_wrapped_lines = self._add_wrapped(len(self._history) - 1, to_append)
if self._wrapped_idx < -1:
self._history_idx -= 1
def set_geometry(self, measurements: _YX) -> None:
self._y, self._width = measurements
- def append(self, to_append: str) -> None:
- self._cursor_x += len(to_append)
- self._input_buffer = (self._input_buffer[:self._cursor_x - 1]
- + to_append
- + self._input_buffer[self._cursor_x - 1:])
- self._history_idx = 0
- self.draw()
-
def draw(self) -> None:
prefix = self._prompt[:]
content = self._input_buffer[:]
padding=False)
self._write(to_write[cursor_x_to_write + 1:])
+ def _archive_prompt(self) -> None:
+ self.append(self._input_buffer[:])
+ self._reset_buffer('')
+
def _scroll(self, up: bool = True) -> None:
if up and -(self._history_idx) < len(self._history):
if self._history_idx == 0 and self._input_buffer:
- self._history += [self._input_buffer[:]]
- self._reset_buffer('')
+ self._archive_prompt()
self._history_idx -= 1
self._history_idx -= 1
self._reset_buffer(self._history[self._history_idx])
else:
self._reset_buffer(self._history[self._history_idx])
elif self._input_buffer:
- self._history += [self._input_buffer[:]]
- self._reset_buffer('')
+ self._archive_prompt()
def cmd__append(self, to_append: str) -> None:
'Append to prompt input buffer.'
- self.append(to_append)
+ self._cursor_x += len(to_append)
+ self._input_buffer = (self._input_buffer[:self._cursor_x - 1]
+ + to_append
+ + self._input_buffer[self._cursor_x - 1:])
+ self._history_idx = 0
+ self.draw()
def cmd__backspace(self) -> None:
'Truncate current content by one character, if possible.'
'Return current content while also clearing and then redrawing.'
to_return = self._input_buffer[:]
if to_return:
- self._history += [to_return]
- self._reset_buffer('')
+ self._archive_prompt()
self.draw()
return to_return