ratatui_toolkit/widgets/ai_chat/methods/
mod.rs1use crate::widgets::ai_chat::state::{InputState, MessageStore};
2use ratatui::style::{Color, Modifier, Style};
3
4use crate::widgets::ai_chat::AIChat;
5
6impl<'a> AIChat<'a> {
7 pub fn register_command(&mut self, command: String) {
9 if !self.commands.contains(&command) {
10 self.commands.push(command);
11 }
12 }
13
14 pub fn commands(&self) -> &[String] {
16 &self.commands
17 }
18
19 pub fn filtered_commands(&self) -> Vec<String> {
21 let command_lower = self.input.command().to_lowercase();
22 self.commands
23 .iter()
24 .filter(|c| c.to_lowercase().starts_with(&format!("/{}", command_lower)))
25 .cloned()
26 .collect()
27 }
28
29 pub fn selected_command_index(&self) -> usize {
31 self.selected_command_index
32 }
33
34 pub fn set_selected_command_index(&mut self, index: usize) {
36 self.selected_command_index = index;
37 }
38
39 pub fn handle_command(&mut self, command: &str) -> bool {
43 match command {
44 "/clear" => {
45 self.messages.clear();
46 true
47 }
48 _ => false,
49 }
50 }
51
52 pub fn set_loading(&mut self, loading: bool) {
54 self.is_loading = loading;
55 }
56
57 pub fn is_loading(&self) -> bool {
59 self.is_loading
60 }
61
62 pub fn with_user_message_style(mut self, style: Style) -> Self {
64 self.user_message_style = style;
65 self
66 }
67
68 pub fn with_ai_message_style(mut self, style: Style) -> Self {
70 self.ai_message_style = style;
71 self
72 }
73
74 pub fn with_input_style(mut self, style: Style) -> Self {
76 self.input_style = style;
77 self
78 }
79
80 pub fn with_prompt(mut self, prompt: String) -> Self {
82 self.input_prompt = prompt;
83 self
84 }
85}