Skip to content

Commit

Permalink
fix: 完善
Browse files Browse the repository at this point in the history
  • Loading branch information
youngster-yj committed Jul 8, 2024
1 parent ba439ea commit 07e1136
Show file tree
Hide file tree
Showing 20 changed files with 310 additions and 101 deletions.
8 changes: 8 additions & 0 deletions app/main/handlers/yakRunnerTerminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ module.exports = (win, getClient) => {
})
}
})
ipcMain.handle("runner-terminal-size", async (e, path, size) => {
const stream = getStreamByPort(path)
if (stream) {
stream.write({
...size
})
}
})
ipcMain.handle("runner-terminal-cancel", async (e, path) => {
removeStreamPort(path)
})
Expand Down
2 changes: 2 additions & 0 deletions app/protos/grpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5011,6 +5011,8 @@ message Input {
string host = 2;
uint32 port = 3;
string path = 4;
uint32 width = 5;
uint32 height = 6;
}

message Output {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {ipcRenderer} = window.require("electron")

export const AuditCode: React.FC<AuditCodeProps> = (props) => {
useEffect(() => {
console.log("我是audit-code")
// console.log("我是audit-code")
}, [])
return <div className={styles["audit-code"]}>我是audit-code</div>
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
.extra {
margin-right: 8px;
display: flex;
align-items: center;
gap: 8px;
}
}
Expand Down Expand Up @@ -83,3 +84,40 @@
}
}
}


