steer_tui/tui/widgets/formatters/
default.rs1use super::{ToolFormatter, helpers::*};
2use crate::tui::theme::{Component, Theme};
3use ratatui::text::{Line, Span};
4use serde_json::Value;
5use steer_core::app::conversation::ToolResult;
6
7pub struct DefaultFormatter;
8
9impl ToolFormatter for DefaultFormatter {
10 fn compact(
11 &self,
12 _params: &Value,
13 _result: &Option<ToolResult>,
14 _wrap_width: usize,
15 theme: &Theme,
16 ) -> Vec<Line<'static>> {
17 vec![Line::from(Span::styled(
18 "Unknown tool",
19 theme.style(Component::ErrorText),
20 ))]
21 }
22
23 fn detailed(
24 &self,
25 params: &Value,
26 result: &Option<ToolResult>,
27 wrap_width: usize,
28 theme: &Theme,
29 ) -> Vec<Line<'static>> {
30 let mut lines = Vec::new();
31
32 lines.push(Line::from(Span::styled(
33 "Tool Parameters:",
34 theme.style(Component::ToolCallHeader),
35 )));
36
37 let pretty_params = serde_json::to_string_pretty(params).unwrap_or_default();
39 for line in pretty_params.lines() {
40 let wrapped_lines = textwrap::wrap(line, wrap_width);
41 for wrapped_line in wrapped_lines {
42 lines.push(Line::from(Span::styled(
43 wrapped_line.to_string(),
44 theme.style(Component::DimText),
45 )));
46 }
47 }
48
49 if let Some(result) = result {
51 lines.push(separator_line(wrap_width, theme.style(Component::DimText)));
52
53 match serde_json::to_string_pretty(result) {
55 Ok(pretty_result) => {
56 const MAX_LINES: usize = 10;
57 let (output_lines, truncated) = truncate_lines(&pretty_result, MAX_LINES);
58
59 for line in output_lines {
60 for wrapped in textwrap::wrap(line, wrap_width) {
61 lines.push(Line::from(Span::raw(wrapped.to_string())));
62 }
63 }
64
65 if truncated {
66 lines.push(Line::from(Span::styled(
67 format!(
68 "... ({} more lines)",
69 pretty_result.lines().count() - MAX_LINES
70 ),
71 theme
72 .style(Component::DimText)
73 .add_modifier(ratatui::style::Modifier::ITALIC),
74 )));
75 }
76 }
77 Err(_) => {
78 lines.push(Line::from(Span::styled(
79 "(Unable to display result)",
80 theme
81 .style(Component::DimText)
82 .add_modifier(ratatui::style::Modifier::ITALIC),
83 )));
84 }
85 }
86 }
87
88 lines
89 }
90}