From d9e323fd4f7ee4cae48bd786f94dd3ca6e2a800b Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Sun, 15 Mar 2020 19:58:10 +0100 Subject: Following (automatic scrolling) --- rcon.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/rcon.py b/rcon.py index 3df49ab..0185f12 100644 --- a/rcon.py +++ b/rcon.py @@ -20,12 +20,24 @@ class JournalViewer: self.root = self.list_box self.proc = None + self.following = True + + # FIXME: call this whenever the user scrolls through the log + def update(self): + lc = len(self.list_walker) + + if self.following: + self.list_box.set_focus(lc - 1) + + self.status.set_text("%d/%d line%s, [F]ollow: %s" % ( + self.list_box.focus_position + 1, + lc, "" if lc == 1 else "s", + "on" if self.following else "off")) + def write(self, text): for line in str(text).split("\n"): self.list_walker.append(urwid.Text(line)) - - lc = len(self.list_walker) - self.status.set_text("%d line%s" % (lc, "" if lc == 1 else "s")) + self.update() def proc_open(self, argv): if self.proc is not None: @@ -129,6 +141,9 @@ class Console: command = self.edit.get_edit_text() self.edit.set_edit_text("") self.execute(command) + elif text == "f": + self.viewer.following = not self.viewer.following + self.viewer.update() def select_server(self, server): self.server = server -- cgit