+ Ignoring empty lines

+ Only adding / on '/' input activation
This commit is contained in:
shockrah 2021-04-05 16:54:27 -07:00
parent a8d4ca9028
commit 939ee8c73f

View File

@ -198,7 +198,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
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<dyn Error>> {
},
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);