-
Notifications
You must be signed in to change notification settings - Fork 1
/
terminal.js
executable file
·72 lines (56 loc) · 1.8 KB
/
terminal.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
const ipc = require("electron").ipcRenderer;
const term = new Terminal({
theme: {
background: '#1f2335',
fontFamily: "JetBrainsMono Nerd Font",
},
});
term.open(document.getElementById('terminal'));
term.resize(80, 14);
ipc.on("terminal.incomingData", (event, data) => {
term.write(data);
});
term.onData(e => {
ipc.send("terminal.keystroke", e);
});
const terminal = document.getElementById('terminal');
let isResizingHeight = false;
let startY, startHeight;
function handleMouseHeightMove(e) {
if (!isResizingHeight) return;
const newHeight = startHeight - (e.clientY - startY);
terminal.style.height = newHeight + 'px';
terminal.style.borderTop = "5px solid #29355a";
}
let hoverTimeout;
terminal.addEventListener('mousemove', (e) => {
const isNearTopEdge = e.offsetY < 6;
clearTimeout(hoverTimeout);
hoverTimeout = setTimeout(() => {
terminal.style.transition = "border-top 0.5s ease";
terminal.style.borderTop = isNearTopEdge ? "5px solid #29355a" : "3px solid #1b1e2e";
}, 300);
terminal.style.cursor = isNearTopEdge ? "row-resize" : "default";
});
terminal.addEventListener('mouseleave', () => {
clearTimeout(hoverTimeout);
terminal.style.transition = "border-top 0.5s ease";
terminal.style.borderTop = "3px solid #1b1e2e";
setTimeout(() => {
terminal.style.transition = "none";
}, 300);
});
terminal.addEventListener('mousedown', (e) => {
const isNearTopEdge = e.offsetY < 6;
if (isNearTopEdge) {
isResizingHeight = true;
startY = e.clientY;
startHeight = terminal.offsetHeight;
document.addEventListener('mousemove', handleMouseHeightMove);
}
});
document.addEventListener('mouseup', () => {
isResizingHeight = false;
document.removeEventListener('mousemove', handleMouseHeightMove);
terminal.style.borderTop = "3px solid #1b1e2e";
});