|
1 | | -import React, { useEffect } from 'react'; |
| 1 | +import React, { useEffect, ChangeEvent } from 'react'; |
2 | 2 | import { XTerm } from 'xterm-for-react'; |
| 3 | +import { TerminalType } from '../../utils/terminalTypes'; |
3 | 4 |
|
4 | 5 | const { Terminal } = require('xterm'); |
5 | 6 | const ipc = require('electron').ipcRenderer; |
6 | 7 |
|
7 | | -const term = new Terminal({ |
| 8 | + |
| 9 | +const terminalArgs: TerminalType = { |
8 | 10 | fontSize: 15, |
9 | 11 | // Currently rows are hardcoded, next step is to make terminal sizing dynamic. |
10 | 12 | rows: 30, |
11 | 13 | fontFamily: 'monospace', |
12 | 14 | theme: { |
13 | 15 | background: '#002a36', |
14 | 16 | }, |
15 | | -}); |
| 17 | +}; |
| 18 | + |
| 19 | +const term = new Terminal(terminalArgs); |
16 | 20 |
|
17 | | -const TerminalGenerator = () => { |
| 21 | +const TerminalView = () => { |
18 | 22 | useEffect(() => { |
19 | 23 | // console.log(global.projectFilePath); |
20 | 24 | term.open(document.getElementsByClassName('terminal')[0]); |
21 | 25 | // when we have input events (e), we would send the data to the main processor |
22 | | - term.onData((e) => { |
| 26 | + term.onData((e: ChangeEvent) => { |
23 | 27 | ipc.send('terminal.toTerm', e); |
24 | 28 | }); |
25 | 29 | // when incoming Data comes back to the main process, this ipc renderer |
26 | 30 | // will take it and writes it to xterm monitor |
27 | | - ipc.on('terminal.incData', (event, data) => { |
| 31 | + ipc.on('terminal.incData', (event, data: string) => { |
28 | 32 | term.write(data); |
29 | 33 | }); |
30 | 34 | }, []); |
31 | 35 |
|
32 | | - return <XTerm className='terminal' />; |
| 36 | + return <XTerm className="terminal" />; |
33 | 37 | }; |
34 | 38 |
|
35 | | -export default TerminalGenerator; |
| 39 | +export default TerminalView; |
0 commit comments