Get ready to upgrade to xterm.js once the new version is stabilized

This commit is contained in:
Ni Rui
2022-09-20 16:38:58 +08:00
parent 3e3dbddcae
commit bc80b52c84

View File

@@ -138,6 +138,7 @@ class Term {
this.closed = false; this.closed = false;
this.fontSize = termDefaultFontSize; this.fontSize = termDefaultFontSize;
this.term = new Terminal({ this.term = new Terminal({
allowProposedApi: true,
allowTransparency: false, allowTransparency: false,
cursorBlink: true, cursorBlink: true,
cursorStyle: "block", cursorStyle: "block",
@@ -154,7 +155,6 @@ class Term {
if (this.closed) { if (this.closed) {
return; return;
} }
this.control.send(data); this.control.send(data);
}); });
@@ -162,7 +162,6 @@ class Term {
if (this.closed) { if (this.closed) {
return; return;
} }
this.control.sendBinary(data); this.control.sendBinary(data);
}); });
@@ -170,28 +169,23 @@ class Term {
if (this.closed) { if (this.closed) {
return; return;
} }
if (!this.control.echo()) { if (!this.control.echo()) {
return; return;
} }
const printable = const printable =
!ev.domEvent.altKey && !ev.domEvent.altKey &&
!ev.domEvent.altGraphKey && !ev.domEvent.altGraphKey &&
!ev.domEvent.ctrlKey && !ev.domEvent.ctrlKey &&
!ev.domEvent.metaKey; !ev.domEvent.metaKey;
switch (ev.domEvent.key) { switch (ev.domEvent.key) {
case "Enter": case "Enter":
ev.domEvent.preventDefault(); ev.domEvent.preventDefault();
this.writeStr("\r\n"); this.writeStr("\r\n");
break; break;
case "Backspace": case "Backspace":
ev.domEvent.preventDefault(); ev.domEvent.preventDefault();
this.writeStr("\b \b"); this.writeStr("\b \b");
break; break;
default: default:
if (printable) { if (printable) {
ev.domEvent.preventDefault(); ev.domEvent.preventDefault();
@@ -200,49 +194,6 @@ class Term {
} }
}); });
// It seems Xtermjs now handles copy paste by itself, following code is no
// longer useful
// this.term.attachCustomKeyEventHandler(async (ev) => {
// if (this.closed) {
// return true;
// }
// if (
// ev.type == "keyup" &&
// ((ev.key.toLowerCase() === "v" && ev.shiftKey && ev.ctrlKey) ||
// (ev.key === "Insert" && ev.shiftKey))
// ) {
// try {
// let text = await window.navigator.clipboard.readText();
// this.writeEchoStr(text);
// } catch (e) {
// alert(
// "Unable to paste: " +
// e +
// ". Please try again without using the Control+Shift+V / " +
// "Shift+Insert hot key"
// );
// }
// return false;
// }
// if (
// ev.type == "keyup" &&
// ((ev.key.toLowerCase() === "c" && ev.shiftKey && ev.ctrlKey) ||
// (ev.key === "Insert" && ev.ctrlKey))
// ) {
// try {
// window.navigator.clipboard.writeText(this.term.getSelection());
// } catch (e) {
// alert("Unable to copy: " + e);
// }
// return false;
// }
// return true;
// });
let resizeDelay = null, let resizeDelay = null,
oldRows = 0, oldRows = 0,
oldCols = 0; oldCols = 0;
@@ -251,30 +202,23 @@ class Term {
if (this.closed) { if (this.closed) {
return; return;
} }
if (dim.cols === oldCols && dim.rows === oldRows) { if (dim.cols === oldCols && dim.rows === oldRows) {
return; return;
} }
oldRows = dim.rows; oldRows = dim.rows;
oldCols = dim.cols; oldCols = dim.cols;
if (resizeDelay !== null) { if (resizeDelay !== null) {
clearTimeout(resizeDelay); clearTimeout(resizeDelay);
resizeDelay = null; resizeDelay = null;
} }
resizeDelay = setTimeout(() => { resizeDelay = setTimeout(() => {
resizeDelay = null; resizeDelay = null;
if (!isNumber(dim.cols) || !isNumber(dim.rows)) { if (!isNumber(dim.cols) || !isNumber(dim.rows)) {
return; return;
} }
if (!dim.cols || !dim.rows) { if (!dim.cols || !dim.rows) {
return; return;
} }
this.control.resize({ this.control.resize({
rows: dim.rows, rows: dim.rows,
cols: dim.cols, cols: dim.cols,
@@ -287,7 +231,6 @@ class Term {
if (this.closed) { if (this.closed) {
return; return;
} }
this.term.open(root); this.term.open(root);
this.term.loadAddon(this.fit); this.term.loadAddon(this.fit);
this.term.loadAddon(new WebLinksAddon()); this.term.loadAddon(new WebLinksAddon());
@@ -304,7 +247,6 @@ class Term {
// }) { // }) {
// this.term.loadAddon(new WebglAddon()); // this.term.loadAddon(new WebglAddon());
// } // }
this.refit(); this.refit();
} }
@@ -312,7 +254,6 @@ class Term {
if (this.closed) { if (this.closed) {
return; return;
} }
try { try {
this.term.textarea.dispatchEvent(event); this.term.textarea.dispatchEvent(event);
} catch (e) { } catch (e) {
@@ -324,13 +265,10 @@ class Term {
if (this.closed) { if (this.closed) {
return; return;
} }
this.control.send(d); this.control.send(d);
if (!this.control.echo()) { if (!this.control.echo()) {
return; return;
} }
this.writeStr(d); this.writeStr(d);
} }
@@ -338,7 +276,6 @@ class Term {
if (this.closed) { if (this.closed) {
return; return;
} }
try { try {
this.term.write(d); this.term.write(d);
} catch (e) { } catch (e) {
@@ -350,7 +287,6 @@ class Term {
if (this.closed) { if (this.closed) {
return; return;
} }
try { try {
this.term.write(d); this.term.write(d);
} catch (e) { } catch (e) {
@@ -362,7 +298,6 @@ class Term {
if (this.closed) { if (this.closed) {
return; return;
} }
this.term.options.fontFamily = value; this.term.options.fontFamily = value;
this.refit(); this.refit();
} }
@@ -371,11 +306,9 @@ class Term {
if (this.closed) { if (this.closed) {
return; return;
} }
if (this.fontSize >= termMaxFontSize) { if (this.fontSize >= termMaxFontSize) {
return; return;
} }
this.fontSize += 2; this.fontSize += 2;
this.term.options.fontSize = this.fontSize; this.term.options.fontSize = this.fontSize;
this.refit(); this.refit();
@@ -385,11 +318,9 @@ class Term {
if (this.closed) { if (this.closed) {
return; return;
} }
if (this.fontSize <= termMinFontSize) { if (this.fontSize <= termMinFontSize) {
return; return;
} }
this.fontSize -= 2; this.fontSize -= 2;
this.term.options.fontSize = this.fontSize; this.term.options.fontSize = this.fontSize;
this.refit(); this.refit();
@@ -399,7 +330,6 @@ class Term {
if (this.closed) { if (this.closed) {
return; return;
} }
try { try {
this.term.focus(); this.term.focus();
this.refit(); this.refit();
@@ -412,7 +342,6 @@ class Term {
if (this.closed) { if (this.closed) {
return; return;
} }
try { try {
this.term.blur(); this.term.blur();
} catch (e) { } catch (e) {
@@ -424,7 +353,6 @@ class Term {
if (this.closed) { if (this.closed) {
return; return;
} }
try { try {
this.fit.fit(); this.fit.fit();
} catch (e) { } catch (e) {
@@ -440,9 +368,7 @@ class Term {
if (this.closed) { if (this.closed) {
return; return;
} }
this.closed = true; this.closed = true;
try { try {
this.term.dispose(); this.term.dispose();
} catch (e) { } catch (e) {