-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathindex.ts
More file actions
52 lines (44 loc) · 1.35 KB
/
index.ts
File metadata and controls
52 lines (44 loc) · 1.35 KB
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
import '@xterm/xterm/css/xterm.css';
import { Terminal } from '@xterm/xterm';
import { TerminalAddon } from './terminalAddon';
declare global {
interface Window {
initializeTerminal: () => Terminal;
writeToTerminal: (text: string) => void;
clearTerminal: () => void;
}
}
window.initializeTerminal = function (): Terminal {
const term = new Terminal({
cursorBlink: true,
theme: {
background: '#1e1e1e',
foreground: '#cccccc',
cursor: '#ffffff',
selectionBackground: 'rgba(128, 128, 128, 0.4)'
},
fontFamily: 'Menlo, Monaco, "Courier New", monospace',
fontSize: 13
});
const terminalAddon = new TerminalAddon();
term.loadAddon(terminalAddon);
const terminalElement = document.getElementById('terminal');
if (!terminalElement) {
throw new Error('Terminal element not found');
}
term.open(terminalElement);
terminalAddon.fit();
// Handle window resize
window.addEventListener('resize', () => {
terminalAddon.fit();
});
// Expose terminal API methods
window.writeToTerminal = function (text: string): void {
term.write(text);
terminalAddon.processTerminalOutput(text);
};
window.clearTerminal = function (): void {
term.clear();
};
return term;
}