update
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { ref, readonly, type Ref, ComputedRef } from 'vue';
|
||||
import { useI18n } from 'vue-i18n'; // +++ Add import for useI18n +++
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { sessions as globalSessionsRef } from '../stores/session/state'; // +++ 导入全局 sessions state +++
|
||||
// import { useWebSocketConnection } from './useWebSocketConnection'; // 移除全局导入
|
||||
import type { Terminal } from 'xterm';
|
||||
import type { SearchAddon, ISearchOptions } from '@xterm/addon-search'; // *** 移除 ISearchResult 导入 ***
|
||||
@@ -74,18 +75,40 @@ export function createSshTerminalManager(sessionId: string, wsDeps: SshTerminalD
|
||||
// }
|
||||
|
||||
// --- 添加日志:检查缓冲区处理 ---
|
||||
console.log(`[会话 ${sessionId}][SSH前端] handleTerminalReady: 准备处理缓冲区,缓冲区长度: ${terminalOutputBuffer.value.length}`);
|
||||
if (terminalOutputBuffer.value.length > 0) {
|
||||
console.log(`[会话 ${sessionId}][SSH前端] handleTerminalReady: 缓冲区内容 (前100字符):`, terminalOutputBuffer.value.map(d => d.substring(0, 100)).join(' | '));
|
||||
}
|
||||
// console.log(`[会话 ${sessionId}][SSH前端] handleTerminalReady: 准备处理缓冲区,缓冲区长度: ${terminalOutputBuffer.value.length}`);
|
||||
// if (terminalOutputBuffer.value.length > 0) {
|
||||
// console.log(`[会话 ${sessionId}][SSH前端] handleTerminalReady: 内部缓冲区内容 (前100字符):`, terminalOutputBuffer.value.map(d => d.substring(0, 100)).join(' | '));
|
||||
// }
|
||||
// ---------------------------------
|
||||
// 将缓冲区的输出写入终端
|
||||
terminalOutputBuffer.value.forEach(data => {
|
||||
console.log(`[会话 ${sessionId}][SSH前端] handleTerminalReady: 正在写入缓冲数据 (前100字符):`, data.substring(0, 100));
|
||||
term.write(data);
|
||||
});
|
||||
console.log(`[会话 ${sessionId}][SSH前端] handleTerminalReady: 缓冲区处理完成。`);
|
||||
terminalOutputBuffer.value = []; // 清空缓冲区
|
||||
|
||||
// 1. 处理 SessionState.pendingOutput (来自 SSH_OUTPUT_CACHED_CHUNK 的早期数据)
|
||||
const currentSessionState = globalSessionsRef.value.get(sessionId);
|
||||
if (currentSessionState && currentSessionState.pendingOutput && currentSessionState.pendingOutput.length > 0) {
|
||||
// console.log(`[会话 ${sessionId}][SSH终端模块] 发现 SessionState.pendingOutput,长度: ${currentSessionState.pendingOutput.length}。正在写入...`);
|
||||
currentSessionState.pendingOutput.forEach(data => {
|
||||
term.write(data);
|
||||
});
|
||||
currentSessionState.pendingOutput = []; // 清空
|
||||
// console.log(`[会话 ${sessionId}][SSH终端模块] SessionState.pendingOutput 处理完毕。`);
|
||||
// 如果之前因为 pendingOutput 而将 isResuming 保持为 true,现在可以考虑更新
|
||||
if (currentSessionState.isResuming) {
|
||||
// 检查 isLastChunk 是否已收到 (这部分逻辑在 handleSshOutputCachedChunk 中,这里仅作标记清除)
|
||||
// 假设所有缓存块都已处理完毕
|
||||
// console.log(`[会话 ${sessionId}][SSH终端模块] 所有 pendingOutput 已写入,清除 isResuming 标记。`);
|
||||
currentSessionState.isResuming = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 将此管理器内部缓冲的输出 (terminalOutputBuffer, 来自 ssh:output) 写入终端
|
||||
if (terminalOutputBuffer.value.length > 0) {
|
||||
terminalOutputBuffer.value.forEach(data => {
|
||||
// console.log(`[会话 ${sessionId}][SSH前端] handleTerminalReady: 正在写入内部缓冲数据 (前100字符):`, data.substring(0, 100));
|
||||
term.write(data);
|
||||
});
|
||||
// console.log(`[会话 ${sessionId}][SSH前端] handleTerminalReady: 内部缓冲区处理完成。`);
|
||||
terminalOutputBuffer.value = []; // 清空内部缓冲区
|
||||
}
|
||||
|
||||
// 可以在这里自动聚焦或执行其他初始化操作
|
||||
// term.focus(); // 也许在 ssh:connected 时聚焦更好
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user