forked from trinitrix/core
feat(states): Add `command` state for command only keymappings
This commit is contained in:
parent
bc1fc0cc02
commit
74f3b25827
|
@ -81,6 +81,7 @@ pub async fn handle(
|
|||
|
||||
Command::CommandLineShow => {
|
||||
app.ui.cli_enable();
|
||||
app.status.set_state(State::Command);
|
||||
send_status_output!("CLI online");
|
||||
EventStatus::Ok
|
||||
}
|
||||
|
|
|
@ -10,10 +10,52 @@ use crate::{
|
|||
ui::central,
|
||||
};
|
||||
|
||||
pub async fn handle_normal(
|
||||
pub async fn handle_command(
|
||||
app: &mut App<'_>,
|
||||
input_event: &CrosstermEvent,
|
||||
) -> Result<EventStatus> {
|
||||
if let Some(cli) = &app.ui.cli {
|
||||
match input_event {
|
||||
CrosstermEvent::Key(KeyEvent {
|
||||
code: KeyCode::Esc, ..
|
||||
}) => {
|
||||
app.tx
|
||||
.send(Event::CommandEvent(Command::SetModeNormal, None))
|
||||
.await?;
|
||||
}
|
||||
CrosstermEvent::Key(KeyEvent {
|
||||
code: KeyCode::Enter,
|
||||
..
|
||||
}) => {
|
||||
let ci_event = cli
|
||||
.lines()
|
||||
.get(0)
|
||||
.expect(
|
||||
"One line always exists,
|
||||
and others can't exists
|
||||
because we collect on
|
||||
enter",
|
||||
)
|
||||
.to_owned();
|
||||
app.tx
|
||||
.send(Event::LuaCommand(ci_event))
|
||||
.await
|
||||
.context("Failed to send lua command to internal event stream")?;
|
||||
}
|
||||
_ => {
|
||||
app.ui
|
||||
.cli
|
||||
.as_mut()
|
||||
.expect("This is already checked")
|
||||
.input(tui_textarea::Input::from(input_event.to_owned()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
unreachable!("The cli should not be active while no cli is defined");
|
||||
}
|
||||
Ok(EventStatus::Ok)
|
||||
}
|
||||
pub async fn handle_normal(app: &mut App<'_>, input_event: &CrosstermEvent) -> Result<EventStatus> {
|
||||
match input_event {
|
||||
CrosstermEvent::Key(KeyEvent {
|
||||
code: KeyCode::Esc, ..
|
||||
|
@ -137,38 +179,7 @@ pub async fn handle_normal(
|
|||
_ => (),
|
||||
};
|
||||
}
|
||||
central::InputPosition::CLI => {
|
||||
if let Some(cli) = &app.ui.cli {
|
||||
match input {
|
||||
CrosstermEvent::Key(KeyEvent {
|
||||
code: KeyCode::Enter,
|
||||
..
|
||||
}) => {
|
||||
let ci_event = cli
|
||||
.lines()
|
||||
.get(0)
|
||||
.expect(
|
||||
"One line always exists,
|
||||
and others can't exists
|
||||
because we collect on
|
||||
enter",
|
||||
)
|
||||
.to_owned();
|
||||
app.tx
|
||||
.send(Event::LuaCommand(ci_event))
|
||||
.await
|
||||
.context("Failed to send lua command to internal event stream")?;
|
||||
}
|
||||
_ => {
|
||||
app.ui
|
||||
.cli
|
||||
.as_mut()
|
||||
.expect("This is already checked")
|
||||
.input(tui_textarea::Input::from(input.to_owned()));
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
_ => (),
|
||||
},
|
||||
};
|
||||
|
|
|
@ -45,6 +45,9 @@ impl Event {
|
|||
State::Insert => main::handle_insert(app, &event).await.with_context(|| {
|
||||
format!("Failed to handle input (insert) event: `{:#?}`", event)
|
||||
}),
|
||||
State::Command => main::handle_command(app, &event).await.with_context(|| {
|
||||
format!("Failed to handle input (command) event: `{:#?}`", event)
|
||||
}),
|
||||
State::Setup => setup::handle(app, &event).await.with_context(|| {
|
||||
format!("Failed to handle input (setup) event: `{:#?}`", event)
|
||||
}),
|
||||
|
|
|
@ -15,6 +15,7 @@ use matrix_sdk::{
|
|||
pub enum State {
|
||||
Normal,
|
||||
Insert,
|
||||
Command,
|
||||
/// Temporary workaround until command based login is working
|
||||
Setup,
|
||||
}
|
||||
|
@ -57,6 +58,7 @@ impl fmt::Display for State {
|
|||
match self {
|
||||
Self::Normal => write!(f, "Normal"),
|
||||
Self::Insert => write!(f, "Insert"),
|
||||
Self::Command => write!(f, "Command"),
|
||||
Self::Setup => write!(f, "Setup (!! workaround !!)"),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue