add SerializeAddon in demo page

This commit is contained in:
javacs3
2019-11-21 20:41:46 +08:00
parent d81b4999dc
commit 92709110ef
3 changed files with 29 additions and 0 deletions
+17
View File
@@ -43,6 +43,7 @@ declare let window: IWindowWithTerminal;
let term;
let fitAddon: FitAddon;
let searchAddon: SearchAddon;
let serializeAddon: SerializeAddon;
let protocol;
let socketURL;
let socket;
@@ -96,6 +97,7 @@ if (document.location.pathname === '/test') {
createTerminal();
document.getElementById('dispose').addEventListener('click', disposeRecreateButtonHandler);
document.getElementById('webgl').addEventListener('click', () => term.loadAddon(new WebglAddon()));
document.getElementById('serialize').addEventListener('click', serializeButtonHandler);
}
function createTerminal(): void {
@@ -116,6 +118,8 @@ function createTerminal(): void {
typedTerm.loadAddon(searchAddon);
fitAddon = new FitAddon();
typedTerm.loadAddon(fitAddon);
serializeAddon = new SerializeAddon();
typedTerm.loadAddon(serializeAddon);
window.term = term; // Expose `term` to window for debugging purposes
term.onResize((size: { cols: number, rows: number }) => {
@@ -323,3 +327,16 @@ function updateTerminalSize(): void {
terminalContainer.style.height = height;
fitAddon.fit();
}
function serializeButtonHandler(): void {
const output = serializeAddon.serialize();
const outputString = JSON.stringify(output);
console.log('serialize output', outputString);
document.getElementById('serialize-output').innerText = outputString;
if ((document.getElementById('write-to-terminal') as HTMLInputElement).checked) {
term.reset();
term.write(output);
}
}
+6
View File
@@ -20,6 +20,12 @@
<label>Case sensitive<input type="checkbox" id="case-sensitive"/></label>
<label>Whole word<input type="checkbox" id="whole-word"/></label>
</p>
<div>
<h3>SerializeAddon</h3>
<button id="serialize">Serialize the content of terminal</button>
<label>write to terminal<input type="checkbox" id="write-to-terminal"></label>
<label>Output <code id="serialize-output"></code></label>
</div>
</div>
<div>
<h3>Options</h3>
+6
View File
@@ -30,3 +30,9 @@ p {
padding-left: 20px;
vertical-align: top;
}
code {
padding: 2px 4px;
color: #c7254e;
background-color: #f9f2f4;
}