Refactor pty resetting logic to TerminadoMiniServer

This commit is contained in:
Kristóf Tóth 2018-03-06 16:15:04 +01:00
parent e20a5dab23
commit 1165fa4ec9
2 changed files with 7 additions and 8 deletions

View File

@ -13,8 +13,7 @@ class TerminadoEventHandler(TriggerlessEventHandler):
self._historymonitor = HistoryMonitor(tfwenv.HISTFILE) self._historymonitor = HistoryMonitor(tfwenv.HISTFILE)
self.terminado_server = TerminadoMiniServer('/terminal', tfwenv.TERMINADO_PORT, tfwenv.TERMINADO_WD, ['bash']) self.terminado_server = TerminadoMiniServer('/terminal', tfwenv.TERMINADO_PORT, tfwenv.TERMINADO_WD, ['bash'])
self.commands = {'write': self.write, self.commands = {'write': self.write,
'read': self.read, 'read': self.read}
'resetshell': self.resetshell}
self._historymonitor.watch() self._historymonitor.watch()
self.terminado_server.listen() self.terminado_server.listen()
@ -36,9 +35,5 @@ class TerminadoEventHandler(TriggerlessEventHandler):
data['history'] = self.historymonitor.history[-data['count']:] data['history'] = self.historymonitor.history[-data['count']:]
return data return data
def resetshell(self, data):
self.terminado_server.term_manager.terminal = None
self.terminado_server.term_manager.get_terminal()
def cleanup(self): def cleanup(self):
self.historymonitor.stop() self.historymonitor.stop()

View File

@ -15,7 +15,7 @@ class TerminadoMiniServer:
self.application = Application( self.application = Application(
[( [(
url, url,
TerminadoMiniServer.CORSTermSocket, TerminadoMiniServer.ResetterTermSocket,
{'term_manager': self._term_manager} {'term_manager': self._term_manager}
)] )]
) )
@ -28,10 +28,14 @@ class TerminadoMiniServer:
def pty(self): def pty(self):
return self.term_manager.terminal.ptyproc return self.term_manager.terminal.ptyproc
class CORSTermSocket(TermSocket): class ResetterTermSocket(TermSocket):
def check_origin(self, origin): def check_origin(self, origin):
return True return True
def on_close(self):
self.term_manager.terminal = None
self.term_manager.get_terminal()
def listen(self): def listen(self):
self.application.listen(self.port) self.application.listen(self.port)