Hello everyone,
I am building a simple tui for dnote using ratatui’s component template. I am trying to get my application to pause to allow vim to edit notes file and resume my tui once user is done editing. I am just testing this out in Home component from template: templates/component/template/src/components/home.rs at main · ratatui-org/templates · GitHub
What am I doing wrong in handle_key_events
in my code? It spawns vim but I can’t provide input and it just gets hung up.
// imports ...
#[derive(Default)]
pub struct Home {
command_tx: Option<UnboundedSender<Action>>,
config: Config,
}
impl Home {
pub fn new() -> Self {
Self::default()
}
}
impl Component for Home {
// register_action_handler, register_config_handler, ...
fn handle_key_events(&mut self, key: KeyEvent) -> Result<Option<Action>> {
match key.code {
KeyCode::Char('v') => {
if let Some(tx) = &self.command_tx {
tx.send(Action::Suspend)?;
}
disable_raw_mode()?;
Command::new("sh")
.arg("-c")
.arg("vim /tmp/a.txt")
.status()
.expect("Failed to execute vim");
enable_raw_mode()?;
if let Some(tx) = &self.command_tx {
tx.send(Action::Resume)?;
}
Ok(None)
}
_ => Ok(None),
}
}
// update, draw, other functions...
}