aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-09-15 01:39:23 -0400
committerJesse Luehrs <doy@tozt.net>2014-09-15 01:44:51 -0400
commit070da900a4bdda26ee4ee00ad6e3d9fcb6aa262a (patch)
tree9e2e19f22bf4c0690521222cb453ec058bfd7c46
parentf5c3448d15e1e9e1f51d4c9f2b0d1b8a4e0e4b10 (diff)
downloadpython-termcast-server-070da900a4bdda26ee4ee00ad6e3d9fcb6aa262a.tar.gz
python-termcast-server-070da900a4bdda26ee4ee00ad6e3d9fcb6aa262a.zip
start working on a watcher menu for the ssh side
-rw-r--r--ssh.py34
-rw-r--r--termcast.py9
2 files changed, 32 insertions, 11 deletions
diff --git a/ssh.py b/ssh.py
index 35a1595..5e88834 100644
--- a/ssh.py
+++ b/ssh.py
@@ -1,15 +1,6 @@
import paramiko
import time
-class Handler(object):
- def __init__(self, sock, connections):
- self.sock = sock
- self.connections = connections
- self.which
-
- def show(self):
- pass
-
class Connection(object):
def __init__(self, client, connection_id, publisher):
self.transport = paramiko.Transport(client)
@@ -22,9 +13,11 @@ class Connection(object):
self.transport.start_server(server=Server())
self.chan = self.transport.accept(None)
+ self.watching_id = self.select_stream()
+
# XXX need to have the user select a stream, and then pass the stream's
# id in here
- self.publisher.notify("new_viewer", "some-stream")
+ self.publisher.notify("new_viewer", self.watching_id)
while True:
c = self.chan.recv(1)
@@ -32,6 +25,27 @@ class Connection(object):
break
self.chan.close()
+ def select_stream(self):
+ self.chan.send("\033[2J\033[HTermcast")
+ row = 3
+ key_code = ord('a')
+ keymap = {}
+ for streamer in self.publisher.request_all("get_streamers"):
+ key = chr(key_code)
+ keymap[key] = streamer["id"]
+ self.chan.send("\033[%dH%s) %s" % (row, key, streamer["name"].decode('utf-8')))
+ row += 1
+ key_code += 1
+
+ self.chan.send("\033[%dHChoose a stream: " % (row + 1))
+
+ c = self.chan.recv(1).decode('utf-8')
+ if c in keymap:
+ self.chan.send("\033[2J\033[H")
+ return keymap[c]
+ else:
+ return self.select_stream()
+
def msg_new_data(self, connection_id, prev_buf, data):
# XXX uncomment this once we implement stream selection
# if self.watching_id != connection_id:
diff --git a/termcast.py b/termcast.py
index c1d8a5e..c5495cf 100644
--- a/termcast.py
+++ b/termcast.py
@@ -52,7 +52,8 @@ class Connection(object):
return
print(b"got auth: " + auth)
- self.client.send(b"hello, " + m.group(1) + b"\n")
+ self.name = m.group(1)
+ self.client.send(b"hello, " + self.name + b"\n")
extra_data = {}
extra_data_re = re.compile(b'^\033\[H\000([^\377]*)\377\033\[H\033\[2J(.*)$')
@@ -81,3 +82,9 @@ class Connection(object):
# if connection_id != self.connection_id:
# return
self.publisher.notify("new_data", self.connection_id, self.handler.buf, b'')
+
+ def request_get_streamers(self):
+ return {
+ "name": self.name,
+ "id": self.connection_id,
+ }