From 4873bbf421b1ad7a08997cc5013f88d884b67e59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Sat, 3 Mar 2018 14:14:44 +0100 Subject: [PATCH] Implement simple pty writing API --- lib/tfw/components/terminado_event_handler.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/tfw/components/terminado_event_handler.py b/lib/tfw/components/terminado_event_handler.py index cb29e4e..00a90c9 100644 --- a/lib/tfw/components/terminado_event_handler.py +++ b/lib/tfw/components/terminado_event_handler.py @@ -10,9 +10,13 @@ class TerminadoEventHandler(TriggerlessEventHandler): super().__init__(key) self.working_directory = tfwenv.TERMINADO_DIR self.terminado_server = TerminadoMiniServer('/terminal', tfwenv.TERMINADO_PORT, tfwenv.TERMINADO_WD, ['bash']) + self.commands = {'write': self.write} self.terminado_server.listen() def handle_event(self, key, data_json): - log.debug('TerminadoEventHandler received event for key {}'.format(key)) - self.terminado_server.pty.write('echo cica\n') - # TODO: design & implement pty.write API + log.debug('TerminadoEventHandler received event: {}'.format(data_json)) + data = data_json['data'] + self.commands[data['command']](data) + + def write(self, data): + self.terminado_server.pty.write(data['shellcmd'])