@@ -0,0 +1,280 @@
|
||||
/**
|
||||
* Copyright (c) 2018 The xterm.js authors. All rights reserved.
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
/// <reference path="../../../typings/xterm.d.ts"/>
|
||||
|
||||
import type { Terminal } from '@xterm/xterm';
|
||||
import { BaseWindow } from './baseWindow';
|
||||
import type { IControlWindow } from '../controlBar';
|
||||
import type { AddonCollection } from 'types';
|
||||
import type { IImageAddonOptions } from '@xterm/addon-image';
|
||||
|
||||
export class AddonsWindow extends BaseWindow implements IControlWindow {
|
||||
public readonly id = 'addons';
|
||||
public readonly label = 'Addons';
|
||||
|
||||
private _addonsContainer: HTMLElement;
|
||||
private _findNextInput: HTMLInputElement;
|
||||
private _findPreviousInput: HTMLInputElement;
|
||||
private _findResultsSpan: HTMLElement;
|
||||
private _regexCheckbox: HTMLInputElement;
|
||||
private _caseSensitiveCheckbox: HTMLInputElement;
|
||||
private _wholeWordCheckbox: HTMLInputElement;
|
||||
private _highlightAllMatchesCheckbox: HTMLInputElement;
|
||||
private _serializeOutputPre: HTMLPreElement;
|
||||
private _htmlSerializeOutputPre: HTMLPreElement;
|
||||
private _htmlSerializeOutputResult: HTMLElement;
|
||||
private _writeToTerminalCheckbox: HTMLInputElement;
|
||||
private _imageStorageLimitInput: HTMLInputElement;
|
||||
private _imageShowPlaceholderCheckbox: HTMLInputElement;
|
||||
private _imageOptionsTextarea: HTMLTextAreaElement;
|
||||
|
||||
public build(container: HTMLElement): void {
|
||||
// Heading
|
||||
const heading = document.createElement('h3');
|
||||
heading.textContent = 'Addons';
|
||||
container.appendChild(heading);
|
||||
|
||||
// Description
|
||||
const description = document.createElement('p');
|
||||
description.textContent = 'Addons can be loaded and unloaded on a particular terminal to extend its functionality.';
|
||||
container.appendChild(description);
|
||||
|
||||
// Addons container (checkboxes go here)
|
||||
this._addonsContainer = document.createElement('div');
|
||||
this._addonsContainer.id = 'addons-container';
|
||||
container.appendChild(this._addonsContainer);
|
||||
|
||||
// Addons Control section
|
||||
const controlHeading = document.createElement('h3');
|
||||
controlHeading.textContent = 'Addons Control';
|
||||
container.appendChild(controlHeading);
|
||||
|
||||
// SearchAddon section
|
||||
this._buildSearchSection(container);
|
||||
|
||||
// SerializeAddon section
|
||||
this._buildSerializeSection(container);
|
||||
|
||||
// ImageAddon section
|
||||
this._buildImageSection(container);
|
||||
}
|
||||
|
||||
private _buildSearchSection(container: HTMLElement): void {
|
||||
const h4 = document.createElement('h4');
|
||||
h4.textContent = 'SearchAddon';
|
||||
container.appendChild(h4);
|
||||
|
||||
const wrapper = document.createElement('div');
|
||||
wrapper.style.display = 'flex';
|
||||
wrapper.style.flexDirection = 'column';
|
||||
|
||||
// Find next
|
||||
const findNextLabel = document.createElement('label');
|
||||
findNextLabel.textContent = 'Find next ';
|
||||
this._findNextInput = document.createElement('input');
|
||||
this._findNextInput.id = 'find-next';
|
||||
findNextLabel.appendChild(this._findNextInput);
|
||||
wrapper.appendChild(findNextLabel);
|
||||
|
||||
// Find previous
|
||||
const findPrevLabel = document.createElement('label');
|
||||
findPrevLabel.textContent = 'Find previous ';
|
||||
this._findPreviousInput = document.createElement('input');
|
||||
this._findPreviousInput.id = 'find-previous';
|
||||
findPrevLabel.appendChild(this._findPreviousInput);
|
||||
wrapper.appendChild(findPrevLabel);
|
||||
|
||||
// Results
|
||||
const resultsDiv = document.createElement('div');
|
||||
resultsDiv.textContent = 'Results: ';
|
||||
this._findResultsSpan = document.createElement('span');
|
||||
this._findResultsSpan.id = 'find-results';
|
||||
resultsDiv.appendChild(this._findResultsSpan);
|
||||
wrapper.appendChild(resultsDiv);
|
||||
|
||||
// Regex checkbox
|
||||
const regexLabel = document.createElement('label');
|
||||
this._regexCheckbox = document.createElement('input');
|
||||
this._regexCheckbox.type = 'checkbox';
|
||||
this._regexCheckbox.id = 'regex';
|
||||
regexLabel.appendChild(this._regexCheckbox);
|
||||
regexLabel.appendChild(document.createTextNode('Use regex'));
|
||||
wrapper.appendChild(regexLabel);
|
||||
|
||||
// Case sensitive checkbox
|
||||
const caseLabel = document.createElement('label');
|
||||
this._caseSensitiveCheckbox = document.createElement('input');
|
||||
this._caseSensitiveCheckbox.type = 'checkbox';
|
||||
this._caseSensitiveCheckbox.id = 'case-sensitive';
|
||||
caseLabel.appendChild(this._caseSensitiveCheckbox);
|
||||
caseLabel.appendChild(document.createTextNode('Case sensitive'));
|
||||
wrapper.appendChild(caseLabel);
|
||||
|
||||
// Whole word checkbox
|
||||
const wholeWordLabel = document.createElement('label');
|
||||
this._wholeWordCheckbox = document.createElement('input');
|
||||
this._wholeWordCheckbox.type = 'checkbox';
|
||||
this._wholeWordCheckbox.id = 'whole-word';
|
||||
wholeWordLabel.appendChild(this._wholeWordCheckbox);
|
||||
wholeWordLabel.appendChild(document.createTextNode('Whole word'));
|
||||
wrapper.appendChild(wholeWordLabel);
|
||||
|
||||
// Highlight all matches checkbox
|
||||
const highlightLabel = document.createElement('label');
|
||||
this._highlightAllMatchesCheckbox = document.createElement('input');
|
||||
this._highlightAllMatchesCheckbox.type = 'checkbox';
|
||||
this._highlightAllMatchesCheckbox.id = 'highlight-all-matches';
|
||||
this._highlightAllMatchesCheckbox.checked = true;
|
||||
highlightLabel.appendChild(this._highlightAllMatchesCheckbox);
|
||||
highlightLabel.appendChild(document.createTextNode('Highlight All Matches'));
|
||||
wrapper.appendChild(highlightLabel);
|
||||
|
||||
container.appendChild(wrapper);
|
||||
}
|
||||
|
||||
private _buildSerializeSection(container: HTMLElement): void {
|
||||
const h4 = document.createElement('h4');
|
||||
h4.textContent = 'SerializeAddon';
|
||||
container.appendChild(h4);
|
||||
|
||||
const wrapper = document.createElement('div');
|
||||
|
||||
// Serialize button
|
||||
const serializeBtn = document.createElement('button');
|
||||
serializeBtn.id = 'serialize';
|
||||
serializeBtn.textContent = 'Serialize the content of terminal';
|
||||
serializeBtn.addEventListener('click', () => serializeButtonHandler(this._terminal, this._addons));
|
||||
wrapper.appendChild(serializeBtn);
|
||||
|
||||
// Write to terminal checkbox
|
||||
const writeLabel = document.createElement('label');
|
||||
this._writeToTerminalCheckbox = document.createElement('input');
|
||||
this._writeToTerminalCheckbox.type = 'checkbox';
|
||||
this._writeToTerminalCheckbox.id = 'write-to-terminal';
|
||||
writeLabel.appendChild(this._writeToTerminalCheckbox);
|
||||
writeLabel.appendChild(document.createTextNode('Write back to terminal'));
|
||||
wrapper.appendChild(writeLabel);
|
||||
|
||||
// Serialize output
|
||||
const outputDiv = document.createElement('div');
|
||||
this._serializeOutputPre = document.createElement('pre');
|
||||
this._serializeOutputPre.id = 'serialize-output';
|
||||
outputDiv.appendChild(this._serializeOutputPre);
|
||||
wrapper.appendChild(outputDiv);
|
||||
|
||||
// HTML serialize button
|
||||
const htmlSerializeBtn = document.createElement('button');
|
||||
htmlSerializeBtn.id = 'htmlserialize';
|
||||
htmlSerializeBtn.textContent = 'Serialize the content of terminal in HTML';
|
||||
htmlSerializeBtn.addEventListener('click', () => htmlSerializeButtonHandler(this._terminal, this._addons));
|
||||
wrapper.appendChild(htmlSerializeBtn);
|
||||
|
||||
// HTML serialize result
|
||||
this._htmlSerializeOutputResult = document.createElement('span');
|
||||
this._htmlSerializeOutputResult.id = 'htmlserialize-output-result';
|
||||
wrapper.appendChild(this._htmlSerializeOutputResult);
|
||||
|
||||
// HTML serialize output
|
||||
const htmlOutputDiv = document.createElement('div');
|
||||
this._htmlSerializeOutputPre = document.createElement('pre');
|
||||
this._htmlSerializeOutputPre.id = 'htmlserialize-output';
|
||||
htmlOutputDiv.appendChild(this._htmlSerializeOutputPre);
|
||||
wrapper.appendChild(htmlOutputDiv);
|
||||
|
||||
container.appendChild(wrapper);
|
||||
}
|
||||
|
||||
private _buildImageSection(container: HTMLElement): void {
|
||||
const h4 = document.createElement('h4');
|
||||
h4.textContent = 'Image Addon';
|
||||
container.appendChild(h4);
|
||||
|
||||
const details = document.createElement('details');
|
||||
const summary = document.createElement('summary');
|
||||
summary.textContent = 'image addon settings';
|
||||
details.appendChild(summary);
|
||||
|
||||
const wrapper = document.createElement('div');
|
||||
|
||||
// Storage limit
|
||||
const storageLimitLabel = document.createElement('label');
|
||||
storageLimitLabel.textContent = 'Storage Limit (in MB) ';
|
||||
this._imageStorageLimitInput = document.createElement('input');
|
||||
this._imageStorageLimitInput.type = 'number';
|
||||
this._imageStorageLimitInput.id = 'image-storagelimit';
|
||||
storageLimitLabel.appendChild(this._imageStorageLimitInput);
|
||||
wrapper.appendChild(storageLimitLabel);
|
||||
wrapper.appendChild(document.createElement('br'));
|
||||
|
||||
// Show placeholder
|
||||
const placeholderLabel = document.createElement('label');
|
||||
placeholderLabel.textContent = 'Show Placeholder ';
|
||||
this._imageShowPlaceholderCheckbox = document.createElement('input');
|
||||
this._imageShowPlaceholderCheckbox.type = 'checkbox';
|
||||
this._imageShowPlaceholderCheckbox.id = 'image-showplaceholder';
|
||||
placeholderLabel.appendChild(this._imageShowPlaceholderCheckbox);
|
||||
wrapper.appendChild(placeholderLabel);
|
||||
wrapper.appendChild(document.createElement('br'));
|
||||
wrapper.appendChild(document.createElement('br'));
|
||||
|
||||
// Ctor options
|
||||
const optionsLabel = document.createElement('label');
|
||||
optionsLabel.appendChild(document.createTextNode('Ctor options (applied on addon relaunch)'));
|
||||
optionsLabel.appendChild(document.createElement('br'));
|
||||
this._imageOptionsTextarea = document.createElement('textarea');
|
||||
this._imageOptionsTextarea.id = 'image-options';
|
||||
this._imageOptionsTextarea.cols = 40;
|
||||
this._imageOptionsTextarea.rows = 12;
|
||||
optionsLabel.appendChild(this._imageOptionsTextarea);
|
||||
wrapper.appendChild(optionsLabel);
|
||||
|
||||
details.appendChild(wrapper);
|
||||
container.appendChild(details);
|
||||
}
|
||||
|
||||
public get addonsContainer(): HTMLElement {
|
||||
return this._addonsContainer;
|
||||
}
|
||||
|
||||
public get findNextInput(): HTMLInputElement {
|
||||
return this._findNextInput;
|
||||
}
|
||||
|
||||
public get findPreviousInput(): HTMLInputElement {
|
||||
return this._findPreviousInput;
|
||||
}
|
||||
|
||||
public get findResultsSpan(): HTMLElement {
|
||||
return this._findResultsSpan;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function serializeButtonHandler(term: Terminal, addons: AddonCollection): void {
|
||||
const output = addons.serialize.instance.serialize();
|
||||
const outputString = JSON.stringify(output);
|
||||
|
||||
document.getElementById('serialize-output').innerText = outputString;
|
||||
if ((document.getElementById('write-to-terminal') as HTMLInputElement).checked) {
|
||||
term.reset();
|
||||
term.write(output);
|
||||
}
|
||||
}
|
||||
|
||||
function htmlSerializeButtonHandler(term: Terminal, addons: AddonCollection): void {
|
||||
const output = addons.serialize.instance.serializeAsHTML();
|
||||
document.getElementById('htmlserialize-output').innerText = output;
|
||||
|
||||
// Deprecated, but the most supported for now.
|
||||
function listener(e: any): void {
|
||||
e.clipboardData.setData('text/html', output);
|
||||
e.preventDefault();
|
||||
}
|
||||
document.addEventListener('copy', listener);
|
||||
document.execCommand('copy');
|
||||
document.removeEventListener('copy', listener);
|
||||
document.getElementById('htmlserialize-output-result').innerText = 'Copied to clipboard';
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Copyright (c) 2025 The xterm.js authors. All rights reserved.
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
/// <reference path="../../../typings/xterm.d.ts"/>
|
||||
|
||||
import type { AddonCollection } from '../../types';
|
||||
import type { IControlWindow } from '../controlBar';
|
||||
import type { Terminal } from '@xterm/xterm';
|
||||
|
||||
export abstract class BaseWindow implements IControlWindow {
|
||||
protected get _terminal(): Terminal { return this.__terminal; }
|
||||
|
||||
constructor(
|
||||
private __terminal: Terminal,
|
||||
protected readonly _addons: AddonCollection,
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
setTerminal(terminal: Terminal): void {
|
||||
this.__terminal = terminal;
|
||||
}
|
||||
|
||||
abstract id: string;
|
||||
abstract label: string;
|
||||
abstract build(container: HTMLElement): void;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Copyright (c) 2018 The xterm.js authors. All rights reserved.
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { BaseWindow } from './baseWindow';
|
||||
import type { IControlWindow } from '../controlBar';
|
||||
|
||||
export class GpuWindow extends BaseWindow implements IControlWindow {
|
||||
public readonly id = 'gpu';
|
||||
public readonly label = 'GPU';
|
||||
|
||||
private _textureAtlasContainer: HTMLElement;
|
||||
|
||||
public build(container: HTMLElement): void {
|
||||
const heading = document.createElement('h3');
|
||||
heading.textContent = 'GPU';
|
||||
container.appendChild(heading);
|
||||
|
||||
const zoomCheckbox = document.createElement('input');
|
||||
zoomCheckbox.type = 'checkbox';
|
||||
zoomCheckbox.id = 'texture-atlas-zoom';
|
||||
container.appendChild(zoomCheckbox);
|
||||
|
||||
const zoomLabel = document.createElement('label');
|
||||
zoomLabel.htmlFor = 'texture-atlas-zoom';
|
||||
zoomLabel.textContent = 'Zoom texture atlas';
|
||||
container.appendChild(zoomLabel);
|
||||
|
||||
this._textureAtlasContainer = document.createElement('div');
|
||||
this._textureAtlasContainer.id = 'texture-atlas';
|
||||
container.appendChild(this._textureAtlasContainer);
|
||||
}
|
||||
|
||||
public setTextureAtlas(canvas: HTMLCanvasElement): void {
|
||||
this._styleAtlasPage(canvas);
|
||||
this._textureAtlasContainer.replaceChildren(canvas);
|
||||
}
|
||||
|
||||
public appendTextureAtlas(canvas: HTMLCanvasElement): void {
|
||||
this._styleAtlasPage(canvas);
|
||||
this._textureAtlasContainer.appendChild(canvas);
|
||||
}
|
||||
|
||||
public removeTextureAtlas(canvas: HTMLCanvasElement): void {
|
||||
canvas.remove();
|
||||
}
|
||||
|
||||
private _styleAtlasPage(canvas: HTMLCanvasElement): void {
|
||||
canvas.style.width = `${canvas.width / window.devicePixelRatio}px`;
|
||||
canvas.style.height = `${canvas.height / window.devicePixelRatio}px`;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
/**
|
||||
* Copyright (c) 2018 The xterm.js authors. All rights reserved.
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { BaseWindow } from './baseWindow';
|
||||
import type { Terminal, ITheme } from '@xterm/xterm';
|
||||
import type { IControlWindow } from '../controlBar';
|
||||
import type { AddonCollection } from 'types';
|
||||
|
||||
const xtermjsTheme: ITheme = {
|
||||
foreground: '#F8F8F8',
|
||||
background: '#2D2E2C',
|
||||
selectionBackground: '#5DA5D533',
|
||||
selectionInactiveBackground: '#555555AA',
|
||||
black: '#1E1E1D',
|
||||
brightBlack: '#262625',
|
||||
red: '#CE5C5C',
|
||||
brightRed: '#FF7272',
|
||||
green: '#5BCC5B',
|
||||
brightGreen: '#72FF72',
|
||||
yellow: '#CCCC5B',
|
||||
brightYellow: '#FFFF72',
|
||||
blue: '#5D5DD3',
|
||||
brightBlue: '#7279FF',
|
||||
magenta: '#BC5ED1',
|
||||
brightMagenta: '#E572FF',
|
||||
cyan: '#5DA5D5',
|
||||
brightCyan: '#72F0FF',
|
||||
white: '#F8F8F8',
|
||||
brightWhite: '#FFFFFF'
|
||||
};
|
||||
|
||||
export class OptionsWindow extends BaseWindow implements IControlWindow {
|
||||
public readonly id = 'options';
|
||||
public readonly label = 'Options';
|
||||
|
||||
private _container: HTMLElement;
|
||||
private _optionsContainer: HTMLElement;
|
||||
private _autoResize: boolean = true;
|
||||
|
||||
constructor(
|
||||
terminal: Terminal,
|
||||
addons: AddonCollection,
|
||||
private readonly _handlers: {
|
||||
updateTerminalSize: () => void,
|
||||
updateTerminalContainerBackground: () => void
|
||||
},
|
||||
) {
|
||||
super(terminal, addons)
|
||||
}
|
||||
|
||||
public build(container: HTMLElement): void {
|
||||
this._container = container;
|
||||
|
||||
const heading = document.createElement('h3');
|
||||
heading.textContent = 'Options';
|
||||
container.appendChild(heading);
|
||||
|
||||
const description = document.createElement('p');
|
||||
description.innerHTML = 'These options can be set in the <code>Terminal</code> constructor or by using the <code>Terminal.options</code> property.';
|
||||
container.appendChild(description);
|
||||
|
||||
this._optionsContainer = document.createElement('div');
|
||||
this._optionsContainer.id = 'options-container';
|
||||
container.appendChild(this._optionsContainer);
|
||||
}
|
||||
|
||||
public initOptions(addDomListener: (el: HTMLElement, type: string, handler: (...args: any[]) => any) => void): void {
|
||||
const blacklistedOptions = [
|
||||
'cancelEvents',
|
||||
'convertEol',
|
||||
'termName',
|
||||
'cols', 'rows',
|
||||
'documentOverride',
|
||||
'linkHandler',
|
||||
'logger',
|
||||
'overviewRuler',
|
||||
'theme',
|
||||
'windowOptions',
|
||||
'windowsPty',
|
||||
];
|
||||
const stringOptions: { [key: string]: string[] | null } = {
|
||||
cursorStyle: ['block', 'underline', 'bar'],
|
||||
cursorInactiveStyle: ['outline', 'block', 'bar', 'underline', 'none'],
|
||||
fontFamily: null,
|
||||
fontWeight: ['normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900'],
|
||||
fontWeightBold: ['normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900'],
|
||||
logLevel: ['trace', 'debug', 'info', 'warn', 'error', 'off'],
|
||||
theme: ['default', 'xtermjs', 'sapphire', 'light'],
|
||||
wordSeparator: null,
|
||||
colsRows: null
|
||||
};
|
||||
const options = Object.getOwnPropertyNames(this._terminal.options);
|
||||
const booleanOptions: string[] = [];
|
||||
const numberOptions: string[] = [];
|
||||
options.filter(o => blacklistedOptions.indexOf(o) === -1).forEach(o => {
|
||||
switch (typeof this._terminal.options[o]) {
|
||||
case 'boolean':
|
||||
booleanOptions.push(o);
|
||||
break;
|
||||
case 'number':
|
||||
numberOptions.push(o);
|
||||
break;
|
||||
default:
|
||||
if (Object.keys(stringOptions).indexOf(o) === -1 && numberOptions.indexOf(o) === -1 && booleanOptions.indexOf(o) === -1) {
|
||||
console.warn(`Unrecognized option: "${o}"`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let html = '';
|
||||
html += '<div class="option-group">';
|
||||
booleanOptions.forEach(o => {
|
||||
html += `<div class="option"><label><input id="opt-${o}" type="checkbox" ${this._terminal.options[o] ? 'checked' : ''}/> ${o}</label></div>`;
|
||||
});
|
||||
html += '</div><div class="option-group">';
|
||||
numberOptions.forEach(o => {
|
||||
html += `<div class="option"><label>${o} <input id="opt-${o}" type="number" value="${this._terminal.options[o] ?? ''}" step="${o === 'lineHeight' || o === 'scrollSensitivity' ? '0.1' : '1'}"/></label></div>`;
|
||||
});
|
||||
html += '</div><div class="option-group">';
|
||||
Object.keys(stringOptions).forEach(o => {
|
||||
if (o === 'colsRows') {
|
||||
html += `<div class="option"><label>size (<var>cols</var><code>x</code><var>rows</var> or <code>auto</code>) <input id="opt-${o}" type="text" value="auto"/></label></div>`;
|
||||
} else if (stringOptions[o]) {
|
||||
const selectedOption = o === 'theme' ? 'xtermjs' : this._terminal.options[o];
|
||||
html += `<div class="option"><label>${o} <select id="opt-${o}">${stringOptions[o]!.map(v => `<option ${v === selectedOption ? 'selected' : ''}>${v}</option>`).join('')}</select></label></div>`;
|
||||
} else {
|
||||
html += `<div class="option"><label>${o} <input id="opt-${o}" type="text" value="${this._terminal.options[o]}"/></label></div>`;
|
||||
}
|
||||
});
|
||||
html += '</div>';
|
||||
|
||||
this._optionsContainer.innerHTML = html;
|
||||
|
||||
// Attach listeners
|
||||
booleanOptions.forEach(o => {
|
||||
const input = document.getElementById(`opt-${o}`) as HTMLInputElement;
|
||||
addDomListener(input, 'change', () => {
|
||||
console.log('change', o, input.checked);
|
||||
this._terminal.options[o] = input.checked;
|
||||
});
|
||||
});
|
||||
numberOptions.forEach(o => {
|
||||
const input = document.getElementById(`opt-${o}`) as HTMLInputElement;
|
||||
addDomListener(input, 'change', () => {
|
||||
console.log('change', o, input.value);
|
||||
if (o === 'lineHeight') {
|
||||
this._terminal.options.lineHeight = parseFloat(input.value);
|
||||
} else if (o === 'scrollSensitivity') {
|
||||
this._terminal.options.scrollSensitivity = parseFloat(input.value);
|
||||
} else if (o === 'scrollback') {
|
||||
this._terminal.options.scrollback = parseInt(input.value);
|
||||
setTimeout(() => this._handlers.updateTerminalSize(), 5);
|
||||
} else {
|
||||
this._terminal.options[o] = parseInt(input.value);
|
||||
}
|
||||
this._handlers.updateTerminalSize();
|
||||
});
|
||||
});
|
||||
Object.keys(stringOptions).forEach(o => {
|
||||
const input = document.getElementById(`opt-${o}`) as HTMLInputElement;
|
||||
addDomListener(input, 'change', () => {
|
||||
console.log('change', o, input.value);
|
||||
let value: any = input.value;
|
||||
if (o === 'colsRows') {
|
||||
const m = input.value.match(/^([0-9]+)x([0-9]+)$/);
|
||||
if (m) {
|
||||
this._autoResize = false;
|
||||
this._terminal.resize(parseInt(m[1]), parseInt(m[2]));
|
||||
} else {
|
||||
this._autoResize = true;
|
||||
input.value = 'auto';
|
||||
this._handlers.updateTerminalSize();
|
||||
}
|
||||
} else if (o === 'theme') {
|
||||
switch (input.value) {
|
||||
case 'default':
|
||||
value = undefined;
|
||||
break;
|
||||
case 'xtermjs':
|
||||
value = xtermjsTheme;
|
||||
break;
|
||||
case 'sapphire':
|
||||
value = {
|
||||
background: '#1c2431',
|
||||
foreground: '#cccccc',
|
||||
selectionBackground: '#399ef440',
|
||||
black: '#666666',
|
||||
blue: '#399ef4',
|
||||
brightBlack: '#666666',
|
||||
brightBlue: '#399ef4',
|
||||
brightCyan: '#21c5c7',
|
||||
brightGreen: '#4eb071',
|
||||
brightMagenta: '#b168df',
|
||||
brightRed: '#da6771',
|
||||
brightWhite: '#efefef',
|
||||
brightYellow: '#fff099',
|
||||
cyan: '#21c5c7',
|
||||
green: '#4eb071',
|
||||
magenta: '#b168df',
|
||||
red: '#da6771',
|
||||
white: '#efefef',
|
||||
yellow: '#fff099'
|
||||
};
|
||||
break;
|
||||
case 'light':
|
||||
value = {
|
||||
background: '#ffffff',
|
||||
foreground: '#333333',
|
||||
cursor: '#333333',
|
||||
cursorAccent: '#ffffff',
|
||||
selectionBackground: '#add6ff',
|
||||
overviewRulerBorder: '#aaaaaa',
|
||||
black: '#000000',
|
||||
blue: '#0451a5',
|
||||
brightBlack: '#666666',
|
||||
brightBlue: '#0451a5',
|
||||
brightCyan: '#0598bc',
|
||||
brightGreen: '#14ce14',
|
||||
brightMagenta: '#bc05bc',
|
||||
brightRed: '#cd3131',
|
||||
brightWhite: '#a5a5a5',
|
||||
brightYellow: '#b5ba00',
|
||||
cyan: '#0598bc',
|
||||
green: '#00bc00',
|
||||
magenta: '#bc05bc',
|
||||
red: '#cd3131',
|
||||
white: '#555555',
|
||||
yellow: '#949800'
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
this._terminal.options[o] = value;
|
||||
if (o === 'theme') {
|
||||
this._handlers.updateTerminalContainerBackground();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public get autoResize(): boolean {
|
||||
return this._autoResize;
|
||||
}
|
||||
|
||||
public set autoResize(value: boolean) {
|
||||
this._autoResize = value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Copyright (c) 2018 The xterm.js authors. All rights reserved.
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { BaseWindow } from './baseWindow';
|
||||
import type { IControlWindow } from '../controlBar';
|
||||
|
||||
export class StyleWindow extends BaseWindow implements IControlWindow {
|
||||
public readonly id = 'style';
|
||||
public readonly label = 'Style';
|
||||
|
||||
private _paddingElement: HTMLInputElement;
|
||||
|
||||
public build(container: HTMLElement): void {
|
||||
const heading = document.createElement('h3');
|
||||
heading.textContent = 'Style';
|
||||
container.appendChild(heading);
|
||||
|
||||
const wrapper = document.createElement('div');
|
||||
wrapper.style.display = 'inline-block';
|
||||
wrapper.style.marginRight = '16px';
|
||||
|
||||
const label = document.createElement('label');
|
||||
label.htmlFor = 'padding';
|
||||
label.textContent = 'Padding';
|
||||
wrapper.appendChild(label);
|
||||
|
||||
this._paddingElement = document.createElement('input');
|
||||
this._paddingElement.type = 'number';
|
||||
this._paddingElement.id = 'padding';
|
||||
wrapper.appendChild(this._paddingElement);
|
||||
|
||||
container.appendChild(wrapper);
|
||||
}
|
||||
|
||||
public get paddingElement(): HTMLInputElement {
|
||||
return this._paddingElement;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,967 @@
|
||||
/**
|
||||
* Copyright (c) 2018 The xterm.js authors. All rights reserved.
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
/// <reference path="../../../../typings/xterm.d.ts"/>
|
||||
|
||||
import { writeUnicodeTable } from '../../unicodeTable';
|
||||
import type { IControlWindow } from '../controlBar';
|
||||
import { BaseWindow } from './baseWindow';
|
||||
import type { IDisposable, Terminal } from '@xterm/xterm';
|
||||
import type { AddonCollection } from 'types';
|
||||
import type { IProgressState } from '@xterm/addon-progress';
|
||||
import type { IImageAddonOptions } from '@xterm/addon-image';
|
||||
|
||||
export class TestWindow extends BaseWindow implements IControlWindow {
|
||||
public readonly id = 'test';
|
||||
public readonly label = 'Test';
|
||||
|
||||
constructor(
|
||||
terminal: Terminal,
|
||||
addons: AddonCollection,
|
||||
private readonly _handlers: {
|
||||
disposeRecreateButtonHandler: () => void,
|
||||
createNewWindowButtonHandler: () => void,
|
||||
},
|
||||
) {
|
||||
super(terminal, addons);
|
||||
}
|
||||
|
||||
public build(container: HTMLElement): void {
|
||||
const heading = document.createElement('h3');
|
||||
heading.textContent = 'Test';
|
||||
container.appendChild(heading);
|
||||
|
||||
const wrapper = document.createElement('div');
|
||||
wrapper.style.display = 'inline-block';
|
||||
wrapper.style.marginRight = '16px';
|
||||
|
||||
const dl = document.createElement('dl');
|
||||
|
||||
// Lifecycle section
|
||||
this._addDt(dl, 'Lifecycle');
|
||||
this._addDdWithCheckbox(dl, 'use-real-terminal', 'Use real terminal', 'This is used to real vs fake terminals', true);
|
||||
this._addDdWithButton(dl, 'dispose', 'Dispose terminal', 'This is used to testing memory leaks', () => this._handlers.disposeRecreateButtonHandler());
|
||||
this._addDdWithButton(dl, 'create-new-window', 'Create terminal in new window', 'This is used to test rendering in other windows', () => this._handlers.createNewWindowButtonHandler());
|
||||
|
||||
// Performance section
|
||||
this._addDt(dl, 'Performance');
|
||||
this._addDdWithButton(dl, 'load-test', 'Load test', 'Write several MB of data to simulate a lot of data coming from the process', () => loadTest(this._terminal, this._addons));
|
||||
this._addDdWithButton(dl, 'load-test-long-lines', 'Load test (long lines)', 'Write several MB of data with long lines to simulate a lot of data coming from the process', () => loadTestLongLines(this._terminal, this._addons));
|
||||
this._addDdWithButton(dl, 'print-cjk', 'CJK Unified Ideographs', 'Prints the 20977 characters from the CJK Unified Ideographs unicode block', () => addCjk(this._terminal));
|
||||
this._addDdWithButton(dl, 'print-cjk-sgr', 'CJK Unified Ideographs (random SGR)', 'Prints the 20977 characters from the CJK Unified Ideographs unicode block with randomized SGR attributes', () => addCjkRandomSgr(this._terminal));
|
||||
|
||||
// Styles section
|
||||
this._addDt(dl, 'Styles');
|
||||
this._addDdWithButton(dl, 'custom-glyph-alignment', 'Custom glyph alignment test', 'Write custom glyph alignment tests to the terminal', () => customGlyphAlignmentHandler(this._terminal));
|
||||
this._addDdWithButton(dl, 'custom-glyph-ranges', 'Custom glyph ranges', 'Write custom glyph unicode range to the terminal', () => customGlyphRangesHandler(this._terminal));
|
||||
this._addDdWithButton(dl, 'powerline-symbol-test', 'Powerline symbol test', 'Write powerline symbol characters to the terminal (\\ue0a0+)', () => powerlineSymbolTest(this._terminal));
|
||||
this._addDdWithButton(dl, 'underline-test', 'Underline test', 'Write text with Kitty\'s extended underline sequences', () => underlineTest(this._terminal));
|
||||
this._addDdWithButton(dl, 'sgr-test', 'SGR test', 'Write text with SGR attribute', () => sgrTest(this._terminal));
|
||||
this._addDdWithButton(dl, 'ansi-colors', 'Ansi colors test', 'Write a wide range of ansi colors', () => ansiColorsTest(this._terminal));
|
||||
this._addDdWithButton(dl, 'osc-hyperlinks', 'Ansi hyperlinks test', 'Write some OSC 8 hyperlinks', () => addAnsiHyperlink(this._terminal));
|
||||
this._addDdWithButton(dl, 'bce', 'Colored Erase (BCE)', 'Test colored erase', () => coloredErase(this._terminal));
|
||||
this._addDdWithButton(dl, 'add-grapheme-clusters', 'Grapheme clusters', 'Write grapheme cluster test strings', () => addGraphemeClusters(this._terminal));
|
||||
|
||||
// Decorations section
|
||||
this._addDt(dl, 'Decorations');
|
||||
this._addDdWithButton(dl, 'add-decoration', 'Decoration', 'Add a decoration to the terminal', () => addDecoration(this._terminal));
|
||||
this._addDdWithButton(dl, 'add-overview-ruler', 'Add Overview Ruler', 'Add an overview ruler to the terminal', () => addOverviewRuler(this._terminal));
|
||||
this._addDdWithButton(dl, 'decoration-stress-test', 'Stress Test', 'Toggle between adding and removing a decoration to each line', () => decorationStressTest(this._terminal));
|
||||
|
||||
// Ligatures Addon section
|
||||
this._addDt(dl, 'Ligatures Addon');
|
||||
this._addDdWithButton(dl, 'ligatures-test', 'Common ligatures', 'Write common ligatures sequences', () => ligaturesTest(this._terminal));
|
||||
|
||||
// Weblinks Addon section
|
||||
this._addDt(dl, 'Weblinks Addon');
|
||||
this._addDdWithButton(dl, 'weblinks-test', 'Test URLs', 'Various url conditions from demo data, hover&click to test', () => testWeblinks(this._terminal));
|
||||
|
||||
// Image Test section
|
||||
this._addDt(dl, 'Image Test');
|
||||
this._addDdWithButton(dl, 'image-demo1', 'snake (sixel)', '');
|
||||
this._addDdWithButton(dl, 'image-demo2', 'oranges (sixel)', '');
|
||||
this._addDdWithButton(dl, 'image-demo3', 'palette (iip)', '');
|
||||
|
||||
// Events Test section
|
||||
this._addDt(dl, 'Events Test');
|
||||
this._addDdWithButton(dl, 'event-focus', 'focus', '', () => this._terminal.focus());
|
||||
this._addDdWithButton(dl, 'event-blur', 'blur', '', () => this._terminal.blur());
|
||||
|
||||
// Progress Addon section
|
||||
this._addDt(dl, 'Progress Addon');
|
||||
this._addDdWithButton(dl, 'progress-run', 'full set run', '');
|
||||
this._addDdWithButton(dl, 'progress-0', 'state 0: remove', '');
|
||||
this._addDdWithButton(dl, 'progress-1', 'state 1: set 20%', '');
|
||||
this._addDdWithButton(dl, 'progress-2', 'state 2: error', '');
|
||||
this._addDdWithButton(dl, 'progress-3', 'state 3: indeterminate', '');
|
||||
this._addDdWithButton(dl, 'progress-4', 'state 4: pause', '');
|
||||
|
||||
// Progress bar
|
||||
const progressDd = document.createElement('dd');
|
||||
const progressDiv = document.createElement('div');
|
||||
progressDiv.id = 'progress-progress';
|
||||
const progressPercent = document.createElement('div');
|
||||
progressPercent.id = 'progress-percent';
|
||||
const progressIndeterminate = document.createElement('div');
|
||||
progressIndeterminate.id = 'progress-indeterminate';
|
||||
progressDiv.appendChild(progressPercent);
|
||||
progressDiv.appendChild(progressIndeterminate);
|
||||
progressDd.appendChild(progressDiv);
|
||||
dl.appendChild(progressDd);
|
||||
|
||||
// Progress state
|
||||
const stateDd = document.createElement('dd');
|
||||
const stateDiv = document.createElement('div');
|
||||
stateDiv.id = 'progress-state';
|
||||
stateDiv.textContent = 'State:';
|
||||
stateDd.appendChild(stateDiv);
|
||||
dl.appendChild(stateDd);
|
||||
|
||||
wrapper.appendChild(dl);
|
||||
container.appendChild(wrapper);
|
||||
|
||||
initProgress(this._terminal, this._addons);
|
||||
this._addProgressStyles(container);
|
||||
initImageAddonExposed(this._terminal, this._addons);
|
||||
}
|
||||
|
||||
private _addDt(dl: HTMLElement, text: string): void {
|
||||
const dt = document.createElement('dt');
|
||||
dt.textContent = text;
|
||||
dl.appendChild(dt);
|
||||
}
|
||||
|
||||
private _addDdWithButton(dl: HTMLElement, id: string, label: string, title: string, handler?: () => void): void {
|
||||
const dd = document.createElement('dd');
|
||||
const button = document.createElement('button');
|
||||
button.id = id;
|
||||
button.textContent = label;
|
||||
if (title) {
|
||||
button.title = title;
|
||||
}
|
||||
dd.appendChild(button);
|
||||
dl.appendChild(dd);
|
||||
button.addEventListener('click', handler);
|
||||
}
|
||||
|
||||
private _addDdWithCheckbox(dl: HTMLElement, id: string, label: string, title: string, checked: boolean): void {
|
||||
const dd = document.createElement('dd');
|
||||
const labelElement = document.createElement('label');
|
||||
labelElement.htmlFor = id;
|
||||
const checkbox = document.createElement('input');
|
||||
checkbox.type = 'checkbox';
|
||||
checkbox.id = id;
|
||||
checkbox.checked = checked;
|
||||
if (title) {
|
||||
checkbox.title = title;
|
||||
}
|
||||
labelElement.appendChild(checkbox);
|
||||
labelElement.appendChild(document.createTextNode(label));
|
||||
dd.appendChild(labelElement);
|
||||
dl.appendChild(dd);
|
||||
}
|
||||
|
||||
private _addProgressStyles(container: HTMLElement): void {
|
||||
const style = document.createElement('style');
|
||||
style.textContent = `
|
||||
#progress-progress {
|
||||
border: 1px solid black;
|
||||
height: 10px;
|
||||
}
|
||||
#progress-percent {
|
||||
height: 100%;
|
||||
}
|
||||
#progress-indeterminate {
|
||||
display: none;
|
||||
position: relative;
|
||||
height: 100%;
|
||||
}
|
||||
#progress-indeterminate:before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 0;
|
||||
bottom: 0px;
|
||||
width: 50px;
|
||||
height: 10px;
|
||||
background: blue;
|
||||
animation: ballbns 1s ease-in-out infinite alternate;
|
||||
}
|
||||
@keyframes ballbns {
|
||||
0% { left: 0; transform: translateX(0%); }
|
||||
100% { left: 100%; transform: translateX(-100%); }
|
||||
}
|
||||
`;
|
||||
container.appendChild(style);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the 20977 characters from the CJK Unified Ideographs unicode block.
|
||||
*/
|
||||
export function addCjk(term: Terminal): void {
|
||||
term.write('\n\n\r');
|
||||
for (let i = 0x4E00; i < 0x9FCC; i++) {
|
||||
term.write(String.fromCharCode(i));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints the 20977 characters from the CJK Unified Ideographs unicode block with randomized styles.
|
||||
*/
|
||||
function addCjkRandomSgr(term: Terminal): void {
|
||||
term.write('\n\n\r');
|
||||
for (let i = 0x4E00; i < 0x9FCC; i++) {
|
||||
term.write(`\x1b[${getRandomSgr()}m${String.fromCharCode(i)}\x1b[0m`);
|
||||
}
|
||||
}
|
||||
const randomSgrAttributes = [
|
||||
'1', '2', '3', '4', '5', '6', '7', '9',
|
||||
'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'
|
||||
];
|
||||
function getRandomSgr(): string {
|
||||
return randomSgrAttributes[Math.floor(Math.random() * randomSgrAttributes.length)];
|
||||
}
|
||||
|
||||
function powerlineSymbolTest(term: Terminal): void {
|
||||
function s(char: string): string {
|
||||
return `${char} \x1b[7m${char}\x1b[0m `;
|
||||
}
|
||||
term.write('\n\n\r');
|
||||
term.writeln('Standard powerline symbols:');
|
||||
term.writeln(' 0 1 2 3 4 5 6 7 8 9 A B C D E F');
|
||||
term.writeln(`0xA_ ${s('\ue0a0')}${s('\ue0a1')}${s('\ue0a2')}`);
|
||||
term.writeln(`0xB_ ${s('\ue0b0')}${s('\ue0b1')}${s('\ue0b2')}${s('\ue0b3')}`);
|
||||
term.writeln('');
|
||||
term.writeln(
|
||||
`\x1b[7m` +
|
||||
` inverse \ue0b1 \x1b[0;40m\ue0b0` +
|
||||
` 0 \ue0b1 \x1b[30;41m\ue0b0\x1b[39m` +
|
||||
` 1 \ue0b1 \x1b[31;42m\ue0b0\x1b[39m` +
|
||||
` 2 \ue0b1 \x1b[32;43m\ue0b0\x1b[39m` +
|
||||
` 3 \ue0b1 \x1b[33;44m\ue0b0\x1b[39m` +
|
||||
` 4 \ue0b1 \x1b[34;45m\ue0b0\x1b[39m` +
|
||||
` 5 \ue0b1 \x1b[35;46m\ue0b0\x1b[39m` +
|
||||
` 6 \ue0b1 \x1b[36;47m\ue0b0\x1b[30m` +
|
||||
` 7 \ue0b1 \x1b[37;49m\ue0b0\x1b[0m`
|
||||
);
|
||||
term.writeln('');
|
||||
term.writeln(
|
||||
`\x1b[7m` +
|
||||
` inverse \ue0b3 \x1b[0;7;40m\ue0b2\x1b[27m` +
|
||||
` 0 \ue0b3 \x1b[7;30;41m\ue0b2\x1b[27;39m` +
|
||||
` 1 \ue0b3 \x1b[7;31;42m\ue0b2\x1b[27;39m` +
|
||||
` 2 \ue0b3 \x1b[7;32;43m\ue0b2\x1b[27;39m` +
|
||||
` 3 \ue0b3 \x1b[7;33;44m\ue0b2\x1b[27;39m` +
|
||||
` 4 \ue0b3 \x1b[7;34;45m\ue0b2\x1b[27;39m` +
|
||||
` 5 \ue0b3 \x1b[7;35;46m\ue0b2\x1b[27;39m` +
|
||||
` 6 \ue0b3 \x1b[7;36;47m\ue0b2\x1b[27;30m` +
|
||||
` 7 \ue0b3 \x1b[7;37;49m\ue0b2\x1b[0m`
|
||||
);
|
||||
term.writeln('');
|
||||
term.writeln(
|
||||
`\x1b[7m` +
|
||||
` inverse \ue0b5 \x1b[0;40m\ue0b4` +
|
||||
` 0 \ue0b5 \x1b[30;41m\ue0b4\x1b[39m` +
|
||||
` 1 \ue0b5 \x1b[31;42m\ue0b4\x1b[39m` +
|
||||
` 2 \ue0b5 \x1b[32;43m\ue0b4\x1b[39m` +
|
||||
` 3 \ue0b5 \x1b[33;44m\ue0b4\x1b[39m` +
|
||||
` 4 \ue0b5 \x1b[34;45m\ue0b4\x1b[39m` +
|
||||
` 5 \ue0b5 \x1b[35;46m\ue0b4\x1b[39m` +
|
||||
` 6 \ue0b5 \x1b[36;47m\ue0b4\x1b[30m` +
|
||||
` 7 \ue0b5 \x1b[37;49m\ue0b4\x1b[0m`
|
||||
);
|
||||
term.writeln('');
|
||||
term.writeln(
|
||||
`\x1b[7m` +
|
||||
` inverse \ue0b7 \x1b[0;7;40m\ue0b6\x1b[27m` +
|
||||
` 0 \ue0b7 \x1b[7;30;41m\ue0b6\x1b[27;39m` +
|
||||
` 1 \ue0b7 \x1b[7;31;42m\ue0b6\x1b[27;39m` +
|
||||
` 2 \ue0b7 \x1b[7;32;43m\ue0b6\x1b[27;39m` +
|
||||
` 3 \ue0b7 \x1b[7;33;44m\ue0b6\x1b[27;39m` +
|
||||
` 4 \ue0b7 \x1b[7;34;45m\ue0b6\x1b[27;39m` +
|
||||
` 5 \ue0b7 \x1b[7;35;46m\ue0b6\x1b[27;39m` +
|
||||
` 6 \ue0b7 \x1b[7;36;47m\ue0b6\x1b[27;30m` +
|
||||
` 7 \ue0b7 \x1b[7;37;49m\ue0b6\x1b[0m`
|
||||
);
|
||||
term.writeln('');
|
||||
term.writeln('Powerline extra symbols:');
|
||||
term.writeln(' 0 1 2 3 4 5 6 7 8 9 A B C D E F');
|
||||
term.writeln(`0xA_ ${s('\ue0a3')}`);
|
||||
term.writeln(`0xB_ ${s('\ue0b4')}${s('\ue0b5')}${s('\ue0b6')}${s('\ue0b7')}${s('\ue0b8')}${s('\ue0b9')}${s('\ue0ba')}${s('\ue0bb')}${s('\ue0bc')}${s('\ue0bd')}${s('\ue0be')}${s('\ue0bf')}`);
|
||||
term.writeln(`0xC_ ${s('\ue0c0')}${s('\ue0c1')}${s('\ue0c2')}${s('\ue0c3')}${s('\ue0c4')}${s('\ue0c5')}${s('\ue0c6')}${s('\ue0c7')}${s('\ue0c8')}${s('\ue0c9')}${s('\ue0ca')}${s('\ue0cb')}${s('\ue0cc')}${s('\ue0cd')}${s('\ue0be')}${s('\ue0bf')}`);
|
||||
term.writeln(`0xD_ ${s('\ue0d0')}${s('\ue0d1')}${s('\ue0d2')} ${s('\ue0d4')}`);
|
||||
term.writeln('');
|
||||
term.writeln('Sample of nerd fonts icons:');
|
||||
term.writeln(' nf-linux-apple (\\uF302) \uf302');
|
||||
term.writeln('nf-mdi-github_face (\\uFbd9) \ufbd9');
|
||||
}
|
||||
|
||||
function underlineTest(term: Terminal): void {
|
||||
function u(style: number): string {
|
||||
return `\x1b[4:${style}m`;
|
||||
}
|
||||
function c(color: string): string {
|
||||
return `\x1b[58:${color}m`;
|
||||
}
|
||||
term.write('\n\n\r');
|
||||
term.writeln('Underline styles:');
|
||||
term.writeln('');
|
||||
function showSequence(id: number, name: string): string {
|
||||
let alphabet = '';
|
||||
for (let i = 97; i < 123; i++) {
|
||||
alphabet += String.fromCharCode(i);
|
||||
}
|
||||
let numbers = '';
|
||||
for (let i = 0; i < 10; i++) {
|
||||
numbers += i.toString();
|
||||
}
|
||||
return `${u(id)}4:${id}m - ${name}\x1b[4:0m`.padEnd(33, ' ') + `${u(id)}${alphabet} ${numbers} 汉语 한국어 👽\x1b[4:0m`;
|
||||
}
|
||||
term.writeln(showSequence(0, 'No underline'));
|
||||
term.writeln(showSequence(1, 'Straight'));
|
||||
term.writeln(showSequence(2, 'Double'));
|
||||
term.writeln(showSequence(3, 'Curly'));
|
||||
term.writeln(showSequence(4, 'Dotted'));
|
||||
term.writeln(showSequence(5, 'Dashed'));
|
||||
term.writeln('');
|
||||
term.writeln(`Underline colors (256 color mode):`);
|
||||
term.writeln('');
|
||||
for (let i = 0; i < 256; i++) {
|
||||
term.write((i !== 0 ? '\x1b[0m, ' : '') + u(1 + i % 5) + c('5:' + i) + i);
|
||||
}
|
||||
term.writeln(`\x1b[0m\n\n\rUnderline colors (true color mode):`);
|
||||
term.writeln('');
|
||||
for (let i = 0; i < 80; i++) {
|
||||
const v = Math.round(i / 79 * 255);
|
||||
term.write(u(1) + c(`2:0:${v}:${v}:${v}`) + (i < 4 ? 'grey'[i] : ' '));
|
||||
}
|
||||
term.write('\n\r');
|
||||
for (let i = 0; i < 80; i++) {
|
||||
const v = Math.round(i / 79 * 255);
|
||||
term.write(u(1) + c(`2:0:${v}:${0}:${0}`) + (i < 3 ? 'red'[i] : ' '));
|
||||
}
|
||||
term.write('\n\r');
|
||||
for (let i = 0; i < 80; i++) {
|
||||
const v = Math.round(i / 79 * 255);
|
||||
term.write(u(1) + c(`2:0:${0}:${v}:${0}`) + (i < 5 ? 'green'[i] : ' '));
|
||||
}
|
||||
term.write('\n\r');
|
||||
for (let i = 0; i < 80; i++) {
|
||||
const v = Math.round(i / 79 * 255);
|
||||
term.write(u(1) + c(`2:0:${0}:${0}:${v}`) + (i < 4 ? 'blue'[i] : ' '));
|
||||
}
|
||||
term.write('\x1b[0m\n\r');
|
||||
}
|
||||
|
||||
function customGlyphAlignmentHandler(term: Terminal): void {
|
||||
term.write('\n\r');
|
||||
term.write('\n\r');
|
||||
term.write('Box styles: ┎┰┒┍┯┑╓╥╖╒╤╕ ┏┳┓┌┲┓┌┬┐┏┱┐\n\r');
|
||||
term.write('┌─┬─┐ ┏━┳━┓ ╔═╦═╗ ┠╂┨┝┿┥╟╫╢╞╪╡ ┡╇┩├╊┫┢╈┪┣╉┤\n\r');
|
||||
term.write('│ │ │ ┃ ┃ ┃ ║ ║ ║ ┖┸┚┕┷┙╙╨╜╘╧╛ └┴┘└┺┛┗┻┛┗┹┘\n\r');
|
||||
term.write('├─┼─┤ ┣━╋━┫ ╠═╬═╣ ┏┱┐┌┲┓┌┬┐┌┬┐ ┏┳┓┌┮┓┌┬┐┏┭┐\n\r');
|
||||
term.write('│ │ │ ┃ ┃ ┃ ║ ║ ║ ┡╃┤├╄┩├╆┪┢╅┤ ┞╀┦├┾┫┟╁┧┣┽┤\n\r');
|
||||
term.write('└─┴─┘ ┗━┻━┛ ╚═╩═╝ └┴┘└┴┘└┺┛┗┹┘ └┴┘└┶┛┗┻┛┗┵┘\n\r');
|
||||
term.write('\n\r');
|
||||
|
||||
term.write('Other:\n\r');
|
||||
term.write('╭─╮ ╲ ╱ ╷╻╎╏┆┇┊┋ ╺╾╴ ╌╌╌ ┄┄┄ ┈┈┈\n\r');
|
||||
term.write('│ │ ╳ ╽╿╎╏┆┇┊┋ ╶╼╸ ╍╍╍ ┅┅┅ ┉┉┉\n\r');
|
||||
term.write('╰─╯ ╱ ╲ ╹╵╎╏┆┇┊┋\n\r');
|
||||
term.write('\n\r');
|
||||
|
||||
term.write('Box drawing alignment tests:\x1b[31m █\n\r');
|
||||
term.write(' ▉\n\r');
|
||||
term.write(' ╔══╦══╗ ┌──┬──┐ ╭──┬──╮ ╭──┬──╮ ┏━━┳━━┓ ┎┒┏┑ ╷ ╻ ┏┯┓ ┌┰┐ ▊ ╱╲╱╲╳╳╳\n\r');
|
||||
term.write(' ║┌─╨─┐║ │╔═╧═╗│ │╒═╪═╕│ │╓─╁─╖│ ┃┌─╂─┐┃ ┗╃╄┙ ╶┼╴╺╋╸┠┼┨ ┝╋┥ ▋ ╲╱╲╱╳╳╳\n\r');
|
||||
term.write(' ║│╲ ╱│║ │║ ║│ ││ │ ││ │║ ┃ ║│ ┃│ ╿ │┃ ┍╅╆┓ ╵ ╹ ┗┷┛ └┸┘ ▌ ╱╲╱╲╳╳╳\n\r');
|
||||
term.write(' ╠╡ ╳ ╞╣ ├╢ ╟┤ ├┼─┼─┼┤ ├╫─╂─╫┤ ┣┿╾┼╼┿┫ ┕┛┖┚ ┌┄┄┐ ╎ ┏┅┅┓ ┋ ▍ ╲╱╲╱╳╳╳\n\r');
|
||||
term.write(' ║│╱ ╲│║ │║ ║│ ││ │ ││ │║ ┃ ║│ ┃│ ╽ │┃ ░░▒▒▓▓██ ┊ ┆ ╎ ╏ ┇ ┋ ▎\n\r');
|
||||
term.write(' ║└─╥─┘║ │╚═╤═╝│ │╘═╪═╛│ │╙─╀─╜│ ┃└─╂─┘┃ ░░▒▒▓▓██ ┊ ┆ ╎ ╏ ┇ ┋ ▏\n\r');
|
||||
term.write(' ╚══╩══╝ └──┴──┘ ╰──┴──╯ ╰──┴──╯ ┗━━┻━━┛ └╌╌┘ ╎ ┗╍╍┛ ┋ ▁▂▃▄▅▆▇█\n\r');
|
||||
term.write('\x1b[0mBox drawing alignment tests:\x1b[32m █\n\r');
|
||||
term.write(' ▉\n\r');
|
||||
term.write(' ╔══╦══╗ ┌──┬──┐ ╭──┬──╮ ╭──┬──╮ ┏━━┳━━┓ ┎┒┏┑ ╷ ╻ ┏┯┓ ┌┰┐ ▊ ╱╲╱╲╳╳╳\n\r');
|
||||
term.write(' ║┌─╨─┐║ │╔═╧═╗│ │╒═╪═╕│ │╓─╁─╖│ ┃┌─╂─┐┃ ┗╃╄┙ ╶┼╴╺╋╸┠┼┨ ┝╋┥ ▋ ╲╱╲╱╳╳╳\n\r');
|
||||
term.write(' ║│╲ ╱│║ │║ ║│ ││ │ ││ │║ ┃ ║│ ┃│ ╿ │┃ ┍╅╆┓ ╵ ╹ ┗┷┛ └┸┘ ▌ ╱╲╱╲╳╳╳\n\r');
|
||||
term.write(' ╠╡ ╳ ╞╣ ├╢ ╟┤ ├┼─┼─┼┤ ├╫─╂─╫┤ ┣┿╾┼╼┿┫ ┕┛┖┚ ┌┄┄┐ ╎ ┏┅┅┓ ┋ ▍ ╲╱╲╱╳╳╳\n\r');
|
||||
term.write(' ║│╱ ╲│║ │║ ║│ ││ │ ││ │║ ┃ ║│ ┃│ ╽ │┃ ░░▒▒▓▓██ ┊ ┆ ╎ ╏ ┇ ┋ ▎\n\r');
|
||||
term.write(' ║└─╥─┘║ │╚═╤═╝│ │╘═╪═╛│ │╙─╀─╜│ ┃└─╂─┘┃ ░░▒▒▓▓██ ┊ ┆ ╎ ╏ ┇ ┋ ▏\n\r');
|
||||
term.write(' ╚══╩══╝ └──┴──┘ ╰──┴──╯ ╰──┴──╯ ┗━━┻━━┛ └╌╌┘ ╎ ┗╍╍┛ ┋ ▁▂▃▄▅▆▇█\n\r');
|
||||
|
||||
term.write('\x1b[0mSmooth mosaic terminal graphic characters alignment tests:\x1b[33m\n\r');
|
||||
term.write(' 🭇🬼 🭈🬽 🭉🬾 🭊🬿 🭋🭀 🭁🭌 🭂🭍 🭃🭎 🭄🭏 🭅🭐 🭆🭑 🭨🭪 🭩 🭯 🭮🭬\n\r');
|
||||
term.write(' 🭢🭗 🭣🭘 🭤🭙 🭥🭚 🭦🭛 🭒🭝 🭓🭞 🭔🭟 🭕🭠 🭖🭡 🭧🭜 🭫 🭭\n\r');
|
||||
term.write(' 🭇🬼 🭉🬾 🭋🭀\n\r');
|
||||
term.write(' 🭊🭁🭌🬿 🭈🭆🭂🭍🭑🬽 🭇🭄🭏🬼 🭃🭎 🭅🭐 🭨🭪\n\r');
|
||||
term.write(' 🭥🭒🭝🭚 🭣🭧🭓🭞🭜🭘 🭢🭕🭠🭗 🭔🭟 🭖🭡 🭪🭨\n\r');
|
||||
term.write(' 🭢🭗 🭤🭙 🭦🭛\n\r');
|
||||
|
||||
term.write('\x1b[0mCharacter cell diagonals (1FBA0-1FBAE) alignment tests:\x1b[34m\n\r');
|
||||
term.write(' \u{1FBA3}\u{1FBA7}\u{1FBA2} \u{1FBA3}\u{1FBA8}\u{1FBA0} \u{1FBAD}\u{1FBA2} \u{1FBA3}\u{1FBAC} \u{1FBAE}\n\r');
|
||||
term.write(' \u{1FBA3}\u{1FBA0} \u{1FBA1}\u{1FBA2} \u{1FBA1}\u{1FBA9}\u{1FBA2} \u{1FBA1}\u{1FBAA} \u{1FBAB}\u{1FBA0}\n\r');
|
||||
term.write(' \u{1FBA4} \u{1FBA5}\n\r');
|
||||
term.write(' \u{1FBA1}\u{1FBA2} \u{1FBA3}\u{1FBA0}\n\r');
|
||||
term.write(' \u{1FBA1}\u{1FBA6}\u{1FBA0}\n\r');
|
||||
|
||||
term.write('\x1b[0mCharacter cell diagonals (1FBD0-1FBDF) alignment tests:\x1b[34m\n\r');
|
||||
term.write(' \u{1FBD6}\u{1FBD4} \u{1FBD0}\u{1FBD1}\u{1FBD2}\u{1FBD3} \u{1FBDA} \u{1FBD9}\u{1FBDB} \u{1FBDE} \u{1FBDD}\u{1FBDF}\n\r');
|
||||
term.write(' \u{1FBD7}\u{1FBD5} \u{1FBD2}\u{1FBD3}\u{1FBD0}\u{1FBD1} \u{1FBD8} \u{1FBDC}\n\r');
|
||||
term.write(' \u{1FBD4}\u{1FBD6}\n\r');
|
||||
term.write(' \u{1FBD5}\u{1FBD7}\n\r');
|
||||
term.write('');
|
||||
|
||||
term.write('\x1b[0mComposite terminal graphics characters:\x1b[35m\n\r');
|
||||
term.write('\u{1FBB2}\u{1FBB3} \u{1FBB9}\u{1FBBA} \u{1FBC1}\u{1FBC2}\u{1FBC3}\n\r');
|
||||
|
||||
term.write('\x1b[0mFill tests:\x1b[36m\n\r');
|
||||
const fillChars = ['\u{2591}', '\u{2592}', '\u{2593}', '\u{1FB8C}', '\u{1FB8D}', '\u{1FB8E}', '\u{1FB8F}', '\u{1FB90}', '\u{1FB91}', '\u{1FB92}', '\u{1FB94}', '\u{1FB95}', '\u{1FB96}', '\u{1FB97}', '\u{1FB98}', '\u{1FB99}'];
|
||||
while (fillChars.length > 0) {
|
||||
const batch = fillChars.splice(0, 10);
|
||||
for (const fillChar of batch) {
|
||||
term.write(`${fillChar.codePointAt(0).toString(16).toUpperCase().padEnd(5, ' ')} `);
|
||||
}
|
||||
term.write('\n\r');
|
||||
for (let i = 0; i < 3; i++) {
|
||||
for (const fillChar of batch) {
|
||||
term.write(fillChar.repeat(5));
|
||||
term.write(' ');
|
||||
}
|
||||
term.write('\n\r');
|
||||
}
|
||||
}
|
||||
|
||||
term.write('\x1b[0mPowerline alignment tests:\n\r');
|
||||
const powerlineLeftChars = ['\u{E0B2}', '\u{E0B3}', '\u{E0B6}', '\u{E0B7}', '\u{E0BA}', '\u{E0BB}', '\u{E0BE}', '\u{E0BF}', '\u{E0C2}', '\u{E0C3}', '\u{E0C5}', '\u{E0C7}', '\u{E0CA}', '\u{E0D4}'];
|
||||
const powerlineRightChars = ['\u{E0B0}', '\u{E0B1}', '\u{E0B4}', '\u{E0B5}', '\u{E0B8}', '\u{E0B9}', '\u{E0BC}', '\u{E0BD}', '\u{E0C0}', '\u{E0C1}', '\u{E0C4}', '\u{E0C6}', '\u{E0C8}', '\u{E0D2}', '\u{E0CC}', '\u{E0CD}', '\u{E0CE}', '\u{E0CF}', '\u{E0D0}', '\u{E0D1}'];
|
||||
for (const char of powerlineLeftChars) {
|
||||
term.write(`\x1b[31m${char}\x1b[0;41m \x1b[0m `);
|
||||
}
|
||||
term.write('\n\r');
|
||||
for (const char of powerlineRightChars) {
|
||||
term.write(`\x1b[41m \x1b[0;31m${char}\x1b[0m `);
|
||||
}
|
||||
term.write('\n\r');
|
||||
|
||||
term.write('\x1b[0mGit Branch Symbols alignment tests:\x1b[32m\n\r');
|
||||
term.write(' \u{F5F7}\u{F5F7} \u{F5EE}\u{F5EF} \u{F5F6}\u{F5F7} \u{F5D6}\u{F5D0}\u{F5D7} \u{F5FC}\u{F5FC}\u{F5FE} \u{F5FD}\u{F609}\u{F5FF}\n\r');
|
||||
term.write(' \u{F5DA}\u{F5DD} \u{F5F0}\u{F5F4}\u{F5F2} \u{F5FA}\u{F5FB} \u{F5D1} \u{F5D1} \u{F604}\u{F60C}\u{F606} \u{F605}\u{F60D}\u{F607}\n\r');
|
||||
term.write(' \u{F5DB}\u{F5DE} \u{F5F1}\u{F5F5}\u{F5F3} \u{F5F8}\u{F5F9} \u{F5D8}\u{F5D0}\u{F5D9} \u{F600}\u{F60A}\u{F602} \u{F601}\u{F60B}\u{F603}\n\r');
|
||||
term.write(' \u{F5DC}\u{F5DF} \u{F5F7}\u{F5F7}\u{F5F7}\u{F5F7}\u{F5F7}\u{F5F7}\u{F5F7}\n\r');
|
||||
term.write('\u{F5F1}\u{F5E6}\u{F5E7}\u{F5F3} \u{F5D3}\u{F5D0}\u{F5E0}\u{F5E1}\u{F5E2}\u{F5E3}\u{F5E4}\u{F5E5}\u{F5E8}\u{F5E9}\u{F5EC}\u{F5ED}\u{F5D2}\n\r');
|
||||
term.write('\u{F5F1}\u{F5EA}\u{F5EB}\u{F5F3} \u{F5F9}\u{F5F9}\u{F5F9} \u{F5F9}\u{F5F9}\u{F5F9}\u{F5F9}\n\r');
|
||||
term.write(' \u{F5F9}\u{F5F9} \n\r');
|
||||
term.write('\x1b[0m');
|
||||
term.write('\n\r');
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
|
||||
function customGlyphRangesHandler(term: Terminal): void {
|
||||
// Box Drawing
|
||||
// 2500-257F
|
||||
// https://www.unicode.org/charts/PDF/U2500.pdf
|
||||
writeUnicodeTable(term, 'Box Drawing', 0x2500, 0x257F, [
|
||||
['Light and heavy solid lines', 0x2500, 0x2503],
|
||||
['Light and heavy dashed lines', 0x2504, 0x250B],
|
||||
['Light and heavy line box components', 0x250C, 0x254B],
|
||||
['Light and heavy dashed lines', 0x254C, 0x254F],
|
||||
['Double lines', 0x2550, 0x2551],
|
||||
['Light and double line box components', 0x2552, 0x256C],
|
||||
['Character cell arcs', 0x256D, 0x2570],
|
||||
['Character cell diagonals', 0x2571, 0x2573],
|
||||
['Light and heavy half lines', 0x2574, 0x257B],
|
||||
['Mixed light and heavy lines', 0x257C, 0x257F],
|
||||
]);
|
||||
// Box Elements
|
||||
// 2580-259F
|
||||
// https://www.unicode.org/charts/PDF/U2580.pdf
|
||||
writeUnicodeTable(term, 'Box Elements', 0x2580, 0x259F, [
|
||||
['Block elements', 0x2580, 0x2590],
|
||||
['Shade characters', 0x2591, 0x2593],
|
||||
['Block elements', 0x2594, 0x2595],
|
||||
['Terminal graphic characters', 0x2596, 0x259F],
|
||||
]);
|
||||
// Braille Patterns
|
||||
// 2800-28FF
|
||||
// https://www.unicode.org/charts/PDF/U2800.pdf
|
||||
writeUnicodeTable(term, 'Braille patterns', 0x2800, 0x28FF, [
|
||||
['Braille patterns', 0x2800, 0x28FF],
|
||||
]);
|
||||
// Powerline Symbols
|
||||
// Range: E0A0–E0D4
|
||||
// https://github.com/ryanoasis/nerd-fonts
|
||||
writeUnicodeTable(term, 'Powerline Symbols', 0xE0A0, 0xE0D4, [
|
||||
['Powerline symbols', 0xE0A0, 0xE0B3, [0xE0A4, 0xE0A5, 0xE0A6, 0xE0A7, 0xE0A8, 0xE0A9, 0xE0AA, 0xE0AB, 0xE0AC, 0xE0AD, 0xE0AE, 0xE0AF]],
|
||||
['Powerline extra symbols', 0xE0B4, 0xE0D4, [0xE0C9, 0xE0CB, 0xE0D3]],
|
||||
]);
|
||||
// Git Branch Symbols
|
||||
// F5D0-F60D
|
||||
// https://github.com/xtermjs/xterm.js/issues/5477
|
||||
writeUnicodeTable(term, 'Git Branch Symbols', 0xF5D0, 0xF5FB, [
|
||||
['Straight lines', 0xF5D0, 0xF5D5],
|
||||
['Curved lines', 0xF5D6, 0xF5D9],
|
||||
['Branching lines', 0xF5DA, 0xF5ED],
|
||||
['Nodes', 0xF5EE, 0xF5FB],
|
||||
['Extended nodes', 0xF5FC, 0xF60D],
|
||||
]);
|
||||
// Symbols for Legacy Computing
|
||||
// Range: 1FB00–1FBFF
|
||||
// https://www.unicode.org/charts/PDF/U1FB00.pdf
|
||||
writeUnicodeTable(term, 'Symbols for Legacy Computing', 0x1FB00, 0x1FBFF, [
|
||||
['Block mosaic terminal graphic characters (Sextants)', 0x1FB00, 0x1FB3B],
|
||||
['Smooth mosaic terminal graphic characters', 0x1FB3C, 0x1FB6F],
|
||||
['Block elements', 0x1FB70, 0x1FB80],
|
||||
['Window title bar', 0x1FB81, 0x1FB81],
|
||||
['Block elements', 0x1FB82, 0x1FB8B],
|
||||
['Rectangular shade characters', 0x1FB8C, 0x1FB94, [0x1FB93]],
|
||||
['Fill characters', 0x1FB95, 0x1FB97],
|
||||
['Diagonal fill characters', 0x1FB98, 0x1FB99],
|
||||
['Smooth mosaic terminal graphic characters', 0x1FB9A, 0x1FB9B],
|
||||
['Triangular shade characters', 0x1FB9C, 0x1FB9F],
|
||||
['Character cell diagonals', 0x1FBA0, 0x1FBAE],
|
||||
['Light solid line with stroke', 0x1FBAF, 0x1FBAF],
|
||||
['Terminal graphic characters', 0x1FBB0, 0x1FBB3],
|
||||
['Arrows', 0x1FBB4, 0x1FBB8],
|
||||
['Terminal graphic characters', 0x1FBB9, 0x1FBBC],
|
||||
['Negative terminal graphic characters', 0x1FBBD, 0x1FBBF],
|
||||
['Terminal graphic characters', 0x1FBC0, 0x1FBCA],
|
||||
['Terminal graphic characters', 0x1FBCB, 0x1FBCD],
|
||||
['Block elements', 0x1FBCE, 0x1FBCF],
|
||||
['Character cell diagonals', 0x1FBD0, 0x1FBDF],
|
||||
['Geometrics shapes', 0x1FBE0, 0x1FBEF],
|
||||
['Segmented digits', 0x1FBF0, 0x1FBF9],
|
||||
['Terminal graphic character', 0x1FBFA, 0x1FBFA],
|
||||
]);
|
||||
}
|
||||
|
||||
function ansiColorsTest(term: Terminal): void {
|
||||
term.writeln(`\x1b[0m\n\n\rStandard colors: Bright colors:`);
|
||||
for (let i = 0; i < 16; i++) {
|
||||
term.write(`\x1b[48;5;${i}m ${i.toString().padEnd(2, ' ').padStart(3, ' ')} \x1b[0m`);
|
||||
}
|
||||
|
||||
term.writeln(`\x1b[0m\n\n\rColors 17-231 from 256 palette:`);
|
||||
for (let i = 0; i < 6; i++) {
|
||||
const startId = 16 + i * 36;
|
||||
const endId = 16 + (i + 1) * 36 - 1;
|
||||
term.write(`${startId.toString().padStart(3, ' ')}-${endId.toString().padStart(3, ' ')} `);
|
||||
for (let j = 0; j < 36; j++) {
|
||||
const id = 16 + i * 36 + j;
|
||||
term.write(`\x1b[48;5;${id}m${(id % 10).toString().padStart(2, ' ')}\x1b[0m`);
|
||||
}
|
||||
term.write(`\r\n`);
|
||||
}
|
||||
|
||||
term.writeln(`\x1b[0m\n\rGreyscale from 256 palette:`);
|
||||
term.write('232-255 ');
|
||||
for (let i = 232; i < 256; i++) {
|
||||
term.write(`\x1b[48;5;${i}m ${(i % 10)} \x1b[0m`);
|
||||
}
|
||||
}
|
||||
|
||||
function writeTestString(): string {
|
||||
let alphabet = '';
|
||||
for (let i = 97; i < 123; i++) {
|
||||
alphabet += String.fromCharCode(i);
|
||||
}
|
||||
let numbers = '';
|
||||
for (let i = 0; i < 10; i++) {
|
||||
numbers += i.toString();
|
||||
}
|
||||
return `${alphabet} ${numbers} 汉语 한국어 👽`;
|
||||
}
|
||||
const testString = writeTestString();
|
||||
|
||||
function sgrTest(term: Terminal): void {
|
||||
term.write('\n\n\r');
|
||||
term.writeln(`Character Attributes (SGR, Select Graphic Rendition)`);
|
||||
const entries: { ps: number, name: string }[] = [
|
||||
{ ps: 0, name: 'Normal' },
|
||||
{ ps: 1, name: 'Bold' },
|
||||
{ ps: 2, name: 'Faint/dim' },
|
||||
{ ps: 3, name: 'Italicized' },
|
||||
{ ps: 4, name: 'Underlined' },
|
||||
{ ps: 5, name: 'Blink' },
|
||||
{ ps: 7, name: 'Inverse' },
|
||||
{ ps: 8, name: 'Invisible' },
|
||||
{ ps: 9, name: 'Crossed-out characters' },
|
||||
{ ps: 21, name: 'Doubly-underlined' },
|
||||
{ ps: 22, name: 'Normal' },
|
||||
{ ps: 23, name: 'Not italicized' },
|
||||
{ ps: 24, name: 'Not underlined' },
|
||||
{ ps: 25, name: 'Steady (not blink)' },
|
||||
{ ps: 27, name: 'Positive (not inverse)' },
|
||||
{ ps: 28, name: 'Visible (not hidden)' },
|
||||
{ ps: 29, name: 'Not crossed-out' },
|
||||
{ ps: 30, name: 'Foreground Black' },
|
||||
{ ps: 31, name: 'Foreground Red' },
|
||||
{ ps: 32, name: 'Foreground Green' },
|
||||
{ ps: 33, name: 'Foreground Yellow' },
|
||||
{ ps: 34, name: 'Foreground Blue' },
|
||||
{ ps: 35, name: 'Foreground Magenta' },
|
||||
{ ps: 36, name: 'Foreground Cyan' },
|
||||
{ ps: 37, name: 'Foreground White' },
|
||||
{ ps: 39, name: 'Foreground default' },
|
||||
{ ps: 40, name: 'Background Black' },
|
||||
{ ps: 41, name: 'Background Red' },
|
||||
{ ps: 42, name: 'Background Green' },
|
||||
{ ps: 43, name: 'Background Yellow' },
|
||||
{ ps: 44, name: 'Background Blue' },
|
||||
{ ps: 45, name: 'Background Magenta' },
|
||||
{ ps: 46, name: 'Background Cyan' },
|
||||
{ ps: 47, name: 'Background White' },
|
||||
{ ps: 49, name: 'Background default' },
|
||||
{ ps: 53, name: 'Overlined' },
|
||||
{ ps: 55, name: 'Not overlined' }
|
||||
];
|
||||
const maxNameLength = entries.reduce<number>((p, c) => Math.max(c.name.length, p), 0);
|
||||
for (const e of entries) {
|
||||
term.writeln(`\x1b[0m\x1b[${e.ps}m ${e.ps.toString().padEnd(2, ' ')} ${e.name.padEnd(maxNameLength, ' ')} - ${testString}\x1b[0m`);
|
||||
}
|
||||
const entriesByPs: Map<number, string> = new Map();
|
||||
for (const e of entries) {
|
||||
entriesByPs.set(e.ps, e.name);
|
||||
}
|
||||
const comboEntries: { ps: number[] }[] = [
|
||||
{ ps: [1, 2, 3, 4, 5, 6, 7, 9] },
|
||||
{ ps: [2, 41] },
|
||||
{ ps: [4, 53] }
|
||||
];
|
||||
term.write('\n\n\r');
|
||||
term.writeln(`Combinations`);
|
||||
for (const e of comboEntries) {
|
||||
const name = e.ps.map(e => entriesByPs.get(e)).join(', ');
|
||||
term.writeln(`\x1b[0m\x1b[${e.ps.join(';')}m ${name}\n\r${testString}\x1b[0m`);
|
||||
}
|
||||
}
|
||||
|
||||
function addAnsiHyperlink(term: Terminal): void {
|
||||
term.write('\n\n\r');
|
||||
term.writeln(`Regular link with no id:`);
|
||||
term.writeln('\x1b]8;;https://github.com\x07GitHub\x1b]8;;\x07');
|
||||
term.writeln('\x1b]8;;https://xtermjs.org\x07https://xtermjs.org\x1b]8;;\x07\x1b[C<- null cell');
|
||||
term.writeln(`\nAdjacent links:`);
|
||||
term.writeln('\x1b]8;;https://github.com\x07GitHub\x1b]8;;https://xtermjs.org\x07\x1b[32mxterm.js\x1b[0m\x1b]8;;\x07');
|
||||
term.writeln(`\nShared ID link (underline should be shared):`);
|
||||
term.writeln('╔════╗');
|
||||
term.writeln('║\x1b]8;id=testid;https://github.com\x07GitH\x1b]8;;\x07║');
|
||||
term.writeln('║\x1b]8;id=testid;https://github.com\x07ub\x1b]8;;\x07 ║');
|
||||
term.writeln('╚════╝');
|
||||
term.writeln(`\nWrapped link with no ID (not necessarily meant to share underline):`);
|
||||
term.writeln('╔════╗');
|
||||
term.writeln('║ ║');
|
||||
term.writeln('║ ║');
|
||||
term.writeln('╚════╝');
|
||||
term.write('\x1b[3A\x1b[1C\x1b]8;;https://xtermjs.org\x07xter\x1b[B\x1b[4Dm.js\x1b]8;;\x07\x1b[2B\x1b[5D');
|
||||
}
|
||||
|
||||
function addGraphemeClusters(term: Terminal): void {
|
||||
term.write('\n\n\r');
|
||||
term.writeln('🤣🤣🤣🤣🤣🤣🤣🤣🤣🤣 [Simple emoji v6: 10 cells, v15: 20 cells]');
|
||||
term.writeln('\u{1F476}\u{1F3FF}\u{1F476} [baby with emoji modifier fitzpatrick type-6; baby]');
|
||||
term.writeln('\u{1F469}\u200d\u{1f469}\u200d\u{1f466} [woman+zwj+woman+zwj+boy]');
|
||||
term.writeln('\u{1F64B}\u{1F64B}\u{200D}\u{2642}\u{FE0F} [person/man raising hand]');
|
||||
term.writeln('\u{1F3CB}\u{FE0F}=\u{1F3CB}\u{1F3FE}\u{200D}\u{2640}\u{FE0F} [person lifting weights emoji; woman lighting weights, medium dark]');
|
||||
term.writeln('\u{1F469}\u{1F469}\u{200D}\u{1F393}\u{1F468}\u{1F3FF}\u{200D}\u{1F393} [woman; woman student; man student dark]');
|
||||
term.writeln('\u{1f1f3}\u{1f1f4}_ [REGIONAL INDICATOR SYMBOL LETTER N and RI O]');
|
||||
term.writeln('\u{1f1f3}_\u{1f1f4} {RI N; underscore; RI O]');
|
||||
term.writeln('\u0061\u0301 [letter a with acute accent]');
|
||||
term.writeln('\u1100\u1161\u11A8=\u1100\u1161= [Korean Jamo]');
|
||||
term.writeln('\uAC00=\uD685= [Hangul syllables (pre-composed)]');
|
||||
term.writeln('(\u26b0\ufe0e) [coffin with text_presentation]');
|
||||
term.writeln('(\u26b0\ufe0f) [coffin with Emoji_presentation]');
|
||||
term.writeln('<E\u0301\ufe0fg\ufe0fa\ufe0fl\ufe0fi\ufe0f\ufe0ft\ufe0fe\u0301\ufe0f> [Égalité (using separate acute) emoij_presentation]');
|
||||
}
|
||||
|
||||
function coloredErase(term: Terminal): void {
|
||||
const sp5 = ' ';
|
||||
const data = `
|
||||
Test BG-colored Erase (BCE):
|
||||
The color block in the following lines should look identical.
|
||||
For newly created rows at the bottom the last color should be applied
|
||||
for all cells to the right.
|
||||
|
||||
def 41 42 43 44 45 46 47\x1b[47m
|
||||
\x1b[m${sp5}\x1b[41m${sp5}\x1b[42m${sp5}\x1b[43m${sp5}\x1b[44m${sp5}\x1b[45m${sp5}\x1b[46m${sp5}\x1b[47m${sp5}
|
||||
\x1b[m\x1b[5X\x1b[41m\x1b[5C\x1b[5X\x1b[42m\x1b[5C\x1b[5X\x1b[43m\x1b[5C\x1b[5X\x1b[44m\x1b[5C\x1b[5X\x1b[45m\x1b[5C\x1b[5X\x1b[46m\x1b[5C\x1b[5X\x1b[47m\x1b[5C\x1b[5X\x1b[m
|
||||
`;
|
||||
term.write(data.split('\n').join('\r\n'));
|
||||
}
|
||||
|
||||
function ligaturesTest(term: Terminal): void {
|
||||
term.write([
|
||||
'',
|
||||
'-<< -< -<- <-- <--- <<- <- -> ->> --> ---> ->- >- >>-',
|
||||
'=<< =< =<= <== <=== <<= <= => =>> ==> ===> =>= >= >>=',
|
||||
'<-> <--> <---> <----> <=> <==> <===> <====> :: ::: __',
|
||||
'<~~ </ </> /> ~~> == != /= ~= <> === !== !=== =/= =!=',
|
||||
'<: := *= *+ <* <*> *> <| <|> |> <. <.> .> +* =* =: :>',
|
||||
'(* *) /* */ [| |] {| |} ++ +++ \/ /\ |- -| <!-- <!---',
|
||||
'==== ===== ====== ======= ======== =========',
|
||||
'---- ----- ------ ------- -------- ---------'
|
||||
].join('\r\n'));
|
||||
}
|
||||
|
||||
function testWeblinks(term: Terminal): void {
|
||||
const linkExamples = `
|
||||
aaa http://example.com aaa http://example.com aaa
|
||||
¥¥¥ http://example.com aaa http://example.com aaa
|
||||
aaa http://example.com ¥¥¥ http://example.com aaa
|
||||
¥¥¥ http://example.com ¥¥¥ http://example.com aaa
|
||||
aaa https://ko.wikipedia.org/wiki/위키백과:대문 aaa https://ko.wikipedia.org/wiki/위키백과:대문 aaa
|
||||
¥¥¥ https://ko.wikipedia.org/wiki/위키백과:대문 aaa https://ko.wikipedia.org/wiki/위키백과:대문 ¥¥¥
|
||||
aaa http://test:password@example.com/some_path aaa
|
||||
brackets enclosed:
|
||||
aaa [http://example.de] aaa
|
||||
aaa (http://example.de) aaa
|
||||
aaa <http://example.de> aaa
|
||||
aaa {http://example.de} aaa
|
||||
ipv6 https://[::1]/with/some?vars=and&a#hash aaa
|
||||
stop at final '.': This is a sentence with an url to http://example.com.
|
||||
stop at final '?': Is this the right url http://example.com/?
|
||||
stop at final '?': Maybe this one http://example.com/with?arguments=false?
|
||||
`;
|
||||
term.write(linkExamples.split('\n').join('\r\n'));
|
||||
}
|
||||
|
||||
function loadTest(term: Terminal, addons: AddonCollection): void {
|
||||
const rendererName = addons.webgl.instance ? 'webgl' : 'dom';
|
||||
const testData = [];
|
||||
let byteCount = 0;
|
||||
for (let i = 0; i < 50; i++) {
|
||||
const count = 1 + Math.floor(Math.random() * 79);
|
||||
byteCount += count + 2;
|
||||
const data = new Uint8Array(count + 2);
|
||||
data[0] = 0x0A; // \n
|
||||
for (let i = 1; i < count + 1; i++) {
|
||||
data[i] = 0x61 + Math.floor(Math.random() * (0x7A - 0x61));
|
||||
}
|
||||
// End each line with \r so the cursor remains constant, this is what ls/tree do and improves
|
||||
// performance significantly due to the cursor DOM element not needing to change
|
||||
data[data.length - 1] = 0x0D; // \r
|
||||
testData.push(data);
|
||||
}
|
||||
const start = performance.now();
|
||||
for (let i = 0; i < 1024; i++) {
|
||||
for (const d of testData) {
|
||||
term.write(d);
|
||||
}
|
||||
}
|
||||
// Wait for all data to be parsed before evaluating time
|
||||
term.write('', () => {
|
||||
const time = Math.round(performance.now() - start);
|
||||
const mbs = ((byteCount / 1024) * (1 / (time / 1000))).toFixed(2);
|
||||
term.write(`\n\r\nWrote ${byteCount}kB in ${time}ms (${mbs}MB/s) using the (${rendererName} renderer)`);
|
||||
// Send ^C to get a new prompt
|
||||
(term as any)._core._onData.fire('\x03');
|
||||
});
|
||||
}
|
||||
|
||||
function loadTestLongLines(term: Terminal, addons: AddonCollection): void {
|
||||
const rendererName = addons.webgl.instance ? 'webgl' : 'dom';
|
||||
const testData = [];
|
||||
let byteCount = 0;
|
||||
for (let i = 0; i < 50; i++) {
|
||||
const count = 1 + Math.floor(Math.random() * 500);
|
||||
byteCount += count + 2;
|
||||
const data = new Uint8Array(count + 2);
|
||||
data[0] = 0x0A; // \n
|
||||
for (let i = 1; i < count + 1; i++) {
|
||||
data[i] = 0x61 + Math.floor(Math.random() * (0x7A - 0x61));
|
||||
}
|
||||
// End each line with \r so the cursor remains constant, this is what ls/tree do and improves
|
||||
// performance significantly due to the cursor DOM element not needing to change
|
||||
data[data.length - 1] = 0x0D; // \r
|
||||
testData.push(data);
|
||||
}
|
||||
const start = performance.now();
|
||||
for (let i = 0; i < 1024 * 50; i++) {
|
||||
for (const d of testData) {
|
||||
term.write(d);
|
||||
}
|
||||
}
|
||||
// Wait for all data to be parsed before evaluating time
|
||||
term.write('', () => {
|
||||
const time = Math.round(performance.now() - start);
|
||||
const mbs = ((byteCount / 1024) * (1 / (time / 1000))).toFixed(2);
|
||||
term.write(`\n\r\nWrote ${byteCount}kB in ${time}ms (${mbs}MB/s) using the (${rendererName} renderer)`);
|
||||
// Send ^C to get a new prompt
|
||||
(term as any)._core._onData.fire('\x03');
|
||||
});
|
||||
}
|
||||
|
||||
function addDecoration(term: Terminal): void {
|
||||
term.options['overviewRuler'] = { width: 14 };
|
||||
const marker = term.registerMarker(1);
|
||||
const decoration = term.registerDecoration({
|
||||
marker,
|
||||
backgroundColor: '#00FF00',
|
||||
foregroundColor: '#00FE00',
|
||||
overviewRulerOptions: { color: '#ef292980', position: 'left' }
|
||||
});
|
||||
decoration.onRender((e: HTMLElement) => {
|
||||
e.style.right = '100%';
|
||||
e.style.backgroundColor = '#ef292980';
|
||||
});
|
||||
}
|
||||
|
||||
function addOverviewRuler(term: Terminal): void {
|
||||
term.options['overviewRuler'] = { width: 14 };
|
||||
term.registerDecoration({ marker: term.registerMarker(1), overviewRulerOptions: { color: '#ef2929' } });
|
||||
term.registerDecoration({ marker: term.registerMarker(3), overviewRulerOptions: { color: '#8ae234' } });
|
||||
term.registerDecoration({ marker: term.registerMarker(5), overviewRulerOptions: { color: '#729fcf' } });
|
||||
term.registerDecoration({ marker: term.registerMarker(7), overviewRulerOptions: { color: '#ef2929', position: 'left' } });
|
||||
term.registerDecoration({ marker: term.registerMarker(7), overviewRulerOptions: { color: '#8ae234', position: 'center' } });
|
||||
term.registerDecoration({ marker: term.registerMarker(7), overviewRulerOptions: { color: '#729fcf', position: 'right' } });
|
||||
term.registerDecoration({ marker: term.registerMarker(10), overviewRulerOptions: { color: '#8ae234', position: 'center' } });
|
||||
term.registerDecoration({ marker: term.registerMarker(10), overviewRulerOptions: { color: '#ffffff80', position: 'full' } });
|
||||
}
|
||||
|
||||
let decorationStressTestDecorations: IDisposable[] | undefined;
|
||||
function decorationStressTest(term: Terminal): void {
|
||||
if (decorationStressTestDecorations) {
|
||||
for (const d of decorationStressTestDecorations) {
|
||||
d.dispose();
|
||||
}
|
||||
decorationStressTestDecorations = undefined;
|
||||
} else {
|
||||
const buffer = term.buffer.active;
|
||||
const cursorY = buffer.baseY + buffer.cursorY;
|
||||
decorationStressTestDecorations = [];
|
||||
for (const x of [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95]) {
|
||||
for (let y = 0; y < term.buffer.active.length; y++) {
|
||||
const cursorOffsetY = y - cursorY;
|
||||
decorationStressTestDecorations.push(term.registerDecoration({
|
||||
marker: term.registerMarker(cursorOffsetY),
|
||||
x,
|
||||
width: 4,
|
||||
backgroundColor: '#FF0000',
|
||||
overviewRulerOptions: { color: '#FF0000' }
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function initProgress(term: Terminal, addons: AddonCollection): void {
|
||||
const STATES = { 0: 'remove', 1: 'set', 2: 'error', 3: 'indeterminate', 4: 'pause' };
|
||||
const COLORS = { 0: '', 1: 'green', 2: 'red', 3: '', 4: 'yellow' };
|
||||
|
||||
function progressHandler({ state, value }: IProgressState): void {
|
||||
// Simulate windows taskbar hack by windows terminal:
|
||||
// Since the taskbar has no means to indicate error/pause state other than by coloring
|
||||
// the current progress, we move 0 to 10% and distribute higher values in the remaining 90 %
|
||||
// NOTE: This is most likely not what you want to do for other progress indicators,
|
||||
// that have a proper visual state for error/paused.
|
||||
value = Math.min(10 + value * 0.9, 100);
|
||||
document.getElementById('progress-percent').style.width = `${value}%`;
|
||||
document.getElementById('progress-percent').style.backgroundColor = COLORS[state];
|
||||
document.getElementById('progress-state').innerText = `State: ${STATES[state]}`;
|
||||
|
||||
document.getElementById('progress-percent').style.display = state === 3 ? 'none' : 'block';
|
||||
document.getElementById('progress-indeterminate').style.display = state === 3 ? 'block' : 'none';
|
||||
}
|
||||
|
||||
const progressAddon = addons.progress.instance;
|
||||
progressAddon.onChange(progressHandler);
|
||||
|
||||
// apply initial state once to make it visible on page load
|
||||
const initialProgress = progressAddon.progress;
|
||||
progressHandler(initialProgress);
|
||||
|
||||
document.getElementById('progress-run').addEventListener('click', async () => {
|
||||
term.write('\x1b]9;4;0\x1b\\');
|
||||
for (let i = 0; i <= 100; i += 5) {
|
||||
term.write(`\x1b]9;4;1;${i}\x1b\\`);
|
||||
await new Promise(res => setTimeout(res, 200));
|
||||
}
|
||||
});
|
||||
document.getElementById('progress-0').addEventListener('click', () => term.write('\x1b]9;4;0\x1b\\'));
|
||||
document.getElementById('progress-1').addEventListener('click', () => term.write('\x1b]9;4;1;20\x1b\\'));
|
||||
document.getElementById('progress-2').addEventListener('click', () => term.write('\x1b]9;4;2\x1b\\'));
|
||||
document.getElementById('progress-3').addEventListener('click', () => term.write('\x1b]9;4;3\x1b\\'));
|
||||
document.getElementById('progress-4').addEventListener('click', () => term.write('\x1b]9;4;4\x1b\\'));
|
||||
}
|
||||
|
||||
function initImageAddonExposed(term: Terminal, addons: AddonCollection): void {
|
||||
const DEFAULT_OPTIONS: IImageAddonOptions = (addons.image.instance as any)._defaultOpts;
|
||||
const limitStorageElement = document.querySelector<HTMLInputElement>('#image-storagelimit');
|
||||
limitStorageElement.valueAsNumber = addons.image.instance.storageLimit;
|
||||
addDomListener(term, limitStorageElement, 'change', () => {
|
||||
try {
|
||||
addons.image.instance.storageLimit = limitStorageElement.valueAsNumber;
|
||||
limitStorageElement.valueAsNumber = addons.image.instance.storageLimit;
|
||||
console.log('changed storageLimit to', addons.image.instance.storageLimit);
|
||||
} catch (e) {
|
||||
limitStorageElement.valueAsNumber = addons.image.instance.storageLimit;
|
||||
console.log('storageLimit at', addons.image.instance.storageLimit);
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
const showPlaceholderElement = document.querySelector<HTMLInputElement>('#image-showplaceholder');
|
||||
showPlaceholderElement.checked = addons.image.instance.showPlaceholder;
|
||||
addDomListener(term, showPlaceholderElement, 'change', () => {
|
||||
addons.image.instance.showPlaceholder = showPlaceholderElement.checked;
|
||||
});
|
||||
const ctorOptionsElement = document.querySelector<HTMLTextAreaElement>('#image-options');
|
||||
ctorOptionsElement.value = JSON.stringify(DEFAULT_OPTIONS, null, 2);
|
||||
|
||||
const sixelDemo = (url: string) => () => fetch(url)
|
||||
.then(resp => resp.arrayBuffer())
|
||||
.then(buffer => {
|
||||
term.write('\r\n');
|
||||
term.write(new Uint8Array(buffer));
|
||||
});
|
||||
|
||||
const iipDemo = (url: string) => () => fetch(url)
|
||||
.then(resp => resp.arrayBuffer())
|
||||
.then(buffer => {
|
||||
const data = new Uint8Array(buffer);
|
||||
let sdata = '';
|
||||
for (let i = 0; i < data.length; ++i) sdata += String.fromCharCode(data[i]);
|
||||
term.write('\r\n');
|
||||
term.write(`\x1b]1337;File=inline=1;size=${data.length}:${btoa(sdata)}\x1b\\`);
|
||||
});
|
||||
|
||||
document.getElementById('image-demo1').addEventListener('click',
|
||||
sixelDemo('https://raw.githubusercontent.com/saitoha/libsixel/master/images/snake.six'));
|
||||
document.getElementById('image-demo2').addEventListener('click',
|
||||
sixelDemo('https://raw.githubusercontent.com/jerch/node-sixel/master/testfiles/test2.sixel'));
|
||||
document.getElementById('image-demo3').addEventListener('click',
|
||||
iipDemo('https://raw.githubusercontent.com/jerch/node-sixel/master/palette.png'));
|
||||
|
||||
// demo for image retrieval API
|
||||
term.element.addEventListener('click', (ev: MouseEvent) => {
|
||||
if (!ev.ctrlKey || !addons.image.instance) return;
|
||||
|
||||
// TODO...
|
||||
// if (ev.altKey) {
|
||||
// const sel = term.getSelectionPosition();
|
||||
// if (sel) {
|
||||
// addons.image.instance
|
||||
// .extractCanvasAtBufferRange(term.getSelectionPosition())
|
||||
// ?.toBlob(data => window.open(URL.createObjectURL(data), '_blank'));
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
const pos = (term as any)._core._mouseService!.getCoords(ev, (term as any)._core.screenElement!, term.cols, term.rows);
|
||||
const x = pos[0] - 1;
|
||||
const y = pos[1] - 1;
|
||||
const canvas = ev.shiftKey
|
||||
// ctrl+shift+click: get single tile
|
||||
? addons.image.instance.extractTileAtBufferCell(x, term.buffer.active.viewportY + y)
|
||||
// ctrl+click: get original image
|
||||
: addons.image.instance.getImageAtBufferCell(x, term.buffer.active.viewportY + y);
|
||||
canvas?.toBlob(data => window.open(URL.createObjectURL(data), '_blank'));
|
||||
});
|
||||
}
|
||||
|
||||
function addDomListener(term: Terminal, element: HTMLElement, type: string, handler: (...args: any[]) => any): void {
|
||||
element.addEventListener(type, handler);
|
||||
(term as any)._core._register({ dispose: () => element.removeEventListener(type, handler) });
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* Copyright (c) 2018 The xterm.js authors. All rights reserved.
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { BaseWindow } from './baseWindow';
|
||||
import type { IControlWindow } from '../controlBar';
|
||||
import type { Terminal } from '@xterm/xterm';
|
||||
|
||||
export class VtWindow extends BaseWindow implements IControlWindow {
|
||||
public readonly id = 'vt';
|
||||
public readonly label = 'VT';
|
||||
|
||||
private _container: HTMLElement;
|
||||
private _term: Terminal | undefined;
|
||||
|
||||
public build(container: HTMLElement): void {
|
||||
this._container = container;
|
||||
|
||||
const heading = document.createElement('h3');
|
||||
heading.textContent = 'VT';
|
||||
container.appendChild(heading);
|
||||
|
||||
const vtContainer = document.createElement('div');
|
||||
vtContainer.id = 'vt-container';
|
||||
container.appendChild(vtContainer);
|
||||
|
||||
const vtFragment = document.createDocumentFragment();
|
||||
const buttonSpecs: { [key: string]: { label: string; description: string; paramCount?: number } } = {
|
||||
'A': { label: 'CUU ↑', description: 'Cursor Up Ps Times' },
|
||||
'B': { label: 'CUD ↓', description: 'Cursor Down Ps Times' },
|
||||
'C': { label: 'CUF →', description: 'Cursor Forward Ps Times' },
|
||||
'D': { label: 'CUB ←', description: 'Cursor Backward Ps Times' },
|
||||
'E': { label: 'CNL', description: 'Cursor Next Line Ps Times' },
|
||||
'F': { label: 'CPL', description: 'Cursor Preceding Line Ps Times' },
|
||||
'G': { label: 'CHA', description: 'Cursor Character Absolute' },
|
||||
'H': { label: 'CUP', description: 'Cursor Position [row;column]', paramCount: 2 },
|
||||
'I': { label: 'CHT', description: 'Cursor Forward Tabulation Ps tab stops' },
|
||||
'J': { label: 'ED', description: 'Erase in Display' },
|
||||
'?|J': { label: 'DECSED', description: 'Erase in Display' },
|
||||
'K': { label: 'EL', description: 'Erase in Line' },
|
||||
'?|K': { label: 'DECSEL', description: 'Erase in Line' },
|
||||
'L': { label: 'IL', description: 'Insert Ps Line(s)' },
|
||||
'M': { label: 'DL', description: 'Delete Ps Line(s)' },
|
||||
'P': { label: 'DCH', description: 'Delete Ps Character(s)' },
|
||||
' q': { label: 'DECSCUSR', description: 'Set Cursor Style' },
|
||||
'?2026h': { label: 'BSU', description: 'Begin synchronized update', paramCount: 0 },
|
||||
'?2026l': { label: 'ESU', description: 'End synchronized update', paramCount: 0 }
|
||||
};
|
||||
for (const s of Object.keys(buttonSpecs)) {
|
||||
const spec = buttonSpecs[s];
|
||||
vtFragment.appendChild(this._createButton(spec.label, spec.description, s, spec.paramCount));
|
||||
}
|
||||
|
||||
vtContainer.appendChild(vtFragment);
|
||||
}
|
||||
|
||||
private _createButton(name: string, description: string, writeCsi: string, paramCount: number = 1): HTMLElement {
|
||||
const inputs: HTMLInputElement[] = [];
|
||||
for (let i = 0; i < paramCount; i++) {
|
||||
const input = document.createElement('input');
|
||||
input.type = 'number';
|
||||
input.title = `Input #${i + 1}`;
|
||||
inputs.push(input);
|
||||
}
|
||||
|
||||
const element = document.createElement('button');
|
||||
element.textContent = name;
|
||||
const writeCsiSplit = writeCsi.split('|');
|
||||
const prefix = writeCsiSplit.length === 2 ? writeCsiSplit[0] : '';
|
||||
const suffix = writeCsiSplit[writeCsiSplit.length - 1];
|
||||
element.addEventListener('click', () => this._term?.write(this._csi(`${prefix}${inputs.map(e => e.value).join(';')}${suffix}`)));
|
||||
|
||||
const desc = document.createElement('span');
|
||||
desc.textContent = description;
|
||||
|
||||
const container = document.createElement('div');
|
||||
container.classList.add('vt-button');
|
||||
container.append(element, ...inputs, desc);
|
||||
return container;
|
||||
}
|
||||
|
||||
private _csi(e: string): string {
|
||||
return `\x1b[${e}`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user