blob: 31db963141e3eb7854ba9aa92de78722c07f05b3 [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 = [
Joel Hockeyb89a9782022-10-16 22:00:12 -0700473 'eraseLine',
Jason Linca61ffb2022-08-03 19:37:12 +1000474 'setBackgroundImage',
Joel Hockeyb89a9782022-10-16 22:00:12 -0700475 'setCursorColumn',
Jason Linca61ffb2022-08-03 19:37:12 +1000476 'setCursorPosition',
477 'setCursorVisible',
Jason Linca61ffb2022-08-03 19:37:12 +1000478 ];
479
480 for (const name of methodNames) {
481 this[name] = () => console.warn(`${name}() is not implemented`);
482 }
483
484 this.contextMenu = {
485 setItems: () => {
486 console.warn('.contextMenu.setItems() is not implemented');
487 },
488 };
Jason Lin21d854f2022-08-22 14:49:59 +1000489
490 this.vt = {
491 resetParseState: () => {
492 console.warn('.vt.resetParseState() is not implemented');
493 },
494 };
Jason Linca61ffb2022-08-03 19:37:12 +1000495 }
496
Jason Line9231bc2022-09-01 13:54:02 +1000497 installEscapeSequenceHandlers_() {
498 // OSC 52 for copy.
499 this.term.parser.registerOscHandler(52, (args) => {
500 // Args comes in as a single 'clipboard;b64-data' string. The clipboard
501 // parameter is used to select which of the X clipboards to address. Since
502 // we're not integrating with X, we treat them all the same.
503 const parsedArgs = args.match(/^[cps01234567]*;(.*)/);
504 if (!parsedArgs) {
505 return true;
506 }
507
508 let data;
509 try {
510 data = window.atob(parsedArgs[1]);
511 } catch (e) {
512 // If the user sent us invalid base64 content, silently ignore it.
513 return true;
514 }
515 const decoder = new TextDecoder();
516 const bytes = lib.codec.stringToCodeUnitArray(data);
517 this.copyString_(decoder.decode(bytes));
518
519 return true;
520 });
Jason Lin2649da22022-10-12 10:16:44 +1100521
522 this.xtermInternal_.installTmuxControlModeHandler(
523 (data) => this.onTmuxControlModeLine(data));
524 this.xtermInternal_.installEscKHandler();
Jason Line9231bc2022-09-01 13:54:02 +1000525 }
526
Jason Linca61ffb2022-08-03 19:37:12 +1000527 /**
Jason Lin21d854f2022-08-22 14:49:59 +1000528 * Write data to the terminal.
529 *
530 * @param {string|!Uint8Array} data string for UTF-16 data, Uint8Array for
531 * UTF-8 data
Jason Lin2649da22022-10-12 10:16:44 +1100532 * @param {function()=} callback Optional callback that fires when the data
533 * was processed by the parser.
Jason Lin21d854f2022-08-22 14:49:59 +1000534 */
Jason Lin2649da22022-10-12 10:16:44 +1100535 write(data, callback) {
536 this.term.write(data, callback);
Jason Lin21d854f2022-08-22 14:49:59 +1000537 }
538
539 /**
540 * Like `this.write()` but also write a line break.
541 *
542 * @param {string|!Uint8Array} data
Jason Lin2649da22022-10-12 10:16:44 +1100543 * @param {function()=} callback Optional callback that fires when the data
544 * was processed by the parser.
Jason Lin21d854f2022-08-22 14:49:59 +1000545 */
Jason Lin2649da22022-10-12 10:16:44 +1100546 writeln(data, callback) {
547 this.term.writeln(data, callback);
Jason Lin21d854f2022-08-22 14:49:59 +1000548 }
549
Jason Linca61ffb2022-08-03 19:37:12 +1000550 get screenSize() {
551 return new hterm.Size(this.term.cols, this.term.rows);
552 }
553
554 /**
555 * Don't need to do anything.
556 *
557 * @override
558 */
559 installKeyboard() {}
560
561 /**
562 * @override
563 */
564 decorate(elem) {
Jason Linc2504ae2022-09-02 13:03:31 +1000565 this.container_ = elem;
Jason Lin8de3d282022-09-01 21:29:05 +1000566 (async () => {
567 await new Promise((resolve) => this.prefs_.readStorage(resolve));
568 // This will trigger all the observers to set the terminal options before
569 // we call `this.term.open()`.
570 this.prefs_.notifyAll();
571
Jason Linc2504ae2022-09-02 13:03:31 +1000572 const screenPaddingSize = /** @type {number} */(
573 this.prefs_.get('screen-padding-size'));
574 elem.style.paddingTop = elem.style.paddingLeft = `${screenPaddingSize}px`;
575
Jason Lin8de3d282022-09-01 21:29:05 +1000576 this.inited_ = true;
577 this.term.open(elem);
578
Jason Lin8de3d282022-09-01 21:29:05 +1000579 if (this.enableWebGL_) {
580 this.term.loadAddon(new WebglAddon());
581 }
582 this.term.focus();
583 (new ResizeObserver(() => this.scheduleFit_())).observe(elem);
Jason Lind3aacef2022-10-12 19:03:37 +1100584 this.htermA11yReader_ = new hterm.AccessibilityReader(elem);
585 this.notificationCenter_ = new hterm.NotificationCenter(document.body,
586 this.htermA11yReader_);
Jason Lin8de3d282022-09-01 21:29:05 +1000587
Emil Mikulic2a194d02022-09-29 14:30:59 +1000588 // Block right-click context menu from popping up.
589 elem.addEventListener('contextmenu', (e) => e.preventDefault());
590
591 // Add a handler for pasting with the mouse.
592 elem.addEventListener('mousedown', async (e) => {
593 if (this.term.modes.mouseTrackingMode !== 'none') {
594 // xterm.js is in mouse mode and will handle the event.
595 return;
596 }
597 const MIDDLE = 1;
598 const RIGHT = 2;
599 if (e.button === MIDDLE || (e.button === RIGHT &&
600 this.prefs_.getBoolean('mouse-right-click-paste'))) {
601 // Paste.
602 if (navigator.clipboard && navigator.clipboard.readText) {
603 const text = await navigator.clipboard.readText();
604 this.term.paste(text);
605 }
606 }
607 });
608
Jason Lin2649da22022-10-12 10:16:44 +1100609 await this.scheduleFit_();
Jason Lind3aacef2022-10-12 19:03:37 +1100610 this.a11yButtons_ = new A11yButtons(this.term, elem);
611
Jason Lin8de3d282022-09-01 21:29:05 +1000612 this.onTerminalReady();
613 })();
Jason Lin21d854f2022-08-22 14:49:59 +1000614 }
615
616 /** @override */
617 showOverlay(msg, timeout = 1500) {
Jason Lin34a45322022-10-12 19:10:52 +1100618 this.notificationCenter_?.show(msg, {timeout});
Jason Lin21d854f2022-08-22 14:49:59 +1000619 }
620
621 /** @override */
622 hideOverlay() {
Jason Lin34a45322022-10-12 19:10:52 +1100623 this.notificationCenter_?.hide();
Jason Linca61ffb2022-08-03 19:37:12 +1000624 }
625
626 /** @override */
627 getPrefs() {
628 return this.prefs_;
629 }
630
631 /** @override */
632 getDocument() {
633 return window.document;
634 }
635
Jason Lin21d854f2022-08-22 14:49:59 +1000636 /** @override */
637 reset() {
638 this.term.reset();
Jason Linca61ffb2022-08-03 19:37:12 +1000639 }
640
641 /** @override */
Jason Lin21d854f2022-08-22 14:49:59 +1000642 setProfile(profileId, callback = undefined) {
643 this.prefs_.setProfile(profileId, callback);
Jason Linca61ffb2022-08-03 19:37:12 +1000644 }
645
Jason Lin21d854f2022-08-22 14:49:59 +1000646 /** @override */
647 interpret(string) {
648 this.term.write(string);
Jason Linca61ffb2022-08-03 19:37:12 +1000649 }
650
Jason Lin21d854f2022-08-22 14:49:59 +1000651 /** @override */
652 focus() {
653 this.term.focus();
654 }
Jason Linca61ffb2022-08-03 19:37:12 +1000655
656 /** @override */
657 onOpenOptionsPage() {}
658
659 /** @override */
660 onTerminalReady() {}
661
Jason Lind04bab32022-08-22 14:48:39 +1000662 observePrefs_() {
Jason Lin21d854f2022-08-22 14:49:59 +1000663 // This is for this.notificationCenter_.
664 const setHtermCSSVariable = (name, value) => {
665 document.body.style.setProperty(`--hterm-${name}`, value);
666 };
667
668 const setHtermColorCSSVariable = (name, color) => {
669 const css = lib.notNull(lib.colors.normalizeCSS(color));
670 const rgb = lib.colors.crackRGB(css).slice(0, 3).join(',');
671 setHtermCSSVariable(name, rgb);
672 };
673
674 this.prefs_.addObserver('font-size', (v) => {
Jason Linda56aa92022-09-02 13:01:49 +1000675 this.updateOption_('fontSize', v, true);
Jason Lin21d854f2022-08-22 14:49:59 +1000676 setHtermCSSVariable('font-size', `${v}px`);
677 });
678
Jason Linda56aa92022-09-02 13:01:49 +1000679 // TODO(lxj): support option "lineHeight", "scrollback".
Jason Lind04bab32022-08-22 14:48:39 +1000680 this.prefs_.addObservers(null, {
Jason Linda56aa92022-09-02 13:01:49 +1000681 'audible-bell-sound': (v) => {
Jason Linc7afb672022-10-11 15:54:17 +1100682 this.bell_.playAudio = !!v;
683 },
684 'desktop-notification-bell': (v) => {
685 this.bell_.showNotification = v;
Jason Linda56aa92022-09-02 13:01:49 +1000686 },
Jason Lind04bab32022-08-22 14:48:39 +1000687 'background-color': (v) => {
688 this.updateTheme_({background: v});
Jason Lin21d854f2022-08-22 14:49:59 +1000689 setHtermColorCSSVariable('background-color', v);
Jason Lind04bab32022-08-22 14:48:39 +1000690 },
Jason Lind04bab32022-08-22 14:48:39 +1000691 'color-palette-overrides': (v) => {
692 if (!(v instanceof Array)) {
693 // For terminal, we always expect this to be an array.
694 console.warn('unexpected color palette: ', v);
695 return;
696 }
697 const colors = {};
698 for (let i = 0; i < v.length; ++i) {
699 colors[ANSI_COLOR_NAMES[i]] = v[i];
700 }
701 this.updateTheme_(colors);
702 },
Jason Linda56aa92022-09-02 13:01:49 +1000703 'cursor-blink': (v) => this.updateOption_('cursorBlink', v, false),
704 'cursor-color': (v) => this.updateTheme_({cursor: v}),
705 'cursor-shape': (v) => {
706 let shape;
707 if (v === 'BEAM') {
708 shape = 'bar';
709 } else {
710 shape = v.toLowerCase();
711 }
712 this.updateOption_('cursorStyle', shape, false);
713 },
714 'font-family': (v) => this.updateFont_(v),
715 'foreground-color': (v) => {
Jason Lin461ca562022-09-07 13:53:08 +1000716 this.updateTheme_({foreground: v});
Jason Linda56aa92022-09-02 13:01:49 +1000717 setHtermColorCSSVariable('foreground-color', v);
718 },
Jason Linc48f7432022-10-13 17:28:30 +1100719 'line-height': (v) => this.updateOption_('lineHeight', v, true),
Jason Lin446f3d92022-10-13 17:34:21 +1100720 'scroll-on-output': (v) => {
721 if (!v) {
722 this.scrollOnOutputListener_?.dispose();
723 this.scrollOnOutputListener_ = null;
724 return;
725 }
726 if (!this.scrollOnOutputListener_) {
727 this.scrollOnOutputListener_ = this.term.onWriteParsed(
728 () => this.term.scrollToBottom());
729 }
730 },
Jason Lind04bab32022-08-22 14:48:39 +1000731 });
Jason Lin5690e752022-08-30 15:36:45 +1000732
733 for (const name of ['keybindings-os-defaults', 'pass-ctrl-n', 'pass-ctrl-t',
734 'pass-ctrl-w', 'pass-ctrl-tab', 'pass-ctrl-number', 'pass-alt-number',
735 'ctrl-plus-minus-zero-zoom', 'ctrl-c-copy', 'ctrl-v-paste']) {
736 this.prefs_.addObserver(name, this.scheduleResetKeyDownHandlers_);
737 }
Jason Lind04bab32022-08-22 14:48:39 +1000738 }
739
740 /**
Jason Linc2504ae2022-09-02 13:03:31 +1000741 * Fit the terminal to the containing HTML element.
742 */
743 fit_() {
744 if (!this.inited_) {
745 return;
746 }
747
748 const screenPaddingSize = /** @type {number} */(
749 this.prefs_.get('screen-padding-size'));
750
751 const calc = (size, cellSize) => {
752 return Math.floor((size - 2 * screenPaddingSize) / cellSize);
753 };
754
Jason Lin2649da22022-10-12 10:16:44 +1100755 const cellDimensions = this.xtermInternal_.getActualCellDimensions();
756 const cols = calc(this.container_.offsetWidth, cellDimensions.width);
757 const rows = calc(this.container_.offsetHeight, cellDimensions.height);
Jason Linc2504ae2022-09-02 13:03:31 +1000758 if (cols >= 0 && rows >= 0) {
759 this.term.resize(cols, rows);
760 }
761 }
762
763 /**
Jason Lind04bab32022-08-22 14:48:39 +1000764 * @param {!Object} theme
765 */
766 updateTheme_(theme) {
Jason Lin8de3d282022-09-01 21:29:05 +1000767 const updateTheme = (target) => {
768 for (const [key, value] of Object.entries(theme)) {
769 target[key] = lib.colors.normalizeCSS(value);
770 }
771 };
772
773 // Must use a new theme object to trigger re-render if we have initialized.
774 if (this.inited_) {
775 const newTheme = {...this.term.options.theme};
776 updateTheme(newTheme);
777 this.term.options.theme = newTheme;
778 return;
Jason Lind04bab32022-08-22 14:48:39 +1000779 }
Jason Lin8de3d282022-09-01 21:29:05 +1000780
781 updateTheme(this.term.options.theme);
Jason Lind04bab32022-08-22 14:48:39 +1000782 }
783
784 /**
Jason Linda56aa92022-09-02 13:01:49 +1000785 * Update one xterm.js option. Use updateTheme_()/updateFont_() for
786 * theme/font.
Jason Lind04bab32022-08-22 14:48:39 +1000787 *
788 * @param {string} key
789 * @param {*} value
Jason Linda56aa92022-09-02 13:01:49 +1000790 * @param {boolean} scheduleFit
Jason Lind04bab32022-08-22 14:48:39 +1000791 */
Jason Linda56aa92022-09-02 13:01:49 +1000792 updateOption_(key, value, scheduleFit) {
Jason Lind04bab32022-08-22 14:48:39 +1000793 // TODO: xterm supports updating multiple options at the same time. We
794 // should probably do that.
795 this.term.options[key] = value;
Jason Linda56aa92022-09-02 13:01:49 +1000796 if (scheduleFit) {
797 this.scheduleFit_();
798 }
Jason Lind04bab32022-08-22 14:48:39 +1000799 }
Jason Linabad7562022-08-22 14:49:05 +1000800
801 /**
802 * Called when there is a "fontloadingdone" event. We need this because
803 * `FontManager.loadFont()` does not guarantee loading all the font files.
804 */
805 async onFontLoadingDone_() {
806 // If there is a pending font, the font is going to be refresh soon, so we
807 // don't need to do anything.
Jason Lin8de3d282022-09-01 21:29:05 +1000808 if (this.inited_ && !this.pendingFont_) {
Jason Linabad7562022-08-22 14:49:05 +1000809 this.scheduleRefreshFont_();
810 }
811 }
812
Jason Lin5690e752022-08-30 15:36:45 +1000813 copySelection_() {
Jason Line9231bc2022-09-01 13:54:02 +1000814 this.copyString_(this.term.getSelection());
815 }
816
817 /** @param {string} data */
818 copyString_(data) {
819 if (!data) {
Jason Lin6a402a72022-08-25 16:07:02 +1000820 return;
821 }
Jason Line9231bc2022-09-01 13:54:02 +1000822 navigator.clipboard?.writeText(data);
Jason Lin83ef5ba2022-10-13 17:40:30 +1100823
824 if (this.prefs_.get('enable-clipboard-notice')) {
825 if (!this.copyNotice_) {
826 this.copyNotice_ = document.createElement('terminal-copy-notice');
827 }
828 setTimeout(() => this.showOverlay(lib.notNull(this.copyNotice_), 500),
829 200);
Jason Lin6a402a72022-08-25 16:07:02 +1000830 }
Jason Lin6a402a72022-08-25 16:07:02 +1000831 }
832
Jason Linabad7562022-08-22 14:49:05 +1000833 /**
834 * Refresh xterm rendering for a font related event.
835 */
836 refreshFont_() {
837 // We have to set the fontFamily option to a different string to trigger the
838 // re-rendering. Appending a space at the end seems to be the easiest
839 // solution. Note that `clearTextureAtlas()` and `refresh()` do not work for
840 // us.
841 //
842 // TODO: Report a bug to xterm.js and ask for exposing a public function for
843 // the refresh so that we don't need to do this hack.
844 this.term.options.fontFamily += ' ';
845 }
846
847 /**
848 * Update a font.
849 *
850 * @param {string} cssFontFamily
851 */
852 async updateFont_(cssFontFamily) {
Jason Lin6a402a72022-08-25 16:07:02 +1000853 this.pendingFont_ = cssFontFamily;
854 await this.fontManager_.loadFont(cssFontFamily);
855 // Sleep a bit to wait for flushing fontloadingdone events. This is not
856 // strictly necessary, but it should prevent `this.onFontLoadingDone_()`
857 // to refresh font unnecessarily in some cases.
858 await sleep(30);
Jason Linabad7562022-08-22 14:49:05 +1000859
Jason Lin6a402a72022-08-25 16:07:02 +1000860 if (this.pendingFont_ !== cssFontFamily) {
861 // `updateFont_()` probably is called again. Abort what we are doing.
862 console.log(`pendingFont_ (${this.pendingFont_}) is changed` +
863 ` (expecting ${cssFontFamily})`);
864 return;
865 }
Jason Linabad7562022-08-22 14:49:05 +1000866
Jason Lin6a402a72022-08-25 16:07:02 +1000867 if (this.term.options.fontFamily !== cssFontFamily) {
868 this.term.options.fontFamily = cssFontFamily;
869 } else {
870 // If the font is already the same, refresh font just to be safe.
871 this.refreshFont_();
872 }
873 this.pendingFont_ = null;
874 this.scheduleFit_();
Jason Linabad7562022-08-22 14:49:05 +1000875 }
Jason Lin5690e752022-08-30 15:36:45 +1000876
877 /**
878 * @param {!KeyboardEvent} ev
879 * @return {boolean} Return false if xterm.js should not handle the key event.
880 */
881 customKeyEventHandler_(ev) {
882 const modifiers = (ev.shiftKey ? Modifier.Shift : 0) |
883 (ev.altKey ? Modifier.Alt : 0) |
884 (ev.ctrlKey ? Modifier.Ctrl : 0) |
885 (ev.metaKey ? Modifier.Meta : 0);
886 const handler = this.keyDownHandlers_.get(
887 encodeKeyCombo(modifiers, ev.keyCode));
888 if (handler) {
889 if (ev.type === 'keydown') {
890 handler(ev);
891 }
892 return false;
893 }
894
895 return true;
896 }
897
898 /**
899 * A keydown handler for zoom-related keys.
900 *
901 * @param {!KeyboardEvent} ev
902 */
903 zoomKeyDownHandler_(ev) {
904 ev.preventDefault();
905
906 if (this.prefs_.get('ctrl-plus-minus-zero-zoom') === ev.shiftKey) {
907 // The only one with a control code.
908 if (ev.keyCode === keyCodes.MINUS) {
909 this.io.onVTKeystroke('\x1f');
910 }
911 return;
912 }
913
914 let newFontSize;
915 switch (ev.keyCode) {
916 case keyCodes.ZERO:
917 newFontSize = this.prefs_.get('font-size');
918 break;
919 case keyCodes.MINUS:
920 newFontSize = this.term.options.fontSize - 1;
921 break;
922 default:
923 newFontSize = this.term.options.fontSize + 1;
924 break;
925 }
926
Jason Linda56aa92022-09-02 13:01:49 +1000927 this.updateOption_('fontSize', Math.max(1, newFontSize), true);
Jason Lin5690e752022-08-30 15:36:45 +1000928 }
929
930 /** @param {!KeyboardEvent} ev */
931 ctrlCKeyDownHandler_(ev) {
932 ev.preventDefault();
933 if (this.prefs_.get('ctrl-c-copy') !== ev.shiftKey &&
934 this.term.hasSelection()) {
935 this.copySelection_();
936 return;
937 }
938
939 this.io.onVTKeystroke('\x03');
940 }
941
942 /** @param {!KeyboardEvent} ev */
943 ctrlVKeyDownHandler_(ev) {
944 if (this.prefs_.get('ctrl-v-paste') !== ev.shiftKey) {
945 // Don't do anything and let the browser handles the key.
946 return;
947 }
948
949 ev.preventDefault();
950 this.io.onVTKeystroke('\x16');
951 }
952
953 resetKeyDownHandlers_() {
954 this.keyDownHandlers_.clear();
955
956 /**
957 * Don't do anything and let the browser handles the key.
958 *
959 * @param {!KeyboardEvent} ev
960 */
961 const noop = (ev) => {};
962
963 /**
964 * @param {number} modifiers
965 * @param {number} keyCode
966 * @param {function(!KeyboardEvent)} func
967 */
968 const set = (modifiers, keyCode, func) => {
969 this.keyDownHandlers_.set(encodeKeyCombo(modifiers, keyCode),
970 func);
971 };
972
973 /**
974 * @param {number} modifiers
975 * @param {number} keyCode
976 * @param {function(!KeyboardEvent)} func
977 */
978 const setWithShiftVersion = (modifiers, keyCode, func) => {
979 set(modifiers, keyCode, func);
980 set(modifiers | Modifier.Shift, keyCode, func);
981 };
982
Jason Lin5690e752022-08-30 15:36:45 +1000983 // Ctrl+/
984 set(Modifier.Ctrl, 191, (ev) => {
985 ev.preventDefault();
986 this.io.onVTKeystroke(ctl('_'));
987 });
988
989 // Settings page.
990 set(Modifier.Ctrl | Modifier.Shift, keyCodes.P, (ev) => {
991 ev.preventDefault();
992 chrome.terminalPrivate.openOptionsPage(() => {});
993 });
994
995 if (this.prefs_.get('keybindings-os-defaults')) {
996 for (const binding of OS_DEFAULT_BINDINGS) {
997 this.keyDownHandlers_.set(binding, noop);
998 }
999 }
1000
1001 /** @param {!KeyboardEvent} ev */
1002 const newWindow = (ev) => {
1003 ev.preventDefault();
1004 chrome.terminalPrivate.openWindow();
1005 };
1006 set(Modifier.Ctrl | Modifier.Shift, keyCodes.N, newWindow);
1007 if (this.prefs_.get('pass-ctrl-n')) {
1008 set(Modifier.Ctrl, keyCodes.N, newWindow);
1009 }
1010
1011 if (this.prefs_.get('pass-ctrl-t')) {
1012 setWithShiftVersion(Modifier.Ctrl, keyCodes.T, noop);
1013 }
1014
1015 if (this.prefs_.get('pass-ctrl-w')) {
1016 setWithShiftVersion(Modifier.Ctrl, keyCodes.W, noop);
1017 }
1018
1019 if (this.prefs_.get('pass-ctrl-tab')) {
1020 setWithShiftVersion(Modifier.Ctrl, keyCodes.TAB, noop);
1021 }
1022
1023 const passCtrlNumber = this.prefs_.get('pass-ctrl-number');
1024
1025 /**
1026 * Set a handler for the key combo ctrl+<number>.
1027 *
1028 * @param {number} number 1 to 9
1029 * @param {string} controlCode The control code to send if we don't want to
1030 * let the browser to handle it.
1031 */
1032 const setCtrlNumberHandler = (number, controlCode) => {
1033 let func = noop;
1034 if (!passCtrlNumber) {
1035 func = (ev) => {
1036 ev.preventDefault();
1037 this.io.onVTKeystroke(controlCode);
1038 };
1039 }
1040 set(Modifier.Ctrl, keyCodes.ZERO + number, func);
1041 };
1042
1043 setCtrlNumberHandler(1, '1');
1044 setCtrlNumberHandler(2, ctl('@'));
1045 setCtrlNumberHandler(3, ctl('['));
1046 setCtrlNumberHandler(4, ctl('\\'));
1047 setCtrlNumberHandler(5, ctl(']'));
1048 setCtrlNumberHandler(6, ctl('^'));
1049 setCtrlNumberHandler(7, ctl('_'));
1050 setCtrlNumberHandler(8, '\x7f');
1051 setCtrlNumberHandler(9, '9');
1052
1053 if (this.prefs_.get('pass-alt-number')) {
1054 for (let keyCode = keyCodes.ZERO; keyCode <= keyCodes.NINE; ++keyCode) {
1055 set(Modifier.Alt, keyCode, noop);
1056 }
1057 }
1058
1059 for (const keyCode of [keyCodes.ZERO, keyCodes.MINUS, keyCodes.EQUAL]) {
1060 setWithShiftVersion(Modifier.Ctrl, keyCode, this.zoomKeyDownHandler_);
1061 }
1062
1063 setWithShiftVersion(Modifier.Ctrl, keyCodes.C, this.ctrlCKeyDownHandler_);
1064 setWithShiftVersion(Modifier.Ctrl, keyCodes.V, this.ctrlVKeyDownHandler_);
1065 }
Jason Linca61ffb2022-08-03 19:37:12 +10001066}
1067
Jason Lind66e6bf2022-08-22 14:47:10 +10001068class HtermTerminal extends hterm.Terminal {
1069 /** @override */
1070 decorate(div) {
1071 super.decorate(div);
1072
Jason Linc48f7432022-10-13 17:28:30 +11001073 definePrefs(this.getPrefs());
1074
Jason Lind66e6bf2022-08-22 14:47:10 +10001075 const fontManager = new FontManager(this.getDocument());
1076 fontManager.loadPowerlineCSS().then(() => {
1077 const prefs = this.getPrefs();
1078 fontManager.loadFont(/** @type {string} */(prefs.get('font-family')));
1079 prefs.addObserver(
1080 'font-family',
1081 (v) => fontManager.loadFont(/** @type {string} */(v)));
1082 });
1083 }
Jason Lin2649da22022-10-12 10:16:44 +11001084
1085 /**
1086 * Write data to the terminal.
1087 *
1088 * @param {string|!Uint8Array} data string for UTF-16 data, Uint8Array for
1089 * UTF-8 data
1090 * @param {function()=} callback Optional callback that fires when the data
1091 * was processed by the parser.
1092 */
1093 write(data, callback) {
1094 if (typeof data === 'string') {
1095 this.io.print(data);
1096 } else {
1097 this.io.writeUTF8(data);
1098 }
1099 // Hterm processes the data synchronously, so we can call the callback
1100 // immediately.
1101 if (callback) {
1102 setTimeout(callback);
1103 }
1104 }
Jason Lind66e6bf2022-08-22 14:47:10 +10001105}
1106
Jason Linca61ffb2022-08-03 19:37:12 +10001107/**
1108 * Constructs and returns a `hterm.Terminal` or a compatible one based on the
1109 * preference value.
1110 *
1111 * @param {{
1112 * storage: !lib.Storage,
1113 * profileId: string,
1114 * }} args
1115 * @return {!Promise<!hterm.Terminal>}
1116 */
1117export async function createEmulator({storage, profileId}) {
1118 let config = TERMINAL_EMULATORS.get('hterm');
1119
1120 if (getOSInfo().alternative_emulator) {
Jason Lin21d854f2022-08-22 14:49:59 +10001121 // TODO: remove the url param logic. This is temporary to make manual
1122 // testing a bit easier, which is also why this is not in
1123 // './js/terminal_info.js'.
1124 const emulator = ORIGINAL_URL.searchParams.get('emulator') ||
1125 await storage.getItem(`/hterm/profiles/${profileId}/terminal-emulator`);
Jason Linca61ffb2022-08-03 19:37:12 +10001126 // Use the default (i.e. first) one if the pref is not set or invalid.
Jason Lin21d854f2022-08-22 14:49:59 +10001127 config = TERMINAL_EMULATORS.get(emulator) ||
Jason Linca61ffb2022-08-03 19:37:12 +10001128 TERMINAL_EMULATORS.values().next().value;
1129 console.log('Terminal emulator config: ', config);
1130 }
1131
1132 switch (config.lib) {
1133 case 'xterm.js':
1134 {
1135 const terminal = new XtermTerminal({
1136 storage,
1137 profileId,
1138 enableWebGL: config.webgl,
1139 });
Jason Linca61ffb2022-08-03 19:37:12 +10001140 return terminal;
1141 }
1142 case 'hterm':
Jason Lind66e6bf2022-08-22 14:47:10 +10001143 return new HtermTerminal({profileId, storage});
Jason Linca61ffb2022-08-03 19:37:12 +10001144 default:
1145 throw new Error('incorrect emulator config');
1146 }
1147}
1148
Jason Lin6a402a72022-08-25 16:07:02 +10001149class TerminalCopyNotice extends LitElement {
1150 /** @override */
1151 static get styles() {
1152 return css`
1153 :host {
1154 display: block;
1155 text-align: center;
1156 }
1157
1158 svg {
1159 fill: currentColor;
1160 }
1161 `;
1162 }
1163
1164 /** @override */
Jason Lind3aacef2022-10-12 19:03:37 +11001165 connectedCallback() {
1166 super.connectedCallback();
1167 if (!this.childNodes.length) {
1168 // This is not visible since we use shadow dom. But this will allow the
1169 // hterm.NotificationCenter to announce the the copy text.
1170 this.append(hterm.messageManager.get('HTERM_NOTIFY_COPY'));
1171 }
1172 }
1173
1174 /** @override */
Jason Lin6a402a72022-08-25 16:07:02 +10001175 render() {
1176 return html`
1177 ${ICON_COPY}
1178 <div>${hterm.messageManager.get('HTERM_NOTIFY_COPY')}</div>
1179 `;
1180 }
1181}
1182
1183customElements.define('terminal-copy-notice', TerminalCopyNotice);