terminado.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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(JSON.stringify(["set_size", size.rows, size.cols,
  14. window.innerHeight, window.innerWidth]));
  15. term.on('data', function(data) {
  16. ws.send(JSON.stringify(['stdin', data]));
  17. });
  18. term.on('title', function(title) {
  19. document.title = title;
  20. });
  21. term.open(element);
  22. ws.onmessage = function(event) {
  23. json_msg = JSON.parse(event.data);
  24. switch(json_msg[0]) {
  25. case "stdout":
  26. term.write(json_msg[1]);
  27. break;
  28. case "disconnect":
  29. term.write("\r\n\r\n[Finished... Terminado]\r\n");
  30. break;
  31. }
  32. };
  33. };
  34. return {socket: ws, term: term};
  35. }