diff options
author | Jesse Luehrs <doy@tozt.net> | 2014-09-17 12:18:25 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2014-09-17 12:18:25 -0400 |
commit | 92ba955c9cb5836c21d15537f9cccc91a999bc53 (patch) | |
tree | 06d543f0b46b6c96dbf15cb44e041049497a44bf /ssh.py | |
parent | f625d280190fadc57feea6933b65076cc7ef9745 (diff) | |
download | python-termcast-server-92ba955c9cb5836c21d15537f9cccc91a999bc53.tar.gz python-termcast-server-92ba955c9cb5836c21d15537f9cccc91a999bc53.zip |
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.
Diffstat (limited to 'ssh.py')
-rw-r--r-- | ssh.py | 23 |
1 files changed, 17 insertions, 6 deletions
@@ -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" |