pub struct ChatMode {
input_history: Vec<String>,
history_index: Option<usize>,
completer: ChatCompleter,
current_suggestion: Option<String>,
}Expand description
Manages the state and logic for the chat input and display.
Fields§
§input_history: Vec<String>History of user input commands/messages.
history_index: Option<usize>Current index in the input history for navigation.
completer: ChatCompleterCompleter for command and peer ID suggestions.
current_suggestion: Option<String>The currently suggested completion for the input.
Implementations§
Source§impl ChatMode
impl ChatMode
Sourcepub async fn handle_key(
&mut self,
state: &mut UIState,
key: KeyEvent,
action_tx: &UnboundedSender<UIAction>,
) -> Result<()>
pub async fn handle_key( &mut self, state: &mut UIState, key: KeyEvent, action_tx: &UnboundedSender<UIAction>, ) -> Result<()>
Handles a key event in chat mode.
This function processes various key presses, including typing characters, navigating input history, moving the cursor, and executing commands.
§Arguments
state- The current UI state.key- TheKeyEventto handle.action_tx- The sender for dispatching UI actions.
§Errors
This function returns an error if a command execution fails.
Sourcefn update_suggestion(&mut self, state: &UIState)
fn update_suggestion(&mut self, state: &UIState)
Updates the current input suggestion based on the input buffer content.
This is typically used for command autocompletion.
Navigates through the input history.
§Arguments
state- The current UI state.up- Iftrue, navigates up (older entries); iffalse, navigates down (newer entries).
Sourceasync fn execute_command(
&self,
input: &str,
action_tx: &UnboundedSender<UIAction>,
) -> Result<()>
async fn execute_command( &self, input: &str, action_tx: &UnboundedSender<UIAction>, ) -> Result<()>
Executes a command based on the input string.
This function parses the input, identifies commands like “send”, and
dispatches appropriate UIActions.
§Arguments
input- The input string to parse and execute.action_tx- The sender for dispatching UI actions.
§Errors
This function returns an error if the action sender fails.
Source§impl ChatMode
impl ChatMode
Sourcepub fn render(
&self,
stdout: &mut impl Write,
state: &UIState,
area: (u16, u16, u16, u16),
node: Option<&Node>,
) -> Result<()>
pub fn render( &self, stdout: &mut impl Write, state: &UIState, area: (u16, u16, u16, u16), node: Option<&Node>, ) -> Result<()>
Renders the chat interface, including messages and suggestions.
This function draws the chat history, input buffer, and any active suggestions to the terminal. It handles scrolling and message formatting.
§Arguments
stdout- A mutable reference to the output stream.state- The current UI state.area- The (x, y, width, height) coordinates of the rendering area.node- An optional reference to the application’sNodefor message decryption and friend information.
§Errors
This function returns an error if writing to the output stream fails.
Source§impl ChatMode
impl ChatMode
Sourcepub fn update_friends(&mut self, friends: Vec<String>)
pub fn update_friends(&mut self, friends: Vec<String>)
Updates the list of friends for the completer.
Sourcepub fn update_discovered_peers(&mut self, peers: Vec<String>)
pub fn update_discovered_peers(&mut self, peers: Vec<String>)
Updates the list of discovered peers for the completer.
Sourcepub fn get_current_suggestion(&self) -> Option<&str>
pub fn get_current_suggestion(&self) -> Option<&str>
Returns the current suggestion string, if any.
Auto Trait Implementations§
impl Freeze for ChatMode
impl RefUnwindSafe for ChatMode
impl Send for ChatMode
impl Sync for ChatMode
impl Unpin for ChatMode
impl UnwindSafe for ChatMode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more