-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.js
106 lines (99 loc) · 3.2 KB
/
renderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// This gets the ipc from electron
const ipc = require("electron").ipcRenderer;
const Terminal = require("xterm").Terminal;
const { FitAddon } = require("xterm-addon-fit");
// This imports the webGL addon for xterm, which allows for gpu acceleration
const { WebglAddon } = require("xterm-addon-webgl");
const { LigaturesAddon } = require("xterm-addon-ligatures");
const { ImageAddon } = require("xterm-addon-image");
const { WebLinksAddon } = require("xterm-addon-web-links");
const { Unicode11Addon } = require("xterm-addon-unicode11");
class WebViewLinksAddon extends WebLinksAddon {
openWebLink(link) {
ipcRenderer.send("open-url-in-webview", link);
}
}
const { getTermBG, saveBGColor, getFont, saveFont } = require("./settings");
const bgColor = getTermBG();
const font = getFont();
var term = new Terminal({
theme: {
background: bgColor,
},
fontFamily: font,
// This gives the terminal name to other programs like neofetch
termProgram: "Formalterm",
experimentalCharAtlas: "dynamic",
// This allows xterm.js to use rgba backgrounds
allowTransparency: "true",
cursorBlink: false,
rendererType: "webgl",
allowProposedApi: true,
});
console.log(getTermBG);
document.body.style.backgroundColor = bgColor;
const fitAddon = new FitAddon();
// Writes incoming data from the pty process into xterm.js
ipc.on("terminal.incomingData", (event, data) => {
term.write(data);
term.refresh(0, term.rows - 1);
});
// Does the same kindof
term.onData((e) => {
ipc.send("terminal.keystroke", e);
});
// To debug the background color, enable if needed
// console.log(bgColor);
// This resizes the pty process itself
term.onResize(function (size) {
ipc.send("terminal.resize", size);
});
// This writes the version number into the terminal window
//term.write("Kaiium V1.1.0 ");
// This handles the copy and paste for the pty process
term.attachCustomKeyEventHandler((arg) => {
if (arg.ctrlKey && arg.code === "KeyV" && arg.type === "keydown") {
navigator.clipboard.readText().then((text) => {
term.write(text);
});
}
return true;
});
term.open(document.getElementById("terminal-container"));
const webgl = new WebglAddon();
term.loadAddon(webgl);
term.loadAddon(fitAddon);
fitAddon.fit();
const ligaturesAddon = new LigaturesAddon();
term.loadAddon(ligaturesAddon);
term.loadAddon(new ImageAddon());
term.loadAddon(new WebViewLinksAddon());
term.loadAddon(new Unicode11Addon());
term.onRender = function () {
fitAddon.fit();
};
window.onresize = function () {
// Logs the window dimensions when resized
//log();
fitAddon.fit();
};
/*
if (term.onCursorMove) {
this.disposableListeners.push(
this.term.onCursorMove(() => {
const cursorFrame = {
x:
this.term.buffer.active.cursorX *
this.term._core._renderService.dimensions.actualCellWidth,
y:
this.term.buffer.active.cursorY *
this.term._core._renderService.dimensions.actualCellHeight,
width: this.term._core._renderService.dimensions.actualCellWidth,
height: this.term._core._renderService.dimensions.actualCellHeight,
col: this.term.buffer.active.cursorX,
row: this.term.buffer.active.cursorY,
};
term.onCursorMove?.(cursorFrame);
})
);
}*/