mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-03-01 16:20:25 +00:00
refactor: 整体重构 (#1381)
* feat: pnpm new * Refactor build and release workflows, update dependencies Switch build scripts and workflows from npm to pnpm, update build and artifact paths, and simplify release workflow by removing version detection and changelog steps. Add new dependencies (silk-wasm, express, ws, node-pty-prebuilt-multiarch), update exports in package.json files, and add vite config for napcat-framework. Also, rename manifest.json for framework package and fix static asset copying in shell build config.
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
|
||||
import TerminalManager from '@/controllers/terminal_manager';
|
||||
|
||||
import XTerm, { XTermRef } from '../xterm';
|
||||
|
||||
interface TerminalInstanceProps {
|
||||
id: string
|
||||
}
|
||||
|
||||
export function TerminalInstance ({ id }: TerminalInstanceProps) {
|
||||
const termRef = useRef<XTermRef>(null);
|
||||
const connected = useRef(false);
|
||||
|
||||
const handleData = (data: string) => {
|
||||
try {
|
||||
const parsed = JSON.parse(data);
|
||||
if (parsed.data) {
|
||||
termRef.current?.write(parsed.data);
|
||||
}
|
||||
} catch (_e) {
|
||||
termRef.current?.write(data);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
if (connected.current) {
|
||||
TerminalManager.disconnectTerminal(id, handleData);
|
||||
}
|
||||
};
|
||||
}, [id]);
|
||||
|
||||
const handleInput = (data: string) => {
|
||||
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 });
|
||||
} else {
|
||||
TerminalManager.sendResize(id, cols, rows);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<XTerm
|
||||
ref={termRef}
|
||||
onInput={handleInput}
|
||||
onResize={handleResize} // 使用 fitAddon 改变后触发的 resize 回调
|
||||
className='w-full h-full'
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user