blob: 913ef49eb0495ff3350f0ad04d19fb1b7e46cd50 [file] [log] [blame]
Mike Frysinger598e8012022-09-07 08:38:34 -04001// Copyright 2022 The ChromiumOS Authors
Jason Lind66e6bf2022-08-22 14:47:10 +10002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Jason Linca61ffb2022-08-03 19:37:12 +10005/**
6 * @fileoverview For supporting xterm.js and the terminal emulator.
7 */
8
9// TODO(b/236205389): add tests. For example, we should enable the test in
10// terminal_tests.js for XtermTerminal.
11
Jason Lin2649da22022-10-12 10:16:44 +110012// TODO(b/236205389): support option smoothScrollDuration?
13
Jason Lin6a402a72022-08-25 16:07:02 +100014import {LitElement, css, html} from './lit.js';
Jason Linc48f7432022-10-13 17:28:30 +110015import {FontManager, ORIGINAL_URL, TERMINAL_EMULATORS, definePrefs,
16 delayedScheduler, fontManager, getOSInfo, sleep} from './terminal_common.js';
Jason Lin6a402a72022-08-25 16:07:02 +100017import {ICON_COPY} from './terminal_icons.js';
Jason Lin83707c92022-09-20 19:09:41 +100018import {TerminalTooltip} from './terminal_tooltip.js';
Jason Linc2504ae2022-09-02 13:03:31 +100019import {Terminal, Unicode11Addon, WebLinksAddon, WebglAddon}
Jason Lin4de4f382022-09-01 14:10:18 +100020 from './xterm.js';
Jason Lin2649da22022-10-12 10:16:44 +110021import {XtermInternal} from './terminal_xterm_internal.js';
Jason Linca61ffb2022-08-03 19:37:12 +100022
Jason Lin5690e752022-08-30 15:36:45 +100023
24/** @enum {number} */
25export const Modifier = {
26 Shift: 1 << 0,
27 Alt: 1 << 1,
28 Ctrl: 1 << 2,
29 Meta: 1 << 3,
30};
31
32// This is just a static map from key names to key codes. It helps make the code
33// a bit more readable.
34const keyCodes = hterm.Parser.identifiers.keyCodes;
35
36/**
37 * Encode a key combo (i.e. modifiers + a normal key) to an unique number.
38 *
39 * @param {number} modifiers
40 * @param {number} keyCode
41 * @return {number}
42 */
43export function encodeKeyCombo(modifiers, keyCode) {
44 return keyCode << 4 | modifiers;
45}
46
47const OS_DEFAULT_BINDINGS = [
48 // Submit feedback.
49 encodeKeyCombo(Modifier.Alt | Modifier.Shift, keyCodes.I),
50 // Toggle chromevox.
51 encodeKeyCombo(Modifier.Ctrl | Modifier.Alt, keyCodes.Z),
52 // Switch input method.
53 encodeKeyCombo(Modifier.Ctrl, keyCodes.SPACE),
54
55 // Dock window left/right.
56 encodeKeyCombo(Modifier.Alt, keyCodes.BRACKET_LEFT),
57 encodeKeyCombo(Modifier.Alt, keyCodes.BRACKET_RIGHT),
58
59 // Maximize/minimize window.
60 encodeKeyCombo(Modifier.Alt, keyCodes.EQUAL),
61 encodeKeyCombo(Modifier.Alt, keyCodes.MINUS),
62];
63
64
Jason Linca61ffb2022-08-03 19:37:12 +100065const ANSI_COLOR_NAMES = [
66 'black',
67 'red',
68 'green',
69 'yellow',
70 'blue',
71 'magenta',
72 'cyan',
73 'white',
74 'brightBlack',
75 'brightRed',
76 'brightGreen',
77 'brightYellow',
78 'brightBlue',
79 'brightMagenta',
80 'brightCyan',
81 'brightWhite',
82];
83
Jason Linca61ffb2022-08-03 19:37:12 +100084/**
Jason Linabad7562022-08-22 14:49:05 +100085 * @typedef {{
86 * term: !Terminal,
87 * fontManager: !FontManager,
Jason Lin2649da22022-10-12 10:16:44 +110088 * xtermInternal: !XtermInternal,
Jason Linabad7562022-08-22 14:49:05 +100089 * }}
90 */
91export let XtermTerminalTestParams;
92
93/**
Jason Lin5690e752022-08-30 15:36:45 +100094 * Compute a control character for a given character.
95 *
96 * @param {string} ch
97 * @return {string}
98 */
99function ctl(ch) {
100 return String.fromCharCode(ch.charCodeAt(0) - 64);
101}
102
103/**
Jason Lin21d854f2022-08-22 14:49:59 +1000104 * A "terminal io" class for xterm. We don't want the vanilla hterm.Terminal.IO
105 * because it always convert utf8 data to strings, which is not necessary for
106 * xterm.
107 */
108class XtermTerminalIO extends hterm.Terminal.IO {
109 /** @override */
110 writeUTF8(buffer) {
111 this.terminal_.write(new Uint8Array(buffer));
112 }
113
114 /** @override */
115 writelnUTF8(buffer) {
116 this.terminal_.writeln(new Uint8Array(buffer));
117 }
118
119 /** @override */
120 print(string) {
121 this.terminal_.write(string);
122 }
123
124 /** @override */
125 writeUTF16(string) {
126 this.print(string);
127 }
128
129 /** @override */
130 println(string) {
131 this.terminal_.writeln(string);
132 }
133
134 /** @override */
135 writelnUTF16(string) {
136 this.println(string);
137 }
138}
139
140/**
Jason Lin83707c92022-09-20 19:09:41 +1000141 * A custom link handler that:
142 *
143 * - Shows a tooltip with the url on a OSC 8 link. This is following what hterm
144 * is doing. Also, showing the tooltip is better for the security of the user
145 * because the link can have arbitrary text.
146 * - Uses our own way to open the window.
147 */
148class LinkHandler {
149 /**
150 * @param {!Terminal} term
151 */
152 constructor(term) {
153 this.term_ = term;
154 /** @type {?TerminalTooltip} */
155 this.tooltip_ = null;
156 }
157
158 /**
159 * @return {!TerminalTooltip}
160 */
161 getTooltip_() {
162 if (!this.tooltip_) {
163 this.tooltip_ = /** @type {!TerminalTooltip} */(
164 document.createElement('terminal-tooltip'));
165 this.tooltip_.classList.add('xterm-hover');
166 lib.notNull(this.term_.element).appendChild(this.tooltip_);
167 }
168 return this.tooltip_;
169 }
170
171 /**
172 * @param {!MouseEvent} ev
173 * @param {string} url
174 * @param {!Object} range
175 */
176 activate(ev, url, range) {
177 lib.f.openWindow(url, '_blank');
178 }
179
180 /**
181 * @param {!MouseEvent} ev
182 * @param {string} url
183 * @param {!Object} range
184 */
185 hover(ev, url, range) {
186 this.getTooltip_().show(url, {x: ev.clientX, y: ev.clientY});
187 }
188
189 /**
190 * @param {!MouseEvent} ev
191 * @param {string} url
192 * @param {!Object} range
193 */
194 leave(ev, url, range) {
195 this.getTooltip_().hide();
196 }
197}
198
Jason Linc7afb672022-10-11 15:54:17 +1100199class Bell {
200 constructor() {
201 this.showNotification = false;
202
203 /** @type {?Audio} */
204 this.audio_ = null;
205 /** @type {?Notification} */
206 this.notification_ = null;
207 this.coolDownUntil_ = 0;
208 }
209
210 /**
211 * Set whether a bell audio should be played.
212 *
213 * @param {boolean} value
214 */
215 set playAudio(value) {
216 this.audio_ = value ?
217 new Audio(lib.resource.getDataUrl('hterm/audio/bell')) : null;
218 }
219
220 ring() {
221 const now = Date.now();
222 if (now < this.coolDownUntil_) {
223 return;
224 }
225 this.coolDownUntil_ = now + 500;
226
227 this.audio_?.play();
228 if (this.showNotification && !document.hasFocus() && !this.notification_) {
229 this.notification_ = new Notification(
230 `\u266A ${document.title} \u266A`,
231 {icon: lib.resource.getDataUrl('hterm/images/icon-96')});
232 // Close the notification after a timeout. Note that this is different
233 // from hterm's behavior, but I think it makes more sense to do so.
234 setTimeout(() => {
235 this.notification_.close();
236 this.notification_ = null;
237 }, 5000);
238 }
239 }
240}
241
Jason Lind3aacef2022-10-12 19:03:37 +1100242const A11Y_BUTTON_STYLE = `
243position: fixed;
244z-index: 10;
245right: 16px;
246`;
247
248class A11yButtons {
249 /**
250 * @param {!Terminal} term
251 * @param {!Element} elem The container element for the terminal.
252 */
253 constructor(term, elem) {
254 this.pageUpButton_ = document.createElement('button');
255 this.pageUpButton_.style.cssText = A11Y_BUTTON_STYLE;
256 this.pageUpButton_.textContent =
257 hterm.messageManager.get('HTERM_BUTTON_PAGE_UP');
258 this.pageUpButton_.addEventListener('click',
259 () => term.scrollPages(-1));
260
261 this.pageDownButton_ = document.createElement('button');
262 this.pageDownButton_.style.cssText = A11Y_BUTTON_STYLE;
263 this.pageDownButton_.textContent =
264 hterm.messageManager.get('HTERM_BUTTON_PAGE_DOWN');
265 this.pageDownButton_.addEventListener('click',
266 () => term.scrollPages(1));
267
268 this.resetPos_();
269 elem.prepend(this.pageUpButton_);
270 elem.append(this.pageDownButton_);
271
272 this.onSelectionChange_ = this.onSelectionChange_.bind(this);
273 }
274
275 /**
276 * @param {boolean} enabled
277 */
278 setEnabled(enabled) {
279 if (enabled) {
280 document.addEventListener('selectionchange', this.onSelectionChange_);
281 } else {
282 this.resetPos_();
283 document.removeEventListener('selectionchange', this.onSelectionChange_);
284 }
285 }
286
287 resetPos_() {
288 this.pageUpButton_.style.top = '-200px';
289 this.pageDownButton_.style.bottom = '-200px';
290 }
291
292 onSelectionChange_() {
293 this.resetPos_();
294
295 const selectedElement = document.getSelection().anchorNode.parentElement;
296 if (selectedElement === this.pageUpButton_) {
297 this.pageUpButton_.style.top = '16px';
298 } else if (selectedElement === this.pageDownButton_) {
299 this.pageDownButton_.style.bottom = '16px';
300 }
301 }
302}
303
Jason Lin83707c92022-09-20 19:09:41 +1000304/**
Jason Linca61ffb2022-08-03 19:37:12 +1000305 * A terminal class that 1) uses xterm.js and 2) behaves like a `hterm.Terminal`
306 * so that it can be used in existing code.
307 *
Jason Linca61ffb2022-08-03 19:37:12 +1000308 * @extends {hterm.Terminal}
309 * @unrestricted
310 */
Jason Linabad7562022-08-22 14:49:05 +1000311export class XtermTerminal {
Jason Linca61ffb2022-08-03 19:37:12 +1000312 /**
313 * @param {{
314 * storage: !lib.Storage,
315 * profileId: string,
316 * enableWebGL: boolean,
Jason Linabad7562022-08-22 14:49:05 +1000317 * testParams: (!XtermTerminalTestParams|undefined),
Jason Linca61ffb2022-08-03 19:37:12 +1000318 * }} args
319 */
Jason Linabad7562022-08-22 14:49:05 +1000320 constructor({storage, profileId, enableWebGL, testParams}) {
Jason Lin5690e752022-08-30 15:36:45 +1000321 this.ctrlCKeyDownHandler_ = this.ctrlCKeyDownHandler_.bind(this);
322 this.ctrlVKeyDownHandler_ = this.ctrlVKeyDownHandler_.bind(this);
323 this.zoomKeyDownHandler_ = this.zoomKeyDownHandler_.bind(this);
324
Jason Lin8de3d282022-09-01 21:29:05 +1000325 this.inited_ = false;
Jason Lin21d854f2022-08-22 14:49:59 +1000326 this.profileId_ = profileId;
Jason Linca61ffb2022-08-03 19:37:12 +1000327 /** @type {!hterm.PreferenceManager} */
328 this.prefs_ = new hterm.PreferenceManager(storage, profileId);
Jason Linc48f7432022-10-13 17:28:30 +1100329 definePrefs(this.prefs_);
Jason Linca61ffb2022-08-03 19:37:12 +1000330 this.enableWebGL_ = enableWebGL;
331
Jason Lin5690e752022-08-30 15:36:45 +1000332 // TODO: we should probably pass the initial prefs to the ctor.
Jason Linfc8a3722022-09-07 17:49:18 +1000333 this.term = testParams?.term || new Terminal({allowProposedApi: true});
Jason Lin2649da22022-10-12 10:16:44 +1100334 this.xtermInternal_ = testParams?.xtermInternal ||
335 new XtermInternal(this.term);
Jason Linabad7562022-08-22 14:49:05 +1000336 this.fontManager_ = testParams?.fontManager || fontManager;
Jason Linabad7562022-08-22 14:49:05 +1000337
Jason Linc2504ae2022-09-02 13:03:31 +1000338 /** @type {?Element} */
339 this.container_;
Jason Linc7afb672022-10-11 15:54:17 +1100340 this.bell_ = new Bell();
Jason Linc2504ae2022-09-02 13:03:31 +1000341 this.scheduleFit_ = delayedScheduler(() => this.fit_(),
Jason Linabad7562022-08-22 14:49:05 +1000342 testParams ? 0 : 250);
343
Jason Lin83707c92022-09-20 19:09:41 +1000344 this.term.loadAddon(
345 new WebLinksAddon((e, uri) => lib.f.openWindow(uri, '_blank')));
Jason Lin4de4f382022-09-01 14:10:18 +1000346 this.term.loadAddon(new Unicode11Addon());
347 this.term.unicode.activeVersion = '11';
348
Jason Linabad7562022-08-22 14:49:05 +1000349 this.pendingFont_ = null;
350 this.scheduleRefreshFont_ = delayedScheduler(
351 () => this.refreshFont_(), 100);
352 document.fonts.addEventListener('loadingdone',
353 () => this.onFontLoadingDone_());
Jason Linca61ffb2022-08-03 19:37:12 +1000354
355 this.installUnimplementedStubs_();
Jason Line9231bc2022-09-01 13:54:02 +1000356 this.installEscapeSequenceHandlers_();
Jason Linca61ffb2022-08-03 19:37:12 +1000357
Jason Lin34a45322022-10-12 19:10:52 +1100358 this.term.onResize(({cols, rows}) => {
359 this.io.onTerminalResize(cols, rows);
360 if (this.prefs_.get('enable-resize-status')) {
361 this.showOverlay(`${cols} × ${rows}`);
362 }
363 });
Jason Lin21d854f2022-08-22 14:49:59 +1000364 // We could also use `this.io.sendString()` except for the nassh exit
365 // prompt, which only listens to onVTKeystroke().
366 this.term.onData((data) => this.io.onVTKeystroke(data));
Jason Lin80e69132022-09-02 16:31:43 +1000367 this.term.onBinary((data) => this.io.onVTKeystroke(data));
Jason Lin2649da22022-10-12 10:16:44 +1100368 this.term.onTitleChange((title) => this.setWindowTitle(title));
Jason Lin83ef5ba2022-10-13 17:40:30 +1100369 this.term.onSelectionChange(() => {
370 if (this.prefs_.get('copy-on-select')) {
371 this.copySelection_();
372 }
373 });
Jason Linc7afb672022-10-11 15:54:17 +1100374 this.term.onBell(() => this.ringBell());
Jason Lin5690e752022-08-30 15:36:45 +1000375
376 /**
377 * A mapping from key combo (see encodeKeyCombo()) to a handler function.
378 *
379 * If a key combo is in the map:
380 *
381 * - The handler instead of xterm.js will handle the keydown event.
382 * - Keyup and keypress will be ignored by both us and xterm.js.
383 *
384 * We re-generate this map every time a relevant pref value is changed. This
385 * is ok because pref changes are rare.
386 *
387 * @type {!Map<number, function(!KeyboardEvent)>}
388 */
389 this.keyDownHandlers_ = new Map();
390 this.scheduleResetKeyDownHandlers_ =
391 delayedScheduler(() => this.resetKeyDownHandlers_(), 250);
392
393 this.term.attachCustomKeyEventHandler(
394 this.customKeyEventHandler_.bind(this));
Jason Linca61ffb2022-08-03 19:37:12 +1000395
Jason Lin21d854f2022-08-22 14:49:59 +1000396 this.io = new XtermTerminalIO(this);
397 this.notificationCenter_ = null;
Jason Lind3aacef2022-10-12 19:03:37 +1100398 this.htermA11yReader_ = null;
399 this.a11yButtons_ = null;
Jason Lin6a402a72022-08-25 16:07:02 +1000400 this.copyNotice_ = null;
Jason Lin446f3d92022-10-13 17:34:21 +1100401 this.scrollOnOutputListener_ = null;
Jason Lin6a402a72022-08-25 16:07:02 +1000402
Jason Lin83707c92022-09-20 19:09:41 +1000403 this.term.options.linkHandler = new LinkHandler(this.term);
Jason Lin6a402a72022-08-25 16:07:02 +1000404 this.term.options.theme = {
Jason Lin461ca562022-09-07 13:53:08 +1000405 // The webgl cursor layer also paints the character under the cursor with
406 // this `cursorAccent` color. We use a completely transparent color here
407 // to effectively disable that.
408 cursorAccent: 'rgba(0, 0, 0, 0)',
409 customGlyphs: true,
Jason Lin2edc25d2022-09-16 15:06:48 +1000410 selectionBackground: 'rgba(174, 203, 250, .6)',
411 selectionInactiveBackground: 'rgba(218, 220, 224, .6)',
Jason Lin6a402a72022-08-25 16:07:02 +1000412 selectionForeground: 'black',
Jason Lin6a402a72022-08-25 16:07:02 +1000413 };
414 this.observePrefs_();
Jason Linca61ffb2022-08-03 19:37:12 +1000415 }
416
Jason Linc7afb672022-10-11 15:54:17 +1100417 /** @override */
Jason Lin2649da22022-10-12 10:16:44 +1100418 setWindowTitle(title) {
419 document.title = title;
420 }
421
422 /** @override */
Jason Linc7afb672022-10-11 15:54:17 +1100423 ringBell() {
424 this.bell_.ring();
425 }
426
Jason Lin2649da22022-10-12 10:16:44 +1100427 /** @override */
428 print(str) {
429 this.xtermInternal_.print(str);
430 }
431
432 /** @override */
433 wipeContents() {
434 this.term.clear();
435 }
436
437 /** @override */
438 newLine() {
439 this.xtermInternal_.newLine();
440 }
441
442 /** @override */
443 cursorLeft(number) {
444 this.xtermInternal_.cursorLeft(number ?? 1);
445 }
446
Jason Lind3aacef2022-10-12 19:03:37 +1100447 /** @override */
448 setAccessibilityEnabled(enabled) {
449 this.a11yButtons_.setEnabled(enabled);
450 this.htermA11yReader_.setAccessibilityEnabled(enabled);
451 this.term.options.screenReaderMode = enabled;
452 }
453
Jason Linca61ffb2022-08-03 19:37:12 +1000454 /**
455 * Install stubs for stuff that we haven't implemented yet so that the code
456 * still runs.
457 */
458 installUnimplementedStubs_() {
459 this.keyboard = {
460 keyMap: {
461 keyDefs: [],
462 },
463 bindings: {
464 clear: () => {},
465 addBinding: () => {},
466 addBindings: () => {},
467 OsDefaults: {},
468 },
469 };
470 this.keyboard.keyMap.keyDefs[78] = {};
471
472 const methodNames = [
Jason Linca61ffb2022-08-03 19:37:12 +1000473 'setBackgroundImage',
474 'setCursorPosition',
475 'setCursorVisible',
Jason Linca61ffb2022-08-03 19:37:12 +1000476 ];
477
478 for (const name of methodNames) {
479 this[name] = () => console.warn(`${name}() is not implemented`);
480 }
481
482 this.contextMenu = {
483 setItems: () => {
484 console.warn('.contextMenu.setItems() is not implemented');
485 },
486 };
Jason Lin21d854f2022-08-22 14:49:59 +1000487
488 this.vt = {
489 resetParseState: () => {
490 console.warn('.vt.resetParseState() is not implemented');
491 },
492 };
Jason Linca61ffb2022-08-03 19:37:12 +1000493 }
494
Jason Line9231bc2022-09-01 13:54:02 +1000495 installEscapeSequenceHandlers_() {
496 // OSC 52 for copy.
497 this.term.parser.registerOscHandler(52, (args) => {
498 // Args comes in as a single 'clipboard;b64-data' string. The clipboard
499 // parameter is used to select which of the X clipboards to address. Since
500 // we're not integrating with X, we treat them all the same.
501 const parsedArgs = args.match(/^[cps01234567]*;(.*)/);
502 if (!parsedArgs) {
503 return true;
504 }
505
506 let data;
507 try {
508 data = window.atob(parsedArgs[1]);
509 } catch (e) {
510 // If the user sent us invalid base64 content, silently ignore it.
511 return true;
512 }
513 const decoder = new TextDecoder();
514 const bytes = lib.codec.stringToCodeUnitArray(data);
515 this.copyString_(decoder.decode(bytes));
516
517 return true;
518 });
Jason Lin2649da22022-10-12 10:16:44 +1100519
520 this.xtermInternal_.installTmuxControlModeHandler(
521 (data) => this.onTmuxControlModeLine(data));
522 this.xtermInternal_.installEscKHandler();
Jason Line9231bc2022-09-01 13:54:02 +1000523 }
524
Jason Linca61ffb2022-08-03 19:37:12 +1000525 /**
Jason Lin21d854f2022-08-22 14:49:59 +1000526 * Write data to the terminal.
527 *
528 * @param {string|!Uint8Array} data string for UTF-16 data, Uint8Array for
529 * UTF-8 data
Jason Lin2649da22022-10-12 10:16:44 +1100530 * @param {function()=} callback Optional callback that fires when the data
531 * was processed by the parser.
Jason Lin21d854f2022-08-22 14:49:59 +1000532 */
Jason Lin2649da22022-10-12 10:16:44 +1100533 write(data, callback) {
534 this.term.write(data, callback);
Jason Lin21d854f2022-08-22 14:49:59 +1000535 }
536
537 /**
538 * Like `this.write()` but also write a line break.
539 *
540 * @param {string|!Uint8Array} data
Jason Lin2649da22022-10-12 10:16:44 +1100541 * @param {function()=} callback Optional callback that fires when the data
542 * was processed by the parser.
Jason Lin21d854f2022-08-22 14:49:59 +1000543 */
Jason Lin2649da22022-10-12 10:16:44 +1100544 writeln(data, callback) {
545 this.term.writeln(data, callback);
Jason Lin21d854f2022-08-22 14:49:59 +1000546 }
547
Jason Linca61ffb2022-08-03 19:37:12 +1000548 get screenSize() {
549 return new hterm.Size(this.term.cols, this.term.rows);
550 }
551
552 /**
553 * Don't need to do anything.
554 *
555 * @override
556 */
557 installKeyboard() {}
558
559 /**
560 * @override
561 */
562 decorate(elem) {
Jason Linc2504ae2022-09-02 13:03:31 +1000563 this.container_ = elem;
Jason Lin8de3d282022-09-01 21:29:05 +1000564 (async () => {
565 await new Promise((resolve) => this.prefs_.readStorage(resolve));
566 // This will trigger all the observers to set the terminal options before
567 // we call `this.term.open()`.
568 this.prefs_.notifyAll();
569
Jason Linc2504ae2022-09-02 13:03:31 +1000570 const screenPaddingSize = /** @type {number} */(
571 this.prefs_.get('screen-padding-size'));
572 elem.style.paddingTop = elem.style.paddingLeft = `${screenPaddingSize}px`;
573
Jason Lin8de3d282022-09-01 21:29:05 +1000574 this.inited_ = true;
575 this.term.open(elem);
576
Jason Lin8de3d282022-09-01 21:29:05 +1000577 if (this.enableWebGL_) {
578 this.term.loadAddon(new WebglAddon());
579 }
580 this.term.focus();
581 (new ResizeObserver(() => this.scheduleFit_())).observe(elem);
Jason Lind3aacef2022-10-12 19:03:37 +1100582 this.htermA11yReader_ = new hterm.AccessibilityReader(elem);
583 this.notificationCenter_ = new hterm.NotificationCenter(document.body,
584 this.htermA11yReader_);
Jason Lin8de3d282022-09-01 21:29:05 +1000585
Emil Mikulic2a194d02022-09-29 14:30:59 +1000586 // Block right-click context menu from popping up.
587 elem.addEventListener('contextmenu', (e) => e.preventDefault());
588
589 // Add a handler for pasting with the mouse.
590 elem.addEventListener('mousedown', async (e) => {
591 if (this.term.modes.mouseTrackingMode !== 'none') {
592 // xterm.js is in mouse mode and will handle the event.
593 return;
594 }
595 const MIDDLE = 1;
596 const RIGHT = 2;
597 if (e.button === MIDDLE || (e.button === RIGHT &&
598 this.prefs_.getBoolean('mouse-right-click-paste'))) {
599 // Paste.
600 if (navigator.clipboard && navigator.clipboard.readText) {
601 const text = await navigator.clipboard.readText();
602 this.term.paste(text);
603 }
604 }
605 });
606
Jason Lin2649da22022-10-12 10:16:44 +1100607 await this.scheduleFit_();
Jason Lind3aacef2022-10-12 19:03:37 +1100608 this.a11yButtons_ = new A11yButtons(this.term, elem);
609
Jason Lin8de3d282022-09-01 21:29:05 +1000610 this.onTerminalReady();
611 })();
Jason Lin21d854f2022-08-22 14:49:59 +1000612 }
613
614 /** @override */
615 showOverlay(msg, timeout = 1500) {
Jason Lin34a45322022-10-12 19:10:52 +1100616 this.notificationCenter_?.show(msg, {timeout});
Jason Lin21d854f2022-08-22 14:49:59 +1000617 }
618
619 /** @override */
620 hideOverlay() {
Jason Lin34a45322022-10-12 19:10:52 +1100621 this.notificationCenter_?.hide();
Jason Linca61ffb2022-08-03 19:37:12 +1000622 }
623
624 /** @override */
625 getPrefs() {
626 return this.prefs_;
627 }
628
629 /** @override */
630 getDocument() {
631 return window.document;
632 }
633
Jason Lin21d854f2022-08-22 14:49:59 +1000634 /** @override */
635 reset() {
636 this.term.reset();
Jason Linca61ffb2022-08-03 19:37:12 +1000637 }
638
639 /** @override */
Jason Lin21d854f2022-08-22 14:49:59 +1000640 setProfile(profileId, callback = undefined) {
641 this.prefs_.setProfile(profileId, callback);
Jason Linca61ffb2022-08-03 19:37:12 +1000642 }
643
Jason Lin21d854f2022-08-22 14:49:59 +1000644 /** @override */
645 interpret(string) {
646 this.term.write(string);
Jason Linca61ffb2022-08-03 19:37:12 +1000647 }
648
Jason Lin21d854f2022-08-22 14:49:59 +1000649 /** @override */
650 focus() {
651 this.term.focus();
652 }
Jason Linca61ffb2022-08-03 19:37:12 +1000653
654 /** @override */
655 onOpenOptionsPage() {}
656
657 /** @override */
658 onTerminalReady() {}
659
Jason Lind04bab32022-08-22 14:48:39 +1000660 observePrefs_() {
Jason Lin21d854f2022-08-22 14:49:59 +1000661 // This is for this.notificationCenter_.
662 const setHtermCSSVariable = (name, value) => {
663 document.body.style.setProperty(`--hterm-${name}`, value);
664 };
665
666 const setHtermColorCSSVariable = (name, color) => {
667 const css = lib.notNull(lib.colors.normalizeCSS(color));
668 const rgb = lib.colors.crackRGB(css).slice(0, 3).join(',');
669 setHtermCSSVariable(name, rgb);
670 };
671
672 this.prefs_.addObserver('font-size', (v) => {
Jason Linda56aa92022-09-02 13:01:49 +1000673 this.updateOption_('fontSize', v, true);
Jason Lin21d854f2022-08-22 14:49:59 +1000674 setHtermCSSVariable('font-size', `${v}px`);
675 });
676
Jason Linda56aa92022-09-02 13:01:49 +1000677 // TODO(lxj): support option "lineHeight", "scrollback".
Jason Lind04bab32022-08-22 14:48:39 +1000678 this.prefs_.addObservers(null, {
Jason Linda56aa92022-09-02 13:01:49 +1000679 'audible-bell-sound': (v) => {
Jason Linc7afb672022-10-11 15:54:17 +1100680 this.bell_.playAudio = !!v;
681 },
682 'desktop-notification-bell': (v) => {
683 this.bell_.showNotification = v;
Jason Linda56aa92022-09-02 13:01:49 +1000684 },
Jason Lind04bab32022-08-22 14:48:39 +1000685 'background-color': (v) => {
686 this.updateTheme_({background: v});
Jason Lin21d854f2022-08-22 14:49:59 +1000687 setHtermColorCSSVariable('background-color', v);
Jason Lind04bab32022-08-22 14:48:39 +1000688 },
Jason Lind04bab32022-08-22 14:48:39 +1000689 'color-palette-overrides': (v) => {
690 if (!(v instanceof Array)) {
691 // For terminal, we always expect this to be an array.
692 console.warn('unexpected color palette: ', v);
693 return;
694 }
695 const colors = {};
696 for (let i = 0; i < v.length; ++i) {
697 colors[ANSI_COLOR_NAMES[i]] = v[i];
698 }
699 this.updateTheme_(colors);
700 },
Jason Linda56aa92022-09-02 13:01:49 +1000701 'cursor-blink': (v) => this.updateOption_('cursorBlink', v, false),
702 'cursor-color': (v) => this.updateTheme_({cursor: v}),
703 'cursor-shape': (v) => {
704 let shape;
705 if (v === 'BEAM') {
706 shape = 'bar';
707 } else {
708 shape = v.toLowerCase();
709 }
710 this.updateOption_('cursorStyle', shape, false);
711 },
712 'font-family': (v) => this.updateFont_(v),
713 'foreground-color': (v) => {
Jason Lin461ca562022-09-07 13:53:08 +1000714 this.updateTheme_({foreground: v});
Jason Linda56aa92022-09-02 13:01:49 +1000715 setHtermColorCSSVariable('foreground-color', v);
716 },
Jason Linc48f7432022-10-13 17:28:30 +1100717 'line-height': (v) => this.updateOption_('lineHeight', v, true),
Jason Lin446f3d92022-10-13 17:34:21 +1100718 'scroll-on-output': (v) => {
719 if (!v) {
720 this.scrollOnOutputListener_?.dispose();
721 this.scrollOnOutputListener_ = null;
722 return;
723 }
724 if (!this.scrollOnOutputListener_) {
725 this.scrollOnOutputListener_ = this.term.onWriteParsed(
726 () => this.term.scrollToBottom());
727 }
728 },
Jason Lind04bab32022-08-22 14:48:39 +1000729 });
Jason Lin5690e752022-08-30 15:36:45 +1000730
731 for (const name of ['keybindings-os-defaults', 'pass-ctrl-n', 'pass-ctrl-t',
732 'pass-ctrl-w', 'pass-ctrl-tab', 'pass-ctrl-number', 'pass-alt-number',
733 'ctrl-plus-minus-zero-zoom', 'ctrl-c-copy', 'ctrl-v-paste']) {
734 this.prefs_.addObserver(name, this.scheduleResetKeyDownHandlers_);
735 }
Jason Lind04bab32022-08-22 14:48:39 +1000736 }
737
738 /**
Jason Linc2504ae2022-09-02 13:03:31 +1000739 * Fit the terminal to the containing HTML element.
740 */
741 fit_() {
742 if (!this.inited_) {
743 return;
744 }
745
746 const screenPaddingSize = /** @type {number} */(
747 this.prefs_.get('screen-padding-size'));
748
749 const calc = (size, cellSize) => {
750 return Math.floor((size - 2 * screenPaddingSize) / cellSize);
751 };
752
Jason Lin2649da22022-10-12 10:16:44 +1100753 const cellDimensions = this.xtermInternal_.getActualCellDimensions();
754 const cols = calc(this.container_.offsetWidth, cellDimensions.width);
755 const rows = calc(this.container_.offsetHeight, cellDimensions.height);
Jason Linc2504ae2022-09-02 13:03:31 +1000756 if (cols >= 0 && rows >= 0) {
757 this.term.resize(cols, rows);
758 }
759 }
760
761 /**
Jason Lind04bab32022-08-22 14:48:39 +1000762 * @param {!Object} theme
763 */
764 updateTheme_(theme) {
Jason Lin8de3d282022-09-01 21:29:05 +1000765 const updateTheme = (target) => {
766 for (const [key, value] of Object.entries(theme)) {
767 target[key] = lib.colors.normalizeCSS(value);
768 }
769 };
770
771 // Must use a new theme object to trigger re-render if we have initialized.
772 if (this.inited_) {
773 const newTheme = {...this.term.options.theme};
774 updateTheme(newTheme);
775 this.term.options.theme = newTheme;
776 return;
Jason Lind04bab32022-08-22 14:48:39 +1000777 }
Jason Lin8de3d282022-09-01 21:29:05 +1000778
779 updateTheme(this.term.options.theme);
Jason Lind04bab32022-08-22 14:48:39 +1000780 }
781
782 /**
Jason Linda56aa92022-09-02 13:01:49 +1000783 * Update one xterm.js option. Use updateTheme_()/updateFont_() for
784 * theme/font.
Jason Lind04bab32022-08-22 14:48:39 +1000785 *
786 * @param {string} key
787 * @param {*} value
Jason Linda56aa92022-09-02 13:01:49 +1000788 * @param {boolean} scheduleFit
Jason Lind04bab32022-08-22 14:48:39 +1000789 */
Jason Linda56aa92022-09-02 13:01:49 +1000790 updateOption_(key, value, scheduleFit) {
Jason Lind04bab32022-08-22 14:48:39 +1000791 // TODO: xterm supports updating multiple options at the same time. We
792 // should probably do that.
793 this.term.options[key] = value;
Jason Linda56aa92022-09-02 13:01:49 +1000794 if (scheduleFit) {
795 this.scheduleFit_();
796 }
Jason Lind04bab32022-08-22 14:48:39 +1000797 }
Jason Linabad7562022-08-22 14:49:05 +1000798
799 /**
800 * Called when there is a "fontloadingdone" event. We need this because
801 * `FontManager.loadFont()` does not guarantee loading all the font files.
802 */
803 async onFontLoadingDone_() {
804 // If there is a pending font, the font is going to be refresh soon, so we
805 // don't need to do anything.
Jason Lin8de3d282022-09-01 21:29:05 +1000806 if (this.inited_ && !this.pendingFont_) {
Jason Linabad7562022-08-22 14:49:05 +1000807 this.scheduleRefreshFont_();
808 }
809 }
810
Jason Lin5690e752022-08-30 15:36:45 +1000811 copySelection_() {
Jason Line9231bc2022-09-01 13:54:02 +1000812 this.copyString_(this.term.getSelection());
813 }
814
815 /** @param {string} data */
816 copyString_(data) {
817 if (!data) {
Jason Lin6a402a72022-08-25 16:07:02 +1000818 return;
819 }
Jason Line9231bc2022-09-01 13:54:02 +1000820 navigator.clipboard?.writeText(data);
Jason Lin83ef5ba2022-10-13 17:40:30 +1100821
822 if (this.prefs_.get('enable-clipboard-notice')) {
823 if (!this.copyNotice_) {
824 this.copyNotice_ = document.createElement('terminal-copy-notice');
825 }
826 setTimeout(() => this.showOverlay(lib.notNull(this.copyNotice_), 500),
827 200);
Jason Lin6a402a72022-08-25 16:07:02 +1000828 }
Jason Lin6a402a72022-08-25 16:07:02 +1000829 }
830
Jason Linabad7562022-08-22 14:49:05 +1000831 /**
832 * Refresh xterm rendering for a font related event.
833 */
834 refreshFont_() {
835 // We have to set the fontFamily option to a different string to trigger the
836 // re-rendering. Appending a space at the end seems to be the easiest
837 // solution. Note that `clearTextureAtlas()` and `refresh()` do not work for
838 // us.
839 //
840 // TODO: Report a bug to xterm.js and ask for exposing a public function for
841 // the refresh so that we don't need to do this hack.
842 this.term.options.fontFamily += ' ';
843 }
844
845 /**
846 * Update a font.
847 *
848 * @param {string} cssFontFamily
849 */
850 async updateFont_(cssFontFamily) {
Jason Lin6a402a72022-08-25 16:07:02 +1000851 this.pendingFont_ = cssFontFamily;
852 await this.fontManager_.loadFont(cssFontFamily);
853 // Sleep a bit to wait for flushing fontloadingdone events. This is not
854 // strictly necessary, but it should prevent `this.onFontLoadingDone_()`
855 // to refresh font unnecessarily in some cases.
856 await sleep(30);
Jason Linabad7562022-08-22 14:49:05 +1000857
Jason Lin6a402a72022-08-25 16:07:02 +1000858 if (this.pendingFont_ !== cssFontFamily) {
859 // `updateFont_()` probably is called again. Abort what we are doing.
860 console.log(`pendingFont_ (${this.pendingFont_}) is changed` +
861 ` (expecting ${cssFontFamily})`);
862 return;
863 }
Jason Linabad7562022-08-22 14:49:05 +1000864
Jason Lin6a402a72022-08-25 16:07:02 +1000865 if (this.term.options.fontFamily !== cssFontFamily) {
866 this.term.options.fontFamily = cssFontFamily;
867 } else {
868 // If the font is already the same, refresh font just to be safe.
869 this.refreshFont_();
870 }
871 this.pendingFont_ = null;
872 this.scheduleFit_();
Jason Linabad7562022-08-22 14:49:05 +1000873 }
Jason Lin5690e752022-08-30 15:36:45 +1000874
875 /**
876 * @param {!KeyboardEvent} ev
877 * @return {boolean} Return false if xterm.js should not handle the key event.
878 */
879 customKeyEventHandler_(ev) {
880 const modifiers = (ev.shiftKey ? Modifier.Shift : 0) |
881 (ev.altKey ? Modifier.Alt : 0) |
882 (ev.ctrlKey ? Modifier.Ctrl : 0) |
883 (ev.metaKey ? Modifier.Meta : 0);
884 const handler = this.keyDownHandlers_.get(
885 encodeKeyCombo(modifiers, ev.keyCode));
886 if (handler) {
887 if (ev.type === 'keydown') {
888 handler(ev);
889 }
890 return false;
891 }
892
893 return true;
894 }
895
896 /**
897 * A keydown handler for zoom-related keys.
898 *
899 * @param {!KeyboardEvent} ev
900 */
901 zoomKeyDownHandler_(ev) {
902 ev.preventDefault();
903
904 if (this.prefs_.get('ctrl-plus-minus-zero-zoom') === ev.shiftKey) {
905 // The only one with a control code.
906 if (ev.keyCode === keyCodes.MINUS) {
907 this.io.onVTKeystroke('\x1f');
908 }
909 return;
910 }
911
912 let newFontSize;
913 switch (ev.keyCode) {
914 case keyCodes.ZERO:
915 newFontSize = this.prefs_.get('font-size');
916 break;
917 case keyCodes.MINUS:
918 newFontSize = this.term.options.fontSize - 1;
919 break;
920 default:
921 newFontSize = this.term.options.fontSize + 1;
922 break;
923 }
924
Jason Linda56aa92022-09-02 13:01:49 +1000925 this.updateOption_('fontSize', Math.max(1, newFontSize), true);
Jason Lin5690e752022-08-30 15:36:45 +1000926 }
927
928 /** @param {!KeyboardEvent} ev */
929 ctrlCKeyDownHandler_(ev) {
930 ev.preventDefault();
931 if (this.prefs_.get('ctrl-c-copy') !== ev.shiftKey &&
932 this.term.hasSelection()) {
933 this.copySelection_();
934 return;
935 }
936
937 this.io.onVTKeystroke('\x03');
938 }
939
940 /** @param {!KeyboardEvent} ev */
941 ctrlVKeyDownHandler_(ev) {
942 if (this.prefs_.get('ctrl-v-paste') !== ev.shiftKey) {
943 // Don't do anything and let the browser handles the key.
944 return;
945 }
946
947 ev.preventDefault();
948 this.io.onVTKeystroke('\x16');
949 }
950
951 resetKeyDownHandlers_() {
952 this.keyDownHandlers_.clear();
953
954 /**
955 * Don't do anything and let the browser handles the key.
956 *
957 * @param {!KeyboardEvent} ev
958 */
959 const noop = (ev) => {};
960
961 /**
962 * @param {number} modifiers
963 * @param {number} keyCode
964 * @param {function(!KeyboardEvent)} func
965 */
966 const set = (modifiers, keyCode, func) => {
967 this.keyDownHandlers_.set(encodeKeyCombo(modifiers, keyCode),
968 func);
969 };
970
971 /**
972 * @param {number} modifiers
973 * @param {number} keyCode
974 * @param {function(!KeyboardEvent)} func
975 */
976 const setWithShiftVersion = (modifiers, keyCode, func) => {
977 set(modifiers, keyCode, func);
978 set(modifiers | Modifier.Shift, keyCode, func);
979 };
980
Jason Lin5690e752022-08-30 15:36:45 +1000981 // Ctrl+/
982 set(Modifier.Ctrl, 191, (ev) => {
983 ev.preventDefault();
984 this.io.onVTKeystroke(ctl('_'));
985 });
986
987 // Settings page.
988 set(Modifier.Ctrl | Modifier.Shift, keyCodes.P, (ev) => {
989 ev.preventDefault();
990 chrome.terminalPrivate.openOptionsPage(() => {});
991 });
992
993 if (this.prefs_.get('keybindings-os-defaults')) {
994 for (const binding of OS_DEFAULT_BINDINGS) {
995 this.keyDownHandlers_.set(binding, noop);
996 }
997 }
998
999 /** @param {!KeyboardEvent} ev */
1000 const newWindow = (ev) => {
1001 ev.preventDefault();
1002 chrome.terminalPrivate.openWindow();
1003 };
1004 set(Modifier.Ctrl | Modifier.Shift, keyCodes.N, newWindow);
1005 if (this.prefs_.get('pass-ctrl-n')) {
1006 set(Modifier.Ctrl, keyCodes.N, newWindow);
1007 }
1008
1009 if (this.prefs_.get('pass-ctrl-t')) {
1010 setWithShiftVersion(Modifier.Ctrl, keyCodes.T, noop);
1011 }
1012
1013 if (this.prefs_.get('pass-ctrl-w')) {
1014 setWithShiftVersion(Modifier.Ctrl, keyCodes.W, noop);
1015 }
1016
1017 if (this.prefs_.get('pass-ctrl-tab')) {
1018 setWithShiftVersion(Modifier.Ctrl, keyCodes.TAB, noop);
1019 }
1020
1021 const passCtrlNumber = this.prefs_.get('pass-ctrl-number');
1022
1023 /**
1024 * Set a handler for the key combo ctrl+<number>.
1025 *
1026 * @param {number} number 1 to 9
1027 * @param {string} controlCode The control code to send if we don't want to
1028 * let the browser to handle it.
1029 */
1030 const setCtrlNumberHandler = (number, controlCode) => {
1031 let func = noop;
1032 if (!passCtrlNumber) {
1033 func = (ev) => {
1034 ev.preventDefault();
1035 this.io.onVTKeystroke(controlCode);
1036 };
1037 }
1038 set(Modifier.Ctrl, keyCodes.ZERO + number, func);
1039 };
1040
1041 setCtrlNumberHandler(1, '1');
1042 setCtrlNumberHandler(2, ctl('@'));
1043 setCtrlNumberHandler(3, ctl('['));
1044 setCtrlNumberHandler(4, ctl('\\'));
1045 setCtrlNumberHandler(5, ctl(']'));
1046 setCtrlNumberHandler(6, ctl('^'));
1047 setCtrlNumberHandler(7, ctl('_'));
1048 setCtrlNumberHandler(8, '\x7f');
1049 setCtrlNumberHandler(9, '9');
1050
1051 if (this.prefs_.get('pass-alt-number')) {
1052 for (let keyCode = keyCodes.ZERO; keyCode <= keyCodes.NINE; ++keyCode) {
1053 set(Modifier.Alt, keyCode, noop);
1054 }
1055 }
1056
1057 for (const keyCode of [keyCodes.ZERO, keyCodes.MINUS, keyCodes.EQUAL]) {
1058 setWithShiftVersion(Modifier.Ctrl, keyCode, this.zoomKeyDownHandler_);
1059 }
1060
1061 setWithShiftVersion(Modifier.Ctrl, keyCodes.C, this.ctrlCKeyDownHandler_);
1062 setWithShiftVersion(Modifier.Ctrl, keyCodes.V, this.ctrlVKeyDownHandler_);
1063 }
Jason Linca61ffb2022-08-03 19:37:12 +10001064}
1065
Jason Lind66e6bf2022-08-22 14:47:10 +10001066class HtermTerminal extends hterm.Terminal {
1067 /** @override */
1068 decorate(div) {
1069 super.decorate(div);
1070
Jason Linc48f7432022-10-13 17:28:30 +11001071 definePrefs(this.getPrefs());
1072
Jason Lind66e6bf2022-08-22 14:47:10 +10001073 const fontManager = new FontManager(this.getDocument());
1074 fontManager.loadPowerlineCSS().then(() => {
1075 const prefs = this.getPrefs();
1076 fontManager.loadFont(/** @type {string} */(prefs.get('font-family')));
1077 prefs.addObserver(
1078 'font-family',
1079 (v) => fontManager.loadFont(/** @type {string} */(v)));
1080 });
1081 }
Jason Lin2649da22022-10-12 10:16:44 +11001082
1083 /**
1084 * Write data to the terminal.
1085 *
1086 * @param {string|!Uint8Array} data string for UTF-16 data, Uint8Array for
1087 * UTF-8 data
1088 * @param {function()=} callback Optional callback that fires when the data
1089 * was processed by the parser.
1090 */
1091 write(data, callback) {
1092 if (typeof data === 'string') {
1093 this.io.print(data);
1094 } else {
1095 this.io.writeUTF8(data);
1096 }
1097 // Hterm processes the data synchronously, so we can call the callback
1098 // immediately.
1099 if (callback) {
1100 setTimeout(callback);
1101 }
1102 }
Jason Lind66e6bf2022-08-22 14:47:10 +10001103}
1104
Jason Linca61ffb2022-08-03 19:37:12 +10001105/**
1106 * Constructs and returns a `hterm.Terminal` or a compatible one based on the
1107 * preference value.
1108 *
1109 * @param {{
1110 * storage: !lib.Storage,
1111 * profileId: string,
1112 * }} args
1113 * @return {!Promise<!hterm.Terminal>}
1114 */
1115export async function createEmulator({storage, profileId}) {
1116 let config = TERMINAL_EMULATORS.get('hterm');
1117
1118 if (getOSInfo().alternative_emulator) {
Jason Lin21d854f2022-08-22 14:49:59 +10001119 // TODO: remove the url param logic. This is temporary to make manual
1120 // testing a bit easier, which is also why this is not in
1121 // './js/terminal_info.js'.
1122 const emulator = ORIGINAL_URL.searchParams.get('emulator') ||
1123 await storage.getItem(`/hterm/profiles/${profileId}/terminal-emulator`);
Jason Linca61ffb2022-08-03 19:37:12 +10001124 // Use the default (i.e. first) one if the pref is not set or invalid.
Jason Lin21d854f2022-08-22 14:49:59 +10001125 config = TERMINAL_EMULATORS.get(emulator) ||
Jason Linca61ffb2022-08-03 19:37:12 +10001126 TERMINAL_EMULATORS.values().next().value;
1127 console.log('Terminal emulator config: ', config);
1128 }
1129
1130 switch (config.lib) {
1131 case 'xterm.js':
1132 {
1133 const terminal = new XtermTerminal({
1134 storage,
1135 profileId,
1136 enableWebGL: config.webgl,
1137 });
Jason Linca61ffb2022-08-03 19:37:12 +10001138 return terminal;
1139 }
1140 case 'hterm':
Jason Lind66e6bf2022-08-22 14:47:10 +10001141 return new HtermTerminal({profileId, storage});
Jason Linca61ffb2022-08-03 19:37:12 +10001142 default:
1143 throw new Error('incorrect emulator config');
1144 }
1145}
1146
Jason Lin6a402a72022-08-25 16:07:02 +10001147class TerminalCopyNotice extends LitElement {
1148 /** @override */
1149 static get styles() {
1150 return css`
1151 :host {
1152 display: block;
1153 text-align: center;
1154 }
1155
1156 svg {
1157 fill: currentColor;
1158 }
1159 `;
1160 }
1161
1162 /** @override */
Jason Lind3aacef2022-10-12 19:03:37 +11001163 connectedCallback() {
1164 super.connectedCallback();
1165 if (!this.childNodes.length) {
1166 // This is not visible since we use shadow dom. But this will allow the
1167 // hterm.NotificationCenter to announce the the copy text.
1168 this.append(hterm.messageManager.get('HTERM_NOTIFY_COPY'));
1169 }
1170 }
1171
1172 /** @override */
Jason Lin6a402a72022-08-25 16:07:02 +10001173 render() {
1174 return html`
1175 ${ICON_COPY}
1176 <div>${hterm.messageManager.get('HTERM_NOTIFY_COPY')}</div>
1177 `;
1178 }
1179}
1180
1181customElements.define('terminal-copy-notice', TerminalCopyNotice);