2017-08-22 06:56:56 +00:00
|
|
|
import * as bare from "libapps";
|
2017-05-21 23:16:24 +00:00
|
|
|
|
2017-08-22 06:59:24 +00:00
|
|
|
export class Hterm {
|
2017-05-21 23:16:24 +00:00
|
|
|
elem: HTMLElement;
|
|
|
|
|
2017-08-22 07:16:28 +00:00
|
|
|
term: bare.hterm.Terminal;
|
|
|
|
io: bare.hterm.IO;
|
2017-05-21 23:16:24 +00:00
|
|
|
|
|
|
|
columns: number;
|
|
|
|
rows: number;
|
|
|
|
|
|
|
|
// to "show" the current message when removeMessage() is called
|
|
|
|
message: string;
|
|
|
|
|
|
|
|
constructor(elem: HTMLElement) {
|
|
|
|
this.elem = elem;
|
2017-08-22 06:56:56 +00:00
|
|
|
bare.hterm.defaultStorage = new bare.lib.Storage.Memory();
|
|
|
|
this.term = new bare.hterm.Terminal();
|
2017-05-21 23:16:24 +00:00
|
|
|
this.term.getPrefs().set("send-encoding", "raw");
|
|
|
|
this.term.decorate(this.elem);
|
|
|
|
|
|
|
|
this.io = this.term.io.push();
|
|
|
|
this.term.installKeyboard();
|
|
|
|
};
|
|
|
|
|
|
|
|
info(): { columns: number, rows: number } {
|
|
|
|
return { columns: this.columns, rows: this.rows };
|
|
|
|
};
|
|
|
|
|
|
|
|
output(data: string) {
|
|
|
|
if (this.term.io != null) {
|
2017-08-26 07:53:17 +00:00
|
|
|
this.term.io.writeUTF8(data);
|
2017-05-21 23:16:24 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
showMessage(message: string, timeout: number) {
|
|
|
|
this.message = message;
|
|
|
|
if (timeout > 0) {
|
|
|
|
this.term.io.showOverlay(message, timeout);
|
|
|
|
} else {
|
|
|
|
this.term.io.showOverlay(message, null);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
removeMessage(): void {
|
|
|
|
// there is no hideOverlay(), so show the same message with 0 sec
|
|
|
|
this.term.io.showOverlay(this.message, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
setWindowTitle(title: string) {
|
|
|
|
this.term.setWindowTitle(title);
|
|
|
|
};
|
|
|
|
|
|
|
|
setPreferences(value: object) {
|
|
|
|
Object.keys(value).forEach((key) => {
|
2021-04-22 19:44:06 +00:00
|
|
|
if (key != "EnableWebGL") {
|
|
|
|
this.term.getPrefs().set(key, value[key]);
|
|
|
|
}
|
2017-05-21 23:16:24 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
onInput(callback: (input: string) => void) {
|
|
|
|
this.io.onVTKeystroke = (data) => {
|
|
|
|
callback(data);
|
|
|
|
};
|
|
|
|
this.io.sendString = (data) => {
|
|
|
|
callback(data);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
onResize(callback: (colmuns: number, rows: number) => void) {
|
|
|
|
this.io.onTerminalResize = (columns: number, rows: number) => {
|
|
|
|
this.columns = columns;
|
|
|
|
this.rows = rows;
|
|
|
|
callback(columns, rows);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
deactivate(): void {
|
2021-04-22 19:44:06 +00:00
|
|
|
this.io.onVTKeystroke = function () { };
|
|
|
|
this.io.sendString = function () { };
|
|
|
|
this.io.onTerminalResize = function () { };
|
2017-05-21 23:16:24 +00:00
|
|
|
this.term.uninstallKeyboard();
|
|
|
|
}
|
|
|
|
|
|
|
|
reset(): void {
|
|
|
|
this.removeMessage();
|
|
|
|
this.term.installKeyboard();
|
|
|
|
}
|
|
|
|
|
|
|
|
close(): void {
|
|
|
|
this.term.uninstallKeyboard();
|
|
|
|
}
|
|
|
|
}
|