diff --git a/tui/src/main.rs b/tui/src/main.rs index 4c5e4f1..5231523 100644 --- a/tui/src/main.rs +++ b/tui/src/main.rs @@ -198,7 +198,8 @@ async fn main() -> Result<(), Box> { InputMode::Normal => match input { Key::Char('i') | Key::Char('/') => { app.input_mode = InputMode::Editing; - app.input.push('/'); + // only add the slash on slash command start + if Key::Char('/') == input { app.input.push('/'); } events.disable_exit_key(); } Key::Char('q') => { @@ -213,16 +214,22 @@ async fn main() -> Result<(), Box> { }, InputMode::Editing => match input { Key::Char('\n') => { - let cmd = Command::from(app.input.drain(..).collect()); - app.messages.push(match cmd { - // only for networked commands do we need to touch cache - Command::Channel(id) => app.cache.switch_channel(id).await, - Command::Server(host) => app.cache.switch_server(&host).await, - Command::Message(msg) => app.cache.send_message(&msg).await, - Command::ListHost => app.cache.list_hosts(), - Command::ListChannel => app.cache.list_channels(), - _ => cmd - }); + let raw: String = app.input.drain(..).collect(); + let trimmed = raw.trim(); + + // ensure that we don't bother with empty input + if trimmed.len() != 0 { + let cmd = Command::from(trimmed); + app.messages.push(match cmd { + // only for networked commands do we need to touch cache + Command::Channel(id) => app.cache.switch_channel(id).await, + Command::Server(host) => app.cache.switch_server(&host).await, + Command::Message(msg) => app.cache.send_message(&msg).await, + Command::ListHost => app.cache.list_hosts(), + Command::ListChannel => app.cache.list_channels(), + _ => cmd + }); + } } Key::Char(c) => { app.input.push(c);