From fe79f0e5d4daef89015a940dcd916c8c747e1c92 Mon Sep 17 00:00:00 2001 From: OpenClaw Date: Fri, 8 May 2026 00:17:36 +0800 Subject: [PATCH] =?UTF-8?q?fix(tui):=20=E4=BF=AE=E5=A4=8D=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=88=86=E7=B1=BB=E3=80=81=E4=BE=A7=E6=A0=8F=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E3=80=81=E5=8A=A8=E7=94=BB=E5=A4=B1=E6=95=88=E3=80=81?= =?UTF-8?q?TextArea=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - _write_raw: 空字符串'' in msg永远为True导致所有消息归类为tool-ok, 替换为正确的emoji标记(✅/❌/🤖) - action_toggle_sidebar: Textual无.visible属性,改用has_class/addClass - CSS .hidden: display:none阻止transition动画,改用width+opacity方案 - constants.py: 添加TextArea、Rule到Textual可用性检查导入列表 --- xcli_core/constants.py | 2 +- xcli_core/tui.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/xcli_core/constants.py b/xcli_core/constants.py index 2c0aa4a..dd79a68 100644 --- a/xcli_core/constants.py +++ b/xcli_core/constants.py @@ -102,7 +102,7 @@ except ImportError: try: from textual.app import App, ComposeResult from textual.containers import Container, Horizontal, Vertical, VerticalScroll - from textual.widgets import Header, Footer, Input, RichLog, Static, Button, Tree + from textual.widgets import Header, Footer, Input, RichLog, Static, Button, Tree, TextArea, Rule from textual.widgets.tree import TreeNode from textual.binding import Binding from textual.events import Mount diff --git a/xcli_core/tui.py b/xcli_core/tui.py index 33c4558..5a6494e 100644 --- a/xcli_core/tui.py +++ b/xcli_core/tui.py @@ -143,10 +143,11 @@ if TEXTUAL_AVAILABLE: }} #sidebar.hidden {{ - display: none; width: 0; min-width: 0; opacity: 0; + border: none; + overflow: hidden; }} .sidebar-header {{ @@ -845,11 +846,11 @@ if TEXTUAL_AVAILABLE: self.call_after_refresh(self._update_sidebar) def _write_raw(self, msg): - if '' in msg or 'OK 工具' in msg: + if '✅' in msg or 'OK 工具' in msg: self._add(f" {msg}", "msg-tool-ok") - elif '' in msg or 'X 工具' in msg or '错误' in msg: + elif '❌' in msg or 'X 工具' in msg or '错误' in msg: self._add(f" {msg}", "msg-tool-err") - elif '' in msg: + elif '🤖' in msg: self._add(f" {msg}", "msg-ai") elif '工具' in msg and ('调用' in msg or '执行' in msg): self._add(f" {msg}", "msg-tool-ok") @@ -870,12 +871,13 @@ if TEXTUAL_AVAILABLE: def action_toggle_sidebar(self): sidebar = self.query_one("#sidebar") - sidebar.visible = not sidebar.visible - # 动画:侧栏切换时平滑过渡 - if sidebar.visible: + # 通过 CSS 类控制侧栏显隐 + if sidebar.has_class("hidden"): sidebar.remove_class("hidden") + self.sidebar_visible = True else: sidebar.add_class("hidden") + self.sidebar_visible = False def action_cancel(self): if self.is_generating: