use ratatui::{
style::{Modifier, Style},
text::{Line, Span},
};
use crate::app::DisplayToolCall;
use crate::formatters::style_tokens;
use crate::formatters::tool_line::{ToolLineStyle, tool_line_completed};
use crate::formatters::tool_registry::format_tool_call_parts_with_wd;
use crate::widgets::spinner::{COMPLETED_CHAR, CONTINUATION_CHAR};
pub(crate) fn format_tool_call(tc: &DisplayToolCall, working_dir: Option<&str>) -> Line<'static> {
let (icon, icon_color) = if tc.success {
(COMPLETED_CHAR, style_tokens::GREEN_BRIGHT)
} else {
(COMPLETED_CHAR, style_tokens::ERROR)
};
if tc.name == "ask_user" {
return Line::from(vec![
Span::styled(format!("{icon} "), Style::default().fg(icon_color)),
Span::styled(
"User answered Claude's questions:",
Style::default()
.fg(style_tokens::PRIMARY)
.add_modifier(Modifier::BOLD),
),
]);
}
let (verb, arg) = format_tool_call_parts_with_wd(&tc.name, &tc.arguments, working_dir);
tool_line_completed(vec![], tc.success, verb, arg, None, ToolLineStyle::Primary)
}
pub(crate) fn format_nested_tool_call(
tc: &DisplayToolCall,
_depth: usize,
working_dir: Option<&str>,
) -> Line<'static> {
let (verb, arg) = format_tool_call_parts_with_wd(&tc.name, &tc.arguments, working_dir);
let continuation_prefix = vec![Span::styled(
format!(" {CONTINUATION_CHAR} "),
Style::default().fg(style_tokens::GREY),
)];
tool_line_completed(
continuation_prefix,
tc.success,
verb,
arg,
None,
ToolLineStyle::Nested,
)
}