bhcli

A TUI for chatting on LE PHP Chats (onion)
git clone https://git.dasho.dev/n0tr1v/bhcli.git
Log | Files | Refs | README

commit be0633c7cc3d486af021ca0ea5909aeb0a1b78bc
parent 034483f579102d1bbb19f3a5aceb6ae7f156dee1
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sun,  2 Apr 2023 06:10:50 -0700

Avoid sending message when it's a non valid slash command

Diffstat:
Msrc/main.rs | 20+++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/main.rs b/src/main.rs @@ -995,7 +995,8 @@ impl LeChatPHPClient { match app.input_mode { InputMode::LongMessage => self.handle_long_message_mode_key_event(app, key_event, messages), InputMode::Normal => self.handle_normal_mode_key_event(app, key_event, messages), - InputMode::Editing => self.handle_editing_mode_key_event(app, key_event, users), + InputMode::Editing | + InputMode::EditingErr => self.handle_editing_mode_key_event(app, key_event, users), } } @@ -1045,6 +1046,7 @@ impl LeChatPHPClient { } fn handle_editing_mode_key_event(&mut self, app: &mut App, key_event: KeyEvent, users: &Arc<Mutex<Users>>) -> std::result::Result<(), ExitSignal> { + app.input_mode = InputMode::Editing; match key_event { KeyEvent { code: KeyCode::Enter, modifiers: KeyModifiers::NONE, .. } => self.handle_editing_mode_key_event_enter(app)?, KeyEvent { code: KeyCode::Tab, modifiers: KeyModifiers::NONE, .. } => self.handle_editing_mode_key_event_tab(app, users), @@ -1391,8 +1393,14 @@ impl LeChatPHPClient { self.post_msg(PostType::Upload(file_path, send_to, msg)) .unwrap(); } else { - // Send normal message - self.post_msg(PostType::Post(input, None)).unwrap(); + if input.starts_with("/") { + app.input_idx = input.len(); + app.input = input; + app.input_mode = InputMode::EditingErr; + } else { + // Send normal message + self.post_msg(PostType::Post(input, None)).unwrap(); + } } Ok(()) } @@ -2509,7 +2517,7 @@ fn render_help_txt(f: &mut Frame<CrosstermBackend<io::Stdout>>, app: &mut App, r ], Style::default(), ), - InputMode::Editing => ( + InputMode::Editing | InputMode::EditingErr => ( vec![ Span::raw("Press "), Span::styled("Esc", Style::default().add_modifier(Modifier::BOLD)), @@ -2569,6 +2577,7 @@ fn render_textbox(f: &mut Frame<CrosstermBackend<io::Stdout>>, app: &mut App, r: InputMode::LongMessage => Style::default(), InputMode::Normal => Style::default(), InputMode::Editing => Style::default().fg(tuiColor::Yellow), + InputMode::EditingErr => Style::default().fg(tuiColor::Red), }) .block(Block::default().borders(Borders::ALL).title("Input")); f.render_widget(input, r); @@ -2578,7 +2587,7 @@ fn render_textbox(f: &mut Frame<CrosstermBackend<io::Stdout>>, app: &mut App, r: // Hide the cursor. `Frame` does this by default, so we don't need to do anything here {} - InputMode::Editing => { + InputMode::Editing | InputMode::EditingErr => { // Make the cursor visible and ask tui-rs to put it at the specified coordinates after rendering f.set_cursor( // Put cursor past the end of the input text @@ -2702,6 +2711,7 @@ enum InputMode { LongMessage, Normal, Editing, + EditingErr, } /// App holds the state of the application