From 92ba955c9cb5836c21d15537f9cccc91a999bc53 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 17 Sep 2014 12:18:25 -0400 Subject: enforce terminal size better when watching set the scroll region to the size of the terminal you're watching when you first start watching a stream. this typically happens automatically when watching someone who opens and closes something like vim (since resetting the scroll region means explicitly setting the scroll region to the size of the whole terminal, which will be the size of the watching terminal in this case), but this helps for when a stream first starts broadcasting. also be sure to reset it when you stop watching. --- ssh.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/ssh.py b/ssh.py index f82a76d..23d84dd 100644 --- a/ssh.py +++ b/ssh.py @@ -32,18 +32,29 @@ class Connection(object): self.initialized = False self.watching_id = None - self.watching_id = self.select_stream() - if self.watching_id is None: + streamer = self.select_stream() + if streamer is None: break + self.watching_id = streamer["id"] - print("new viewer watching " + self.watching_id) + print("new viewer watching %s (%s)" % (streamer["name"], streamer["id"])) + self.chan.send( + "\033[1;%d;1;%dr\033[m\033[H\033[2J" % ( + streamer["rows"], streamer["cols"] + ) + ) self.publisher.notify("new_viewer", self.watching_id) while True: c = self.chan.recv(1) if c == b'q': - print("viewer stopped watching " + self.watching_id) + print("viewer stopped watching %s (%s)" % (streamer["name"], streamer["id"])) self.publisher.notify("viewer_disconnect", self.watching_id) + self.chan.send( + "\033[1;%d;1;%dr\033[m\033[H\033[2J" % ( + self.server.rows, self.server.cols + ) + ) break self.chan.close() @@ -59,7 +70,7 @@ class Connection(object): key_code += 1 key = chr(key_code) streamer["key"] = key - keymap[key] = streamer["id"] + keymap[key] = streamer key_code += 1 self._display_streamer_screen(streamers) @@ -85,7 +96,7 @@ class Connection(object): self.chan.send(data) def _display_streamer_screen(self, streamers): - self.chan.send("\033[2J\033[H\033[mWelcome to Termcast!") + self.chan.send("\033[H\033[2JWelcome to Termcast!") self.chan.send( "\033[3H %-20s %-15s %-15s %-15s" % ( "User", "Terminal size", "Idle time", "Total time" -- cgit v1.2.3-54-g00ecf