-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathhterm.html
141 lines (128 loc) · 3.85 KB
/
hterm.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!DOCTYPE html>
<html>
<head>
<title>hterm test page</title>
<meta charset='utf-8'/>
<style>
html {
height: 100%;
}
body {
position: absolute;
height: 100%;
width: 100%;
overflow: hidden;
margin: 0px;
padding: 0px;
}
#terminal {
display: block;
position: relative;
height: 100%;
width: 100%;
margin: 0px;
padding: 0px;
}
</style>
</head>
<body>
<div id='terminal'></div>
<script type="module">
import {lib} from '../../libdot/index.js';
import {hterm} from '../index.js';
function initContent(io) {
const ver = lib.resource.getData('hterm/changelog/version');
const date = lib.resource.getData('hterm/changelog/date');
const pkg = `hterm ${ver} (${date})`;
/* eslint-disable quotes */
io.println("\r\n\
.--~~~~~~~~~~~~~------.\r\n\
/--===============------\\\r\n\
| |```````````````| |\r\n\
| | | |\r\n\
| | >_< | |\r\n\
| | | |\r\n\
| |_______________| |\r\n\
| ::::|\r\n\
'======================='\r\n\
//-'-'-'-'-'-'-'-'-'-'-\\\\\r\n\
//_'_'_'_'_'_'_'_'_'_'_'_\\\\\r\n\
[-------------------------]\r\n\
\\_________________________/\r\n\
\r\n\
Welcome to hterm!\r\n\
Press F11 to go fullscreen to use all shortcuts.\r\n\
Running " + pkg + ".\r\n\
");
/* eslint-enable quotes */
}
// Load translations if available.
hterm.initPromise.then(async () => {
// Try to load the messages database from nassh. This isn't strictly needed
// (so if it fails, it should be fine), but does help when testing locally.
// $1 here means we search the user's language. Change it to 'en' or another
// specific language to test those specifically.
const lang = '$1';
await hterm.messageManager.findAndLoadMessages(
lib.f.getURL(`../../nassh/_locales/${lang}/messages.json`));
});
function setupHterm() {
const term = new hterm.Terminal();
term.onTerminalReady = function() {
const io = this.io.push();
function printPrompt() {
io.print(
'\x1b[38:2:51:105:232mh' +
'\x1b[38:2:213:15:37mt' +
'\x1b[38:2:238:178:17me' +
'\x1b[38:2:51:105:232mr' +
'\x1b[38:2:0:153:37mm' +
'\x1b[38:2:213:15:37m>' +
'\x1b[0m ');
}
io.onVTKeystroke = (string) => {
switch (string) {
case '\r':
io.println('');
printPrompt();
break;
case '\x7f':
// \x08 = backspace, \x1b[K = 'Erase in line'.
io.print('\x08\x1b[K');
break;
default:
io.print(string);
break;
}
};
io.sendString = io.print;
initContent(io);
printPrompt();
this.setCursorVisible(true);
this.keyboard.bindings.addBinding('F11', 'PASS');
this.keyboard.bindings.addBinding('Ctrl+R', 'PASS');
};
term.decorate(document.querySelector('#terminal'));
term.installKeyboard();
term.contextMenu.setItems([
{name: 'Terminal Reset', action: () => term.reset()},
{name: 'Terminal Clear', action: () => term.clear()},
{name: hterm.ContextMenu.SEPARATOR},
{name: 'Homepage', action: function() {
lib.f.openWindow(
'https://chromium.googlesource.com/apps/libapps/+/HEAD/hterm/README.md',
'_blank');
}},
{name: 'FAQ', action: function() {
lib.f.openWindow('https://hterm.org/x/ssh/faq', '_blank');
}},
]);
// Useful for console debugging.
globalThis.term_ = term;
}
globalThis.onload = function() {
setupHterm();
};
</script>
</body>
</html>