Added chevron icon and additional text on the tool message indicating that clicking over the message allows to see the tool result.

This commit is contained in:
famez
2026-02-15 22:33:47 +01:00
parent 99bbea32ec
commit 9e7e84c03c

View File

@@ -648,8 +648,13 @@ class ThinkingMessage(Static):
class ToolMessage(Static):
"""Tool execution message"""
TOOL_ICON = "$"
TOOL_COLOR = "#9a9a9a"
ARG_COLOR = "#6b6b6b"
HINT_COLOR = "#6b6b6b"
CHEVRON_COLLAPSED = ""
CHEVRON_EXPANDED = ""
HINT_TEXT = " (click to see result)"
expanded: bool = reactive(False, layout=True)
@@ -661,43 +666,51 @@ class ToolMessage(Static):
def render(self) -> Text:
text = Text()
text.append(f"{self.TOOL_ICON} ", style=self.TOOL_COLOR)
chevron = (
self.CHEVRON_EXPANDED if self.expanded else self.CHEVRON_COLLAPSED
)
# Header line
text.append(f"{chevron} ", style=self.TOOL_COLOR)
text.append(self.tool_name, style=self.TOOL_COLOR)
# Hint text (only when result exists and is collapsed)
if self._result_widget and not self.expanded:
text.append(self.HINT_TEXT, style=self.HINT_COLOR)
text.append("\n")
# Tool arguments
if self.tool_args:
for line in wrap_text_lines(self.tool_args, width=110):
text.append(f" {line}\n", style="#6b6b6b")
text.append(f" {line}\n", style=self.ARG_COLOR)
return text
def attach_result(self, result_widget: "ToolResultMessage") -> None:
"""Attach a ToolResultMessage widget below this message."""
# Prevent double mounting
if self._result_widget is not None:
return
self._result_widget = result_widget
self._result_widget.display = self.expanded
# Mount immediately after this widget
# Mount directly after this widget
self.mount(self._result_widget, after=self)
def on_click(self) -> None:
self.expanded = not self.expanded
if self._result_widget:
self._result_widget.display = self.expanded
class ToolResultMessage(Static):
"""Tool result/output message"""
RESULT_ICON = "#"
RESULT_COLOR = "#7a7a7a"
RESULT_COLOR = "#124670"
OUTPUT_COLOR = "#17606d"
def __init__(self, tool_name: str, result: str = "", **kwargs):
super().__init__(**kwargs)
@@ -706,13 +719,14 @@ class ToolResultMessage(Static):
def render(self) -> Text:
text = Text()
text.append(f"{self.RESULT_ICON} ", style=self.RESULT_COLOR)
text.append(f"{self.tool_name} output", style=self.RESULT_COLOR)
text.append("\n", style="")
text.append("\n")
if self.result:
for line in wrap_text_lines(self.result, width=110):
text.append(f" {line}\n", style="#5a5a5a")
text.append(f" {line}\n", style=self.OUTPUT_COLOR)
return text