parent
5a0d0453b1
commit
1ab6a5219d
@ -1,48 +1,68 @@ |
||||
import React, { useState, useEffect, forwardRef } from 'react' // eslint-disable-line
|
||||
import { ElectronPlugin } from '@remixproject/engine-electron' |
||||
import { Xterm } from './xterm-wrap' |
||||
import { FitAddon } from './xterm-fit-addOn'; |
||||
import React, {useState, useEffect, forwardRef} from 'react' // eslint-disable-line
|
||||
import {ElectronPlugin} from '@remixproject/engine-electron' |
||||
import {Xterm} from './xterm-wrap' |
||||
import {FitAddon} from './xterm-fit-addOn' |
||||
|
||||
const config = { |
||||
fontSize: 12, |
||||
fontFamily: |
||||
'Menlo, "DejaVu Sans Mono", Consolas, "Lucida Console", monospace', |
||||
fontWeight: 'normal', |
||||
fontWeightBold: 'bold', |
||||
lineHeight: 1, |
||||
letterSpacing: 0, |
||||
} |
||||
|
||||
const fitAddon = new FitAddon() |
||||
|
||||
export interface RemixUiXtermProps { |
||||
plugin: ElectronPlugin |
||||
pid: number |
||||
send: (data: string, pid: number) => void |
||||
timeStamp: number |
||||
setTerminalRef: (pid: number, ref: any) => void |
||||
theme: { |
||||
backgroundColor: string |
||||
textColor: string |
||||
} |
||||
plugin: ElectronPlugin |
||||
pid: number |
||||
send: (data: string, pid: number) => void |
||||
resize: (event: { cols: number; rows: number }, pid: number) => void |
||||
timeStamp: number |
||||
setTerminalRef: (pid: number, ref: any) => void |
||||
theme: { |
||||
backgroundColor: string |
||||
textColor: string |
||||
} |
||||
} |
||||
|
||||
const RemixUiXterm = (props: RemixUiXtermProps) => { |
||||
const { plugin, pid, send, timeStamp } = props |
||||
const {plugin, pid, send, timeStamp, theme, resize} = props |
||||
const xtermRef = React.useRef(null) |
||||
|
||||
|
||||
useEffect(() => { |
||||
props.setTerminalRef(pid, xtermRef.current) |
||||
}, [xtermRef.current]) |
||||
|
||||
const onKey = (event: { key: string; domEvent: KeyboardEvent }) => { |
||||
const onKey = (event: {key: string; domEvent: KeyboardEvent}) => { |
||||
send(event.key, pid) |
||||
} |
||||
|
||||
return ( |
||||
const onResize = (event: { cols: number; rows: number }) => { |
||||
resize(event, pid) |
||||
} |
||||
|
||||
return ( |
||||
<Xterm |
||||
addons={[fitAddon]} |
||||
options={{ theme: { background: props.theme.backgroundColor, foreground: props.theme.textColor } }} |
||||
options={{ |
||||
theme: { |
||||
background: theme.backgroundColor, |
||||
foreground: theme.textColor, |
||||
}, |
||||
fontFamily: config.fontFamily, |
||||
fontSize: config.fontSize, |
||||
letterSpacing: config.letterSpacing, |
||||
lineHeight: config.lineHeight, |
||||
}} |
||||
onResize={onResize} |
||||
onRender={() => fitAddon.fit()} |
||||
ref={xtermRef} |
||||
onKey={onKey}></Xterm> |
||||
|
||||
|
||||
onKey={onKey} |
||||
></Xterm> |
||||
) |
||||
|
||||
} |
||||
|
||||
export default RemixUiXterm |
||||
export default RemixUiXterm |
||||
|
Loading…
Reference in new issue