uimodule.py 1012 B

123456789101112131415161718192021222324252627
  1. """A Tornado UI module for a terminal backed by terminado.
  2. See the Tornado docs for information on UI modules:
  3. http://www.tornadoweb.org/en/stable/guide/templates.html#ui-modules
  4. """
  5. # Copyright (c) Jupyter Development Team
  6. # Copyright (c) 2014, Ramalingam Saravanan <sarava@sarava.net>
  7. # Distributed under the terms of the Simplified BSD License.
  8. import os.path
  9. import tornado.web
  10. class Terminal(tornado.web.UIModule):
  11. def render(self, ws_url, cols=80, rows=25):
  12. return ('<div class="terminado-container" '
  13. 'data-ws-url="{ws_url}" '
  14. 'data-rows="{rows}" data-cols="{cols}"/>').format(
  15. ws_url=ws_url, rows=rows, cols=cols)
  16. def javascript_files(self):
  17. # TODO: Can we calculate these dynamically?
  18. return ['/xstatic/termjs/term.js', '/static/terminado.js']
  19. def embedded_javascript(self):
  20. file = os.path.join(os.path.dirname(__file__), 'uimod_embed.js')
  21. with open(file) as f:
  22. return f.read()