uimodule.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  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. from __future__ import annotations
  9. from pathlib import Path
  10. import tornado.web
  11. class Terminal(tornado.web.UIModule):
  12. """A terminal UI module."""
  13. def render(self, ws_url: str, cols: int = 80, rows: int = 25) -> str:
  14. """Render the module."""
  15. return (
  16. '<div class="terminado-container" '
  17. f'data-ws-url="{ws_url}" '
  18. f'data-rows="{rows}" data-cols="{cols}"/>'
  19. )
  20. def javascript_files(self) -> list[str]:
  21. """Get the list of JS files to include."""
  22. # TODO: Can we calculate these dynamically?
  23. return ["/xstatic/termjs/term.js", "/static/terminado.js"]
  24. def embedded_javascript(self) -> str:
  25. """Get the embedded JS content as a string."""
  26. file = Path(__file__).parent / "uimod_embed.js"
  27. with file.open() as f:
  28. return f.read()