class _HistoryWidget(_ScrollableWidget):
_last_read: int = 0
+ _bookmark: int = 0
_y_pgscroll: int
def __init__(self, wrap: Callable[[str], list[str]], **kwargs) -> None:
def _draw(self) -> None:
start_idx = self._wrapped_idx - self._sizes.y + 1
end_idx = self._wrapped_idx
- to_write = [t[1] for t in self._wrapped[start_idx:end_idx]]
+ idx_bookmark = ([idx for idx, t in enumerate(self._wrapped)
+ if t[0] == self._bookmark]+[0])[0]
+ wrapped = (self._wrapped[:idx_bookmark+1]
+ + [(0, '-'*self._sizes.x)]
+ + self._wrapped[idx_bookmark+1:])
+ to_write = [t[1] for t in wrapped[start_idx:end_idx]]
if self._wrapped_idx < -1:
scroll_info = f'vvv [{(-1) * self._wrapped_idx}] '
scroll_info += 'v' * (self._sizes.x - len(scroll_info))
to_write += [scroll_info]
else:
- to_write += [self._wrapped[self._wrapped_idx][1]]
+ to_write += [wrapped[self._wrapped_idx][1]]
for i, line in enumerate(to_write):
self._write(line, i)
- self._last_read = len(self._history)
+ hist_idx = self._wrapped[end_idx][0]
+ self._last_read = max(self._last_read, hist_idx or 0)
+
+ def bookmark(self) -> None:
+ 'Store to what most recent line we have (been) scrolled.'
+ self._bookmark = self._last_read
@property
def n_lines_unread(self) -> int:
'How many new lines have been logged since last focus.'
- return len(self._history) - self._last_read
+ return len(self._history) - self._last_read - 1
def _scroll(self, up: bool = True) -> None:
super()._scroll(up)
def _switch_window(self, idx: int) -> None:
self.window.taint()
+ self.window.history.bookmark()
self._status_line.idx_focus = self._window_idx = idx
self._status_line.taint()