.codec-menu-popover {
.codec-menu-cont-wrapper {
.codec-menu-item {
display: flex;
justify-content: space-between;
padding: 6px 8px;
cursor: pointer;
color: #000000;
font-size: 14px;
line-height: 20px;
width: 130px;
&.active {
color: var(--yakit-primary-5);
}
&:hover {
background-color: var(--yakit-primary-1);
}
.check-icon {
svg {
color: var(--yakit-primary-5);
}
}
}
}
:global {
.ant-popover-inner {
border: 1px solid var(--yakit-border-color);
box-shadow: 0px 8px 16px rgba(133, 137, 158, 0.1);
border-radius: 4px;
.ant-popover-inner-content {
padding: 6px 4px 4px 4px;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ import {XTerm} from "xterm-for-react"
import {YakitSystem} from "@/yakitGVDefine"
import {TerminalBox} from "./TerminalBox/TerminalBox"
import {System, SystemInfo, handleFetchSystem} from "@/constants/hardware"
import {YakitPopover} from "@/components/yakitUI/YakitPopover/YakitPopover"
import {SolidCheckIcon} from "@/assets/icon/solid"
import {ChevronDownIcon, ChevronUpIcon} from "@/assets/newIcon"
const {ipcRenderer} = window.require("electron")

// 编辑器区域 展示详情(输出/语法检查/终端/帮助信息)

export const BottomEditorDetails: React.FC<BottomEditorDetailsProps> = (props) => {
const {isShowEditorDetails,setEditorDetails, showItem, setShowItem} = props
const {isShowEditorDetails, setEditorDetails, showItem, setShowItem} = props

const systemRef = useRef<System | undefined>(SystemInfo.system)
useEffect(() => {
Expand All @@ -38,16 +41,20 @@ export const BottomEditorDetails: React.FC<BottomEditorDetailsProps> = (props) =
}
}, [])

const {activeFile,fileTree} = useStore()
const {activeFile, fileTree} = useStore()
// 不再重新加载的元素
const [showType, setShowType] = useState<ShowItemType[]>([])

// 终端编码
const [codeKey, setCodeKey] = useState<string>("")
const [codeShow, setCodeShow] = useState<boolean>(false)

// 数组去重
const filterItem = (arr) => arr.filter((item, index) => arr.indexOf(item) === index)

useEffect(() => {
if (showItem && isShowEditorDetails) {
if(showType.includes(showItem)) return
if (showType.includes(showItem)) return
setShowType((arr) => filterItem([...arr, showItem]))
}
}, [showItem, isShowEditorDetails])
Expand All @@ -74,7 +81,7 @@ export const BottomEditorDetails: React.FC<BottomEditorDetailsProps> = (props) =
try {
const {type}: {type: ShowItemType} = JSON.parse(v)
// 执行时需要清空输出
if(type === "output"){
if (type === "output") {
xtermClear(xtermRef)
}
setEditorDetails(true)
Expand Down Expand Up @@ -110,15 +117,31 @@ export const BottomEditorDetails: React.FC<BottomEditorDetailsProps> = (props) =
}
}, [xtermRef])

// 终端path为文件树根路径
const folderPath = useMemo(() => {
// 终端路径
const [folderPath, setFolderPath] = useState<string>("")

useEffect(() => {
if (fileTree.length > 0) {
return fileTree[0].path
setFolderPath(fileTree[0].path)
} else {
return ""
setFolderPath("")
}
}, [fileTree])

const onOpenTernimalFun = useMemoizedFn((path) => {
setEditorDetails(true)
setShowItem("terminal")
setFolderPath(path)
})

// 监听终端更改
useEffect(() => {
emiter.on("onOpenTernimal", onOpenTernimalFun)
return () => {
emiter.off("onOpenTernimal", onOpenTernimalFun)
}
}, [])

return (
<div className={styles["bottom-editor-details"]}>
<div className={styles["header"]}>
Expand Down Expand Up @@ -162,12 +185,62 @@ export const BottomEditorDetails: React.FC<BottomEditorDetailsProps> = (props) =
</div>
</div>
<div className={styles["extra"]}>
{showItem === "terminal" && (
<YakitPopover
trigger='click'
overlayClassName={styles["codec-menu-popover"]}
overlayStyle={{paddingTop: 2}}
placement='bottomLeft'
content={
<div className={styles["codec-menu-cont-wrapper"]}>
{[
{label: "gb18030", codeKey: "gb18030"},
{label: "windows-1252", codeKey: "windows-1252"},
{label: "iso-8859-1", codeKey: "iso-8859-1"},
{label: "big5", codeKey: "big5"},
{label: "utf-16", codeKey: "utf-16"}
].map((item) => (
<div
key={item.codeKey}
className={classNames(styles["codec-menu-item"], {
[styles["active"]]: codeKey === item.codeKey
})}
onClick={() => {
// handleClickCoding(item.codeKey)
if (codeKey === item.codeKey) {
setCodeKey("")
} else {
setCodeKey(item.codeKey)
}
}}
>
{item.label}
{codeKey === item.codeKey && (
<SolidCheckIcon className={styles["check-icon"]} />
)}
</div>
))}
</div>
}
visible={codeShow}
onVisibleChange={(visible) => setCodeShow(visible)}
>
<YakitButton
size='small'
type={codeKey !== "" ? "primary" : "outline2"}
onClick={(e) => e.preventDefault()}
>
编码
{codeShow ? <ChevronUpIcon /> : <ChevronDownIcon />}
</YakitButton>
</YakitPopover>
)}
{showItem === "terminal" && (
<YakitButton
type='text2'
icon={<OutlineTrashIcon />}
onClick={() => {
ipcRenderer.invoke("runner-terminal-cancel",folderPath).finally(() => {
ipcRenderer.invoke("runner-terminal-cancel", folderPath).finally(() => {
setEditorDetails(false)
// 重新渲染
setShowType(showType.filter((item) => item !== "terminal"))
Expand Down Expand Up @@ -217,7 +290,11 @@ export const BottomEditorDetails: React.FC<BottomEditorDetailsProps> = (props) =
{/* {systemRef.current === "Windows_NT" ? (
<div className={styles["no-syntax-check"]}>终端监修中</div>
) : ( */}
<TerminalBox folderPath={folderPath} isShowEditorDetails={isShowEditorDetails}/>
<TerminalBox
folderPath={folderPath}
isShowEditorDetails={isShowEditorDetails}
codeKey={codeKey}
/>
{/* )} */}
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.syntax-check-list {
height: 100%;
overflow: hidden;
overflow: auto;
.syntax-check-item {
display: flex;
flex-direction: row;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ import {writeXTerm, xtermClear, xtermFit} from "@/utils/xtermUtils"
import {TERMINAL_INPUT_KEY, YakitCVXterm} from "@/components/yakitUI/YakitCVXterm/YakitCVXterm"
import useStore from "../../hooks/useStore"
import {YakitHint} from "@/components/yakitUI/YakitHint/YakitHint"
import { StringToUint8Array, Uint8ArrayToString } from "@/utils/str"
import {StringToUint8Array, Uint8ArrayToString} from "@/utils/str"
import {number} from "echarts"

const {ipcRenderer} = window.require("electron")

export interface TerminalBoxProps {
isShowEditorDetails: boolean
folderPath: string
codeKey: string
}
export const TerminalBox: React.FC<TerminalBoxProps> = (props) => {
const {isShowEditorDetails,folderPath} = props
const {isShowEditorDetails, folderPath, codeKey} = props
const xtermRef = useRef<any>(null)
// 是否允许输入及不允许输入的原因
const [allowInput, setAllowInput] = useState<boolean>(true)
Expand All @@ -34,15 +36,65 @@ export const TerminalBox: React.FC<TerminalBoxProps> = (props) => {
ipcRenderer.invoke("runner-terminal-input", folderPath, cmd)
})

// 行列变化
const onChangeSize = useMemoizedFn((height, width) => {
if (height && width && folderPath) {
ipcRenderer.invoke("runner-terminal-size", folderPath, {
height,
width
})
}
})

const fetchNewCodec = useMemoizedFn((data: Uint8Array, codeKey: string) => {
const newCodecParams = {
InputBytes: data,
WorkFlow: [
{
CodecType: "CharsetToUTF8",
Params: [
{
Key: "charset",
Value: codeKey
}
]
}
]
}
ipcRenderer
.invoke("NewCodec", newCodecParams)
.then((data: {Result: string; RawResult: Uint8Array}) => {
let outPut = Uint8ArrayToString(data.RawResult)
writeXTerm(xtermRef, outPut)
// onSetCodeValue(data.RawResult)
})
.catch((e) => {
let outPut = Uint8ArrayToString(data)
writeXTerm(xtermRef, outPut)
failed(e)
})
.finally(() => {})
})

// 输出
const onWriteXTerm = useMemoizedFn((data: Uint8Array) => {
let outPut = Uint8ArrayToString(data)
if (codeKey) {
fetchNewCodec(data, codeKey)
} else {
writeXTerm(xtermRef, outPut)
}
})

// 终端启用路径
const startTerminalPath = useRef<string>()

useEffect(() => {
if (!xtermRef) {
return
}
if(startTerminalPath.current){
ipcRenderer.invoke("runner-terminal-cancel",startTerminalPath.current)
if (startTerminalPath.current) {
ipcRenderer.invoke("runner-terminal-cancel", startTerminalPath.current)
startTerminalPath.current = undefined
}
setAllowInput(true)
Expand All @@ -53,7 +105,7 @@ export const TerminalBox: React.FC<TerminalBoxProps> = (props) => {
})
.then(() => {
startTerminalPath.current = folderPath
isShowEditorDetails&&success(`终端${folderPath}监听成功`)
isShowEditorDetails && success(`终端${folderPath}监听成功`)
})
.catch((e: any) => {
failed(`ERROR: ${JSON.stringify(e)}`)
Expand All @@ -68,10 +120,7 @@ export const TerminalBox: React.FC<TerminalBoxProps> = (props) => {
}

if (data?.raw && xtermRef?.current && xtermRef.current?.terminal) {
// let str = String.fromCharCode.apply(null, data.raw);
let str = Uint8ArrayToString(data.raw)

writeXTerm(xtermRef, str)
onWriteXTerm(data.raw)
}
})

Expand All @@ -83,10 +132,10 @@ export const TerminalBox: React.FC<TerminalBoxProps> = (props) => {
// grpc通知关闭
const errorKey = "client-listening-terminal-end"
ipcRenderer.on(errorKey, (e: any, data: any) => {
if(startTerminalPath.current === data){
if (startTerminalPath.current === data) {
setAllowInput(false)
}
isShowEditorDetails&&warn(`终端${data}被关闭`)
isShowEditorDetails && warn(`终端${data}被关闭`)
})
return () => {
// 移除
Expand All @@ -108,6 +157,7 @@ export const TerminalBox: React.FC<TerminalBoxProps> = (props) => {
if (!width || !height) return
const row = Math.floor(height / 18.5)
const col = Math.floor(width / 10)
onChangeSize(row, col)
if (xtermRef) xtermFit(xtermRef, col, row)
}}
handleWidth={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
overflow: hidden auto;
}

.to-end {
text-align: center;
color: var(--yakit-disable-text-color);
font-size: 11px;
line-height: 14px;
padding-top: 24px;
padding-bottom: 24px;
}

.collapse-list-base {
:global {
.ant-collapse-item > .ant-collapse-header {
Expand Down
Loading

0 comments on commit 07e1136

Please sign in to comment.