terminado.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright (c) Jupyter Development Team
  2. // Copyright (c) 2014, Ramalingam Saravanan <sarava@sarava.net>
  3. // Distributed under the terms of the Simplified BSD License.
  4. function make_terminal(element, size, ws_url) {
  5. var ws = new WebSocket(ws_url);
  6. var term = new Terminal({
  7. cols: size.cols,
  8. rows: size.rows,
  9. screenKeys: true,
  10. useStyle: true,
  11. });
  12. ws.onopen = function (event) {
  13. ws.send(
  14. JSON.stringify([
  15. "set_size",
  16. size.rows,
  17. size.cols,
  18. window.innerHeight,
  19. window.innerWidth,
  20. ]),
  21. );
  22. term.on("data", function (data) {
  23. ws.send(JSON.stringify(["stdin", data]));
  24. });
  25. term.on("title", function (title) {
  26. document.title = title;
  27. });
  28. term.open(element);
  29. ws.onmessage = function (event) {
  30. json_msg = JSON.parse(event.data);
  31. switch (json_msg[0]) {
  32. case "stdout":
  33. term.write(json_msg[1]);
  34. break;
  35. case "disconnect":
  36. term.write("\r\n\r\n[Finished... Terminado]\r\n");
  37. break;
  38. }
  39. };
  40. };
  41. return { socket: ws, term: term };
  42. }