fix: terminal overflow

This commit is contained in:
Justin Lin committed 2025-04-26 11:46:36 +08:00
1 parent 53c5391f61
commit 937c5de6b8
3 files changed
+38 -30

No files matched your search

+17 -6
View File
@@ -1,23 +1,34 @@
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, ref } from 'vue' import { onMounted, onUnmounted, ref } from 'vue'
import { useTerminal } from '../../store/session' import { useTerminal } from '../../store/session'
const terminal = ref<HTMLElement | null>(null) const terminal = ref<HTMLElement | null>(null)
const term = useTerminal()
onMounted(() => { onMounted(() => {
const term = useTerminal()
if (!terminal.value) return if (!terminal.value) return
term.mount(terminal.value) term.mount(terminal.value)
window.addEventListener('resize', () => term.resizeScreen())
const handleResize = () => term.resizeScreen()
window.addEventListener('resize', handleResize)
onUnmounted(() => {
window.removeEventListener('resize', handleResize)
})
}) })
</script> </script>
<template> <template>
<font-awesome-icon :icon="['fas', 'terminal']" class="text-text p-1" /> <div class="flex flex-col h-full">
<button id="Terminal" class="text-text h-[5%]">終端機</button> <div class="flex items-center gap-2 p-1">
<font-awesome-icon :icon="['fas', 'terminal']" class="text-text" />
<button id="Terminal" class="text-text">終端機</button>
</div>
<div <div
id="terminal" id="terminal"
ref="terminal" ref="terminal"
class="bg-bg-secondary h-[calc(100%-5%)] p-0.5" class="bg-bg-secondary flex-grow overflow-hidden px-2"
style="height: calc(100vh - 40px)"
></div> ></div>
</div>
</template> </template>
+1 -1
View File
@@ -11,7 +11,7 @@ import type { Session } from '../types'
import { trpc } from '../utils/trpc' import { trpc } from '../utils/trpc'
const socket = new Socket() const socket = new Socket()
const term = new SocketTerminal(40, 80) const term = new SocketTerminal()
let hasSetup = false let hasSetup = false
interface QuestDetailResponse { interface QuestDetailResponse {
+20 -23
View File
@@ -6,33 +6,39 @@ class SocketTerminal {
private term: Terminal private term: Terminal
private fitAddon: FitAddon private fitAddon: FitAddon
constructor(rows: number, cols: number) { constructor() {
this.term = new Terminal({ this.term = new Terminal({
rows, // 行数 convertEol: true,
cols, // 不指定行数,自动回车后光标从下一行开始 scrollback: 1000,
convertEol: true, // 启用时,光标将设置为下一行的开头 fontSize: 16,
// scrollback: 50, //终端中的回滚量
disableStdin: false, // 是否应禁用输入
// cursorStyle: "underline", //光标样式
cursorBlink: true, // 光标闪烁
theme: { theme: {
foreground: '#ECECEC', // 字体 foreground: '#ECECEC',
background: '#000000', // 背景色 background: '#000000',
cursor: 'help', // 设置光标 cursor: 'help',
}, },
fontSize: 18,
fontWeight: 'normal',
}) })
this.fitAddon = new FitAddon() this.fitAddon = new FitAddon()
this.term.loadAddon(this.fitAddon) this.term.loadAddon(this.fitAddon)
}
resizeScreen(): void {
try {
this.fitAddon.fit() 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 { write(message: string): void {
this.term.write(message) this.term.write(message)
} }
onData(callback: any): void { onData(callback: (data: string) => void): void {
this.term.onData(callback) this.term.onData(callback)
} }
@@ -40,15 +46,6 @@ class SocketTerminal {
this.term.focus() this.term.focus()
} }
resizeScreen(): void {
this.fitAddon.fit()
}
mount(reference: HTMLElement): void {
this.term.open(reference)
this.resizeScreen()
}
reset(): void { reset(): void {
this.term.reset() this.term.reset()
} }