|
1 | 1 | <html lang="en">
|
2 |
| -<head> |
3 |
| - <meta charset="utf-8"> |
4 |
| - <title>pyxterm.js</title> |
5 |
| - <style> |
6 |
| - html { |
7 |
| - font-family: arial; |
8 |
| - } |
9 |
| - </style> |
10 |
| - <link rel=" stylesheet" href=" https://unpkg.com/[email protected]/css/xterm.css" /> |
11 |
| -</head> |
12 |
| -<body> |
| 2 | + <head> |
| 3 | + <meta charset="utf-8" /> |
| 4 | + <title>pyxterm.js</title> |
| 5 | + <style> |
| 6 | + html { |
| 7 | + font-family: arial; |
| 8 | + } |
| 9 | + </style> |
| 10 | + <link |
| 11 | + rel="stylesheet" |
| 12 | + href=" https://unpkg.com/[email protected]/css/xterm.css" |
| 13 | + /> |
| 14 | + </head> |
| 15 | + <body> |
| 16 | + <span style="font-size: 1.4em">pyxterm.js</span> |
| 17 | + <span style="font-size: small" |
| 18 | + >status: |
| 19 | + <span style="font-size: small" id="status">connecting...</span></span |
| 20 | + > |
13 | 21 |
|
14 |
| -<span style="font-size: 1.4em;">pyxterm.js</span> |
15 |
| -<span style="font-size: small;">status: <span style="font-size: small;" id="status">connecting...</span></span> |
| 22 | + <div style="width: 100%; height: calc(100% - 50px)" id="terminal"></div> |
16 | 23 |
|
17 |
| -<div style="width: 100%; height: calc(100% - 50px);" id="terminal"></div> |
18 |
| - |
19 |
| -<p style="text-align: right; font-size: small;"> |
20 |
| - built by <a href="https://grassfedcode.com">Chad Smith</a> <a href="https://github.com/cs01">GitHub</a> |
21 |
| -</p> |
22 |
| -<!-- xterm --> |
23 |
| -<script src=" https://unpkg.com/[email protected]/lib/xterm.js" ></script> |
24 |
| -<script src=" https://unpkg.com/[email protected]/lib/xterm-addon-fit.js" ></script> |
25 |
| -<script src=" https://unpkg.com/[email protected]/lib/xterm-addon-web-links.js" ></script> |
26 |
| -<script src=" https://unpkg.com/[email protected]/lib/xterm-addon-sear |
| 24 | + <p style="text-align: right; font-size: small"> |
| 25 | + built by <a href="https://grassfedcode.com">Chad Smith</a> |
| 26 | + <a href="https://github.com/cs01">GitHub</a> |
| 27 | + </p> |
| 28 | + <!-- xterm --> |
| 29 | + <script src=" https://unpkg.com/[email protected]/lib/xterm.js" ></script> |
| 30 | + <script src=" https://unpkg.com/[email protected]/lib/xterm-addon-fit.js" ></script> |
| 31 | + <script src=" https://unpkg.com/[email protected]/lib/xterm-addon-web-links.js" ></script> |
| 32 | + <script src=" https://unpkg.com/[email protected]/lib/xterm-addon-sear |
27 | 33 | ch.js"></script>
|
28 |
| -<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.min.js"></script> |
| 34 | + <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.min.js"></script> |
29 | 35 |
|
30 |
| -<script> |
31 |
| - const term = new Terminal({ |
| 36 | + <script> |
| 37 | + const term = new Terminal({ |
32 | 38 | cursorBlink: true,
|
33 | 39 | macOptionIsMeta: true,
|
34 | 40 | scrollback: true,
|
35 |
| - }); |
36 |
| - // https://github.com/xtermjs/xterm.js/issues/2941 |
37 |
| - const fit = new FitAddon.FitAddon(); |
38 |
| - term.loadAddon(fit); |
39 |
| - term.loadAddon(new WebLinksAddon.WebLinksAddon()); |
40 |
| - term.loadAddon(new SearchAddon.SearchAddon()); |
41 |
| - |
42 |
| - term.open(document.getElementById('terminal')); |
43 |
| - fit.fit() |
44 |
| - term.resize(15, 50) |
45 |
| - console.log(`size: ${term.cols} columns, ${term.rows} rows`) |
46 |
| - fit.fit() |
47 |
| - term.write("Welcome to pyxterm.js!\nhttps://github.com/cs01/pyxterm.js\n") |
48 |
| - term.onKey((key, ev) => { |
49 |
| - console.log("pressed key", key) |
50 |
| - console.log("event", ev) |
51 |
| - socket.emit("pty-input", {"input": key}) |
52 |
| - }); |
53 |
| - |
54 |
| - const socket = io.connect('/pty'); |
55 |
| - const status = document.getElementById("status") |
56 |
| - |
57 |
| - socket.on("pty-output", function(data){ |
58 |
| - console.log("new output", data) |
59 |
| - term.write(data.output) |
60 |
| - }) |
| 41 | + }); |
| 42 | + // https://github.com/xtermjs/xterm.js/issues/2941 |
| 43 | + const fit = new FitAddon.FitAddon(); |
| 44 | + term.loadAddon(fit); |
| 45 | + term.loadAddon(new WebLinksAddon.WebLinksAddon()); |
| 46 | + term.loadAddon(new SearchAddon.SearchAddon()); |
61 | 47 |
|
62 |
| - socket.on("connect", () => { |
63 |
| - fitToscreen() |
64 |
| - status.innerHTML = '<span style="background-color: lightgreen;">connected</span>' |
65 |
| - } |
66 |
| - ) |
| 48 | + term.open(document.getElementById("terminal")); |
| 49 | + fit.fit(); |
| 50 | + term.resize(15, 50); |
| 51 | + console.log(`size: ${term.cols} columns, ${term.rows} rows`); |
| 52 | + fit.fit(); |
| 53 | + term.writeln("Welcome to pyxterm.js!"); |
| 54 | + term.writeln("https://github.com/cs01/pyxterm.js"); |
| 55 | + term.onData((data) => { |
| 56 | + console.log("pressed key", data.input); |
| 57 | + socket.emit("pty-input", { input: data.input }); |
| 58 | + }); |
67 | 59 |
|
68 |
| - socket.on("disconnect", () => { |
69 |
| - status.innerHTML = '<span style="background-color: #ff8383;">disconnected</span>' |
70 |
| - }) |
| 60 | + const socket = io.connect("/pty"); |
| 61 | + const status = document.getElementById("status"); |
71 | 62 |
|
72 |
| - function fitToscreen(){ |
73 |
| - fit.fit() |
74 |
| - socket.emit("resize", {"cols": term.cols, "rows": term.rows}) |
75 |
| - } |
| 63 | + socket.on("pty-output", function (data) { |
| 64 | + console.log("new output", data); |
| 65 | + term.write(data.output); |
| 66 | + }); |
76 | 67 |
|
77 |
| - function debounce(func, wait_ms) { |
78 |
| - let timeout |
79 |
| - return function(...args) { |
80 |
| - const context = this |
81 |
| - clearTimeout(timeout) |
82 |
| - timeout = setTimeout(() => func.apply(context, args), wait_ms) |
83 |
| - } |
84 |
| - } |
| 68 | + socket.on("connect", () => { |
| 69 | + fitToscreen(); |
| 70 | + status.innerHTML = |
| 71 | + '<span style="background-color: lightgreen;">connected</span>'; |
| 72 | + }); |
85 | 73 |
|
86 |
| - const wait_ms = 50; |
87 |
| - window.onresize = debounce(fitToscreen, wait_ms) |
| 74 | + socket.on("disconnect", () => { |
| 75 | + status.innerHTML = |
| 76 | + '<span style="background-color: #ff8383;">disconnected</span>'; |
| 77 | + }); |
88 | 78 |
|
| 79 | + function fitToscreen() { |
| 80 | + fit.fit(); |
| 81 | + socket.emit("resize", { cols: term.cols, rows: term.rows }); |
| 82 | + } |
89 | 83 |
|
90 |
| -</script> |
| 84 | + function debounce(func, wait_ms) { |
| 85 | + let timeout; |
| 86 | + return function (...args) { |
| 87 | + const context = this; |
| 88 | + clearTimeout(timeout); |
| 89 | + timeout = setTimeout(() => func.apply(context, args), wait_ms); |
| 90 | + }; |
| 91 | + } |
91 | 92 |
|
92 |
| -</body> |
| 93 | + const wait_ms = 50; |
| 94 | + window.onresize = debounce(fitToscreen, wait_ms); |
| 95 | + </script> |
| 96 | + </body> |
93 | 97 | </html>
|
0 commit comments