p2p_chat/ui/chat_mode/
mod.rs

1//! This module defines the chat mode functionality for the user interface.
2use super::completers::ChatCompleter;
3
4mod input;
5mod render;
6
7/// Manages the state and logic for the chat input and display.
8pub struct ChatMode {
9    /// History of user input commands/messages.
10    input_history: Vec<String>,
11    /// Current index in the input history for navigation.
12    history_index: Option<usize>,
13    /// Completer for command and peer ID suggestions.
14    completer: ChatCompleter,
15    /// The currently suggested completion for the input.
16    current_suggestion: Option<String>,
17}
18
19impl ChatMode {
20    /// Creates a new `ChatMode` instance.
21    pub fn new() -> Self {
22        Self {
23            input_history: Vec::new(),
24            history_index: None,
25            completer: ChatCompleter::new(Vec::new()),
26            current_suggestion: None,
27        }
28    }
29
30    /// Updates the list of friends for the completer.
31    pub fn update_friends(&mut self, friends: Vec<String>) {
32        self.completer.update_friends(friends);
33    }
34
35    /// Updates the list of discovered peers for the completer.
36    pub fn update_discovered_peers(&mut self, peers: Vec<String>) {
37        self.completer.update_discovered_peers(peers);
38    }
39
40    /// Returns the current suggestion string, if any.
41    pub fn get_current_suggestion(&self) -> Option<&str> {
42        self.current_suggestion.as_deref()
43    }
44}