mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-03-02 08:40:26 +00:00
refactor: 优化eslint配置,提升代码质量 (#1341)
* feat: 统一并标准化eslint * lint: napcat.webui * lint: napcat.webui * lint: napcat.core * build: fix * lint: napcat.webui * refactor: 重构eslint * Update README.md
This commit is contained in:
@@ -1,56 +1,56 @@
|
||||
import { useEffect, useRef } from 'react'
|
||||
import { useEffect, useRef } from 'react';
|
||||
|
||||
import TerminalManager from '@/controllers/terminal_manager'
|
||||
import TerminalManager from '@/controllers/terminal_manager';
|
||||
|
||||
import XTerm, { XTermRef } from '../xterm'
|
||||
import XTerm, { XTermRef } from '../xterm';
|
||||
|
||||
interface TerminalInstanceProps {
|
||||
id: string
|
||||
}
|
||||
|
||||
export function TerminalInstance({ id }: TerminalInstanceProps) {
|
||||
const termRef = useRef<XTermRef>(null)
|
||||
const connected = useRef(false)
|
||||
export function TerminalInstance ({ id }: TerminalInstanceProps) {
|
||||
const termRef = useRef<XTermRef>(null);
|
||||
const connected = useRef(false);
|
||||
|
||||
const handleData = (data: string) => {
|
||||
try {
|
||||
const parsed = JSON.parse(data)
|
||||
const parsed = JSON.parse(data);
|
||||
if (parsed.data) {
|
||||
termRef.current?.write(parsed.data)
|
||||
termRef.current?.write(parsed.data);
|
||||
}
|
||||
} catch (e) {
|
||||
termRef.current?.write(data)
|
||||
} catch (_e) {
|
||||
termRef.current?.write(data);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (connected.current) {
|
||||
TerminalManager.disconnectTerminal(id, handleData)
|
||||
TerminalManager.disconnectTerminal(id, handleData);
|
||||
}
|
||||
}
|
||||
}, [id])
|
||||
};
|
||||
}, [id]);
|
||||
|
||||
const handleInput = (data: string) => {
|
||||
TerminalManager.sendInput(id, data)
|
||||
}
|
||||
TerminalManager.sendInput(id, data);
|
||||
};
|
||||
|
||||
const handleResize = (cols: number, rows: number) => {
|
||||
if (!connected.current) {
|
||||
connected.current = true
|
||||
console.log('instance', rows, cols)
|
||||
TerminalManager.connectTerminal(id, handleData, { rows, cols })
|
||||
connected.current = true;
|
||||
console.log('instance', rows, cols);
|
||||
TerminalManager.connectTerminal(id, handleData, { rows, cols });
|
||||
} else {
|
||||
TerminalManager.sendResize(id, cols, rows)
|
||||
TerminalManager.sendResize(id, cols, rows);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<XTerm
|
||||
ref={termRef}
|
||||
onInput={handleInput}
|
||||
onResize={handleResize} // 使用 fitAddon 改变后触发的 resize 回调
|
||||
className="w-full h-full"
|
||||
className='w-full h-full'
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user