-
Notifications
You must be signed in to change notification settings - Fork 4
/
single.py
29 lines (26 loc) · 1.21 KB
/
single.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""A single common terminal for all websockets.
"""
import tornado.web
# This demo requires tornado_xstatic and XStatic-term.js
import tornado_xstatic
from terminado import TermSocket, SingleTermManager
from common_demo_stuff import run_and_show_browser, STATIC_DIR, TEMPLATE_DIR
class TerminalPageHandler(tornado.web.RequestHandler):
def get(self):
return self.render("termpage.html", static=self.static_url,
xstatic=self.application.settings['xstatic_url'],
ws_url_path="/websocket")
def single_instance(argv):
term_manager = SingleTermManager(shell_command=[argv])
handlers = [
(r"/websocket", TermSocket,
{'term_manager': term_manager}),
(r"/", TerminalPageHandler),
(r"/xstatic/(.*)", tornado_xstatic.XStaticFileHandler,
{'allowed_modules': ['termjs']})
]
app = tornado.web.Application(handlers, static_path=STATIC_DIR,
template_path=TEMPLATE_DIR,
xstatic_url = tornado_xstatic.url_maker('/xstatic/'))
app.listen(8765, 'localhost')
run_and_show_browser("http://localhost:8765/", term_manager)