-
Notifications
You must be signed in to change notification settings - Fork 473
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from caorushizi/dev/terminal
Dev/terminal
- Loading branch information
Showing
12 changed files
with
396 additions
and
40 deletions.
There are no files selected for viewing
Submodule internal
updated
from ca43a3 to c37d4e
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React, { FC, useEffect, useRef } from "react"; | ||
import { useStyles } from "./style"; | ||
import "xterm/css/xterm.css"; | ||
import { Terminal as XTerminal } from "xterm"; | ||
import classNames from "classnames"; | ||
import { Button } from "antd"; | ||
import { CloseOutlined } from "@ant-design/icons"; | ||
import useElectron from "../../hooks/electron"; | ||
|
||
interface TerminalProps { | ||
className?: string; | ||
onClose?: () => void; | ||
} | ||
|
||
const Terminal: FC<TerminalProps> = ({ className, onClose }) => { | ||
const { styles } = useStyles(); | ||
const terminalRef = useRef<HTMLDivElement | null>(null); | ||
const { addIpcListener, removeIpcListener } = useElectron(); | ||
|
||
useEffect(() => { | ||
const terminal = new XTerminal({ | ||
rows: 10, | ||
cols: 100, | ||
fontFamily: "Consolas, 'Courier New', monospace", | ||
}); | ||
terminal.open(terminalRef.current); | ||
|
||
const onDownloadMessage = (_: unknown, message: string) => { | ||
terminal.write(message); | ||
}; | ||
|
||
addIpcListener("download-message", onDownloadMessage); | ||
|
||
return () => { | ||
removeIpcListener("download-message", onDownloadMessage); | ||
terminal.dispose(); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<div ref={terminalRef} className={classNames(className, styles.container)}> | ||
<Button | ||
type="text" | ||
icon={<CloseOutlined />} | ||
className={styles.closeBtn} | ||
onClick={onClose} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Terminal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { createStyles } from "antd-style"; | ||
|
||
export const useStyles = createStyles(({ css }) => ({ | ||
container: css` | ||
position: relative; | ||
`, | ||
closeBtn: css` | ||
position: absolute; | ||
top: 5px; | ||
right: 5px; | ||
z-index: 10000; | ||
color: #fff; | ||
&:hover { | ||
color: #fff !important; | ||
} | ||
`, | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.