From: Christian Heller Date: Mon, 29 Sep 2025 02:10:40 +0000 (+0200) Subject: Add log bookmarking. X-Git-Url: https://plomlompom.com/repos/?a=commitdiff_plain;h=64b6bba4452a3b624f39da50274d2d7ceb05637a;p=ircplom Add log bookmarking. --- diff --git a/src/ircplom/tui_base.py b/src/ircplom/tui_base.py index ad54537..2ef81c7 100644 --- a/src/ircplom/tui_base.py +++ b/src/ircplom/tui_base.py @@ -106,6 +106,7 @@ class _ScrollableWidget(_Widget): class _HistoryWidget(_ScrollableWidget): _last_read: int = 0 + _bookmark: int = 0 _y_pgscroll: int def __init__(self, wrap: Callable[[str], list[str]], **kwargs) -> None: @@ -149,21 +150,31 @@ class _HistoryWidget(_ScrollableWidget): 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) @@ -498,6 +509,7 @@ class BaseTui(QueueMixin): 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()