mirror of
https://github.com/yudai/gotty.git
synced 2026-02-22 16:04:09 +01:00
Update xterm libary to 4.17
Mostly a copy and paste from this community patch.
aee8f007f9
This commit is contained in:
parent
ab9ea2b95f
commit
48b972da9d
14 changed files with 2735 additions and 2352 deletions
|
|
@ -1,40 +1,52 @@
|
|||
import * as bare from "xterm";
|
||||
import { lib } from "libapps"
|
||||
import {lib} from "libapps";
|
||||
|
||||
import {IDisposable, Terminal} from 'xterm';
|
||||
import {FitAddon} from "xterm-addon-fit";
|
||||
|
||||
bare.loadAddon("fit");
|
||||
|
||||
export class Xterm {
|
||||
elem: HTMLElement;
|
||||
term: bare;
|
||||
term: Terminal;
|
||||
resizeListener: () => void;
|
||||
decoder: lib.UTF8Decoder;
|
||||
|
||||
message: HTMLElement;
|
||||
messageTimeout: number;
|
||||
messageTimer: number;
|
||||
messageTimer: NodeJS.Timer;
|
||||
|
||||
fitAddon: FitAddon;
|
||||
disposables: IDisposable[] = [];
|
||||
|
||||
|
||||
constructor(elem: HTMLElement) {
|
||||
this.elem = elem;
|
||||
this.term = new bare();
|
||||
const isWindows = ['Windows', 'Win16', 'Win32', 'WinCE'].indexOf(navigator.platform) >= 0;
|
||||
this.term = new Terminal({
|
||||
cursorStyle: "block",
|
||||
cursorBlink: true,
|
||||
windowsMode: isWindows,
|
||||
fontFamily: "DejaVu Sans Mono, Everson Mono, FreeMono, Menlo, Terminal, monospace, Apple Symbols",
|
||||
fontSize: 12,
|
||||
});
|
||||
|
||||
this.fitAddon = new FitAddon();
|
||||
this.term.loadAddon(this.fitAddon);
|
||||
|
||||
this.message = elem.ownerDocument.createElement("div");
|
||||
this.message.className = "xterm-overlay";
|
||||
this.messageTimeout = 2000;
|
||||
|
||||
this.resizeListener = () => {
|
||||
this.term.fit();
|
||||
this.fitAddon.fit();
|
||||
this.term.scrollToBottom();
|
||||
this.showMessage(String(this.term.cols) + "x" + String(this.term.rows), this.messageTimeout);
|
||||
};
|
||||
|
||||
this.term.on("open", () => {
|
||||
this.resizeListener();
|
||||
window.addEventListener("resize", () => { this.resizeListener(); });
|
||||
});
|
||||
this.term.open(elem);
|
||||
|
||||
this.term.open(elem, true);
|
||||
this.term.focus()
|
||||
this.resizeListener();
|
||||
window.addEventListener("resize", () => { this.resizeListener(); });
|
||||
|
||||
this.decoder = new lib.UTF8Decoder()
|
||||
};
|
||||
|
|
@ -75,21 +87,20 @@ export class Xterm {
|
|||
};
|
||||
|
||||
onInput(callback: (input: string) => void) {
|
||||
this.term.on("data", (data) => {
|
||||
callback(data);
|
||||
});
|
||||
this.disposables.push(this.term.onData((data) => {
|
||||
callback(data);
|
||||
}));
|
||||
|
||||
};
|
||||
|
||||
onResize(callback: (colmuns: number, rows: number) => void) {
|
||||
this.term.on("resize", (data) => {
|
||||
callback(data.cols, data.rows);
|
||||
});
|
||||
this.disposables.push(this.term.onResize((data) => {
|
||||
callback(data.cols, data.rows);
|
||||
}));
|
||||
};
|
||||
|
||||
deactivate(): void {
|
||||
this.term.off("data");
|
||||
this.term.off("resize");
|
||||
this.disposables.forEach(d => d.dispose())
|
||||
this.term.blur();
|
||||
}
|
||||
|
||||
|
|
@ -100,6 +111,6 @@ export class Xterm {
|
|||
|
||||
close(): void {
|
||||
window.removeEventListener("resize", this.resizeListener);
|
||||
this.term.destroy();
|
||||
this.term.dispose();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue