feat(theme): add tool_output color to themes
- Added a `tool_output` color to the `Theme` struct. - Updated all built-in themes to include the new color. - Modified the TUI to use the `tool_output` color for rendering tool output.
This commit is contained in:
@@ -670,7 +670,13 @@ fn render_messages(frame: &mut Frame<'_>, area: Rect, app: &mut ChatApp) {
|
||||
|
||||
let chunks_len = chunks.len();
|
||||
for (i, seg) in chunks.into_iter().enumerate() {
|
||||
let mut spans = vec![Span::raw(format!("{indent}{}", seg))];
|
||||
let style = if matches!(role, Role::Tool) {
|
||||
Style::default().fg(theme.tool_output)
|
||||
} else {
|
||||
Style::default()
|
||||
};
|
||||
|
||||
let mut spans = vec![Span::styled(format!("{indent}{}", seg), style)];
|
||||
if i == chunks_len - 1 && is_streaming {
|
||||
spans.push(Span::styled(" ▌", Style::default().fg(theme.cursor)));
|
||||
}
|
||||
@@ -682,7 +688,13 @@ fn render_messages(frame: &mut Frame<'_>, area: Rect, app: &mut ChatApp) {
|
||||
let chunks = wrap(&content, content_width as usize);
|
||||
let chunks_len = chunks.len();
|
||||
for (i, seg) in chunks.into_iter().enumerate() {
|
||||
let mut spans = vec![Span::raw(seg.into_owned())];
|
||||
let style = if matches!(role, Role::Tool) {
|
||||
Style::default().fg(theme.tool_output)
|
||||
} else {
|
||||
Style::default()
|
||||
};
|
||||
|
||||
let mut spans = vec![Span::styled(seg.into_owned(), style)];
|
||||
if i == chunks_len - 1 && is_streaming {
|
||||
spans.push(Span::styled(" ▌", Style::default().fg(theme.cursor)));
|
||||
}
|
||||
@@ -2075,7 +2087,7 @@ fn role_color(role: &Role, theme: &owlen_core::theme::Theme) -> Style {
|
||||
match role {
|
||||
Role::User => Style::default().fg(theme.user_message_role),
|
||||
Role::Assistant => Style::default().fg(theme.assistant_message_role),
|
||||
Role::System => Style::default().fg(theme.info),
|
||||
Role::System => Style::default().fg(theme.unfocused_panel_border),
|
||||
Role::Tool => Style::default().fg(theme.info),
|
||||
}
|
||||
}
|
||||
@@ -2085,14 +2097,17 @@ fn format_tool_output(content: &str) -> String {
|
||||
// Try to parse as JSON
|
||||
if let Ok(json) = serde_json::from_str::<serde_json::Value>(content) {
|
||||
let mut output = String::new();
|
||||
let mut content_found = false;
|
||||
|
||||
// Extract query if present
|
||||
if let Some(query) = json.get("query").and_then(|v| v.as_str()) {
|
||||
output.push_str(&format!("Query: \"{}\"\n\n", query));
|
||||
content_found = true;
|
||||
}
|
||||
|
||||
// Extract results array
|
||||
if let Some(results) = json.get("results").and_then(|v| v.as_array()) {
|
||||
content_found = true;
|
||||
if results.is_empty() {
|
||||
output.push_str("No results found");
|
||||
return output;
|
||||
@@ -2158,12 +2173,20 @@ fn format_tool_output(content: &str) -> String {
|
||||
if let Some(total) = json.get("total_found").and_then(|v| v.as_u64()) {
|
||||
output.push_str(&format!("Found {} result(s)", total));
|
||||
}
|
||||
} else if let Some(result) = json.get("result").and_then(|v| v.as_str()) {
|
||||
content_found = true;
|
||||
output.push_str(result);
|
||||
} else if let Some(error) = json.get("error").and_then(|v| v.as_str()) {
|
||||
content_found = true;
|
||||
// Handle error results
|
||||
output.push_str(&format!("❌ Error: {}", error));
|
||||
}
|
||||
|
||||
output
|
||||
if content_found {
|
||||
output
|
||||
} else {
|
||||
content.to_string()
|
||||
}
|
||||
} else {
|
||||
// If not JSON, return as-is
|
||||
content.to_string()
|
||||
|
||||
Reference in New Issue
Block a user