From 1165fa4ec941bfc0ecedfb2c875663bbaa1aa0c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Tue, 6 Mar 2018 16:15:04 +0100 Subject: [PATCH] Refactor pty resetting logic to TerminadoMiniServer --- lib/tfw/components/terminado_event_handler.py | 7 +------ lib/tfw/components/terminado_mini_server.py | 8 ++++++-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/tfw/components/terminado_event_handler.py b/lib/tfw/components/terminado_event_handler.py index 0eb423d..756d4db 100644 --- a/lib/tfw/components/terminado_event_handler.py +++ b/lib/tfw/components/terminado_event_handler.py @@ -13,8 +13,7 @@ class TerminadoEventHandler(TriggerlessEventHandler): self._historymonitor = HistoryMonitor(tfwenv.HISTFILE) self.terminado_server = TerminadoMiniServer('/terminal', tfwenv.TERMINADO_PORT, tfwenv.TERMINADO_WD, ['bash']) self.commands = {'write': self.write, - 'read': self.read, - 'resetshell': self.resetshell} + 'read': self.read} self._historymonitor.watch() self.terminado_server.listen() @@ -36,9 +35,5 @@ class TerminadoEventHandler(TriggerlessEventHandler): data['history'] = self.historymonitor.history[-data['count']:] return data - def resetshell(self, data): - self.terminado_server.term_manager.terminal = None - self.terminado_server.term_manager.get_terminal() - def cleanup(self): self.historymonitor.stop() diff --git a/lib/tfw/components/terminado_mini_server.py b/lib/tfw/components/terminado_mini_server.py index 691099a..153a382 100644 --- a/lib/tfw/components/terminado_mini_server.py +++ b/lib/tfw/components/terminado_mini_server.py @@ -15,7 +15,7 @@ class TerminadoMiniServer: self.application = Application( [( url, - TerminadoMiniServer.CORSTermSocket, + TerminadoMiniServer.ResetterTermSocket, {'term_manager': self._term_manager} )] ) @@ -28,10 +28,14 @@ class TerminadoMiniServer: def pty(self): return self.term_manager.terminal.ptyproc - class CORSTermSocket(TermSocket): + class ResetterTermSocket(TermSocket): def check_origin(self, origin): return True + def on_close(self): + self.term_manager.terminal = None + self.term_manager.get_terminal() + def listen(self): self.application.listen(self.port)