diff --git a/app/src/components/game/TerminalPart.vue b/app/src/components/game/TerminalPart.vue index cb37600..000b60e 100644 --- a/app/src/components/game/TerminalPart.vue +++ b/app/src/components/game/TerminalPart.vue @@ -1,23 +1,34 @@ diff --git a/app/src/store/session.ts b/app/src/store/session.ts index 696c9f1..8e13bd2 100644 --- a/app/src/store/session.ts +++ b/app/src/store/session.ts @@ -11,7 +11,7 @@ import type { Session } from '../types' import { trpc } from '../utils/trpc' const socket = new Socket() -const term = new SocketTerminal(40, 80) +const term = new SocketTerminal() let hasSetup = false interface QuestDetailResponse { diff --git a/app/src/utils/terminal.ts b/app/src/utils/terminal.ts index 969c000..b384844 100644 --- a/app/src/utils/terminal.ts +++ b/app/src/utils/terminal.ts @@ -6,33 +6,39 @@ class SocketTerminal { private term: Terminal private fitAddon: FitAddon - constructor(rows: number, cols: number) { + constructor() { this.term = new Terminal({ - rows, // 行数 - cols, // 不指定行数,自动回车后光标从下一行开始 - convertEol: true, // 启用时,光标将设置为下一行的开头 - // scrollback: 50, //终端中的回滚量 - disableStdin: false, // 是否应禁用输入 - // cursorStyle: "underline", //光标样式 - cursorBlink: true, // 光标闪烁 + convertEol: true, + scrollback: 1000, + fontSize: 16, theme: { - foreground: '#ECECEC', // 字体 - background: '#000000', // 背景色 - cursor: 'help', // 设置光标 + foreground: '#ECECEC', + background: '#000000', + cursor: 'help', }, - fontSize: 18, - fontWeight: 'normal', }) this.fitAddon = new FitAddon() this.term.loadAddon(this.fitAddon) - this.fitAddon.fit() + } + + resizeScreen(): void { + try { + this.fitAddon.fit() + } catch (e) { + console.error('Failed to resize terminal:', e) + } + } + + mount(reference: HTMLElement): void { + this.term.open(reference) + this.resizeScreen() } write(message: string): void { this.term.write(message) } - onData(callback: any): void { + onData(callback: (data: string) => void): void { this.term.onData(callback) } @@ -40,15 +46,6 @@ class SocketTerminal { this.term.focus() } - resizeScreen(): void { - this.fitAddon.fit() - } - - mount(reference: HTMLElement): void { - this.term.open(reference) - this.resizeScreen() - } - reset(): void { this.term.reset() }