]> acesimba.cloud Git - codebuddy-web.git/commitdiff
fix(frontend): 修复 reattach/连接提示中的 ANSI 转义被写成字面量
authorCodebuddy <codebuddy@localhost>
Thu, 13 Aug 2026 08:37:34 +0000 (16:37 +0800)
committerCodebuddy <codebuddy@localhost>
Thu, 13 Aug 2026 08:37:34 +0000 (16:37 +0800)
- renderReattach 与 connectWS 的状态提示误用双反斜杠 \\x1b,导致 xterm 把转义序列当纯文本打印
- 统一改为单反斜杠 \x1b,连接成功/重新连接/任务状态等提示恢复正常彩色
- 仅前端改动,刷新浏览器即生效

frontend/index.html

index 0b16c3cb144aa6fc2f4ac082cbc737fe037c01b5..e84124f8f47e6fa5fc259ac97b12d377c0ed74ae 100644 (file)
@@ -613,7 +613,7 @@ body { position: fixed; top: 0; left: 0; right: 0; bottom: 0; height: 100%; over
       }
       const data = await res.json();
       currentTask.model = (data.task && data.task.model) || '';
-      term.writeln('\\x1b[33m⏳ 切换模型为 "' + (currentTask.model || '默认·最新GLM') + '",正在重启会话...\\x1b[0m');
+      term.writeln('\x1b[33m⏳ 切换模型为 "' + (currentTask.model || '默认·最新GLM') + '",正在重启会话...\x1b[0m');
       // 重启以应用新模型(resume 同样会采用新 --model)
       killCurrent();
       if (term) term.clear();
@@ -863,13 +863,13 @@ body { position: fixed; top: 0; left: 0; right: 0; bottom: 0; height: 100%; over
     const m = Math.floor(sec / 60), s = sec % 60;
     term.writeln('');
     if (msg.running) {
-      term.writeln('\\x1b[36m🔗 已重新连接 · 任务运行中 · 已运行 ' + m + '分' + s + '秒\\x1b[0m');
+      term.writeln('\x1b[36m🔗 已重新连接 · 任务运行中 · 已运行 ' + m + '分' + s + '秒\x1b[0m');
     } else {
-      term.writeln('\\x1b[33mⓘ 任务已结束(退出码 ' + (msg.exit_code == null ? '?' : msg.exit_code) + ')\\x1b[0m');
+      term.writeln('\x1b[33mⓘ 任务已结束(退出码 ' + (msg.exit_code == null ? '?' : msg.exit_code) + ')\x1b[0m');
     }
-    if (msg.current_task) term.writeln('\\x1b[90m当前/最近任务:' + msg.current_task + '\\x1b[0m');
+    if (msg.current_task) term.writeln('\x1b[90m当前/最近任务:' + msg.current_task + '\x1b[0m');
     if (msg.replay) {
-      term.writeln('\\x1b[90m──── 以下为断开期间 / 上次的输出 ────\\x1b[0m');
+      term.writeln('\x1b[90m──── 以下为断开期间 / 上次的输出 ────\x1b[0m');
       term.write(msg.replay);
     }
     try { term.focus(); } catch (e) {}
@@ -880,25 +880,25 @@ body { position: fixed; top: 0; left: 0; right: 0; bottom: 0; height: 100%; over
     if (!authToken || !TASK_ID) return;
     const proto = location.protocol === 'https:' ? 'wss:' : 'ws:';
     const url = proto + '//' + location.host + '/ws?token=' + encodeURIComponent(authToken) + '&task=' + encodeURIComponent(TASK_ID);
-    term.writeln('\\x1b[33m⏳ 正在连接任务 [' + (currentTask ? currentTask.name : TASK_ID) + ']...\\x1b[0m');
+    term.writeln('\x1b[33m⏳ 正在连接任务 [' + (currentTask ? currentTask.name : TASK_ID) + ']...\x1b[0m');
     setConnected(false);
 
     ws = new WebSocket(url);
     ws.binaryType = 'arraybuffer';
 
-    ws.onopen = () => { setConnected(true); term.writeln('\\x1b[32m✓ 连接成功\\x1b[0m'); };
+    ws.onopen = () => { setConnected(true); term.writeln('\x1b[32m✓ 连接成功\x1b[0m'); };
     ws.onmessage = (event) => {
       try {
         const msg = JSON.parse(event.data);
         if (msg.type === 'output' && msg.data) term.write(msg.data);
         else if (msg.type === 'pid') pid = msg.pid;
         else if (msg.type === 'reattach') { pid = msg.pid || pid; renderReattach(msg); }
-        else if (msg.type === 'error') { term.writeln('\\x1b[31m✗ ' + msg.data + '\\x1b[0m'); }
-        else if (msg.type === 'exit') { term.writeln('\\x1b[33m⚠ 进程已退出 (code: ' + msg.code + ')\\x1b[0m'); setConnected(false); }
+        else if (msg.type === 'error') { term.writeln('\x1b[31m✗ ' + msg.data + '\x1b[0m'); }
+        else if (msg.type === 'exit') { term.writeln('\x1b[33m⚠ 进程已退出 (code: ' + msg.code + ')\x1b[0m'); setConnected(false); }
       } catch(e) { term.write(event.data); }
     };
-    ws.onclose = () => { setConnected(false); term.writeln('\\x1b[31m✗ 连接已断开\\x1b[0m'); };
-    ws.onerror = () => { setConnected(false); term.writeln('\\x1b[31m✗ 连接错误\\x1b[0m'); };
+    ws.onclose = () => { setConnected(false); term.writeln('\x1b[31m✗ 连接已断开\x1b[0m'); };
+    ws.onerror = () => { setConnected(false); term.writeln('\x1b[31m✗ 连接错误\x1b[0m'); };
   }
 
   function killCurrent() {
@@ -908,7 +908,7 @@ body { position: fixed; top: 0; left: 0; right: 0; bottom: 0; height: 100%; over
   document.getElementById('btn-restart').onclick = () => {
     killCurrent();
     if (term) term.clear();
-    term.writeln('\\x1b[33m⏳ 重启会话中...\\x1b[0m');
+    term.writeln('\x1b[33m⏳ 重启会话中...\x1b[0m');
     connectWS();
   };
   document.getElementById('btn-list').onclick = () => { window.open('/', 'cb_picker'); };