Skip to content

Commit

Permalink
Don't panic on serial command failures
Browse files Browse the repository at this point in the history
  • Loading branch information
fredizzimo committed Oct 12, 2023
1 parent c3e9ec4 commit 5fe0215
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions src/bridge/ui_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,26 @@ pub enum SerialCommand {

impl SerialCommand {
async fn execute(self, nvim: &Neovim<NeovimWriter>) {
match self {
// Don't panic here unless there's absolutely no chance of continuing the program, Instead
// just log the error and hope that it's something temporary or recoverable A normal reason
// for failure is when neovim has already quit, and a command, for example mouse move is
// being sent
let result = match self {
SerialCommand::Keyboard(input_command) => {
trace!("Keyboard Input Sent: {}", input_command);
nvim.input(&input_command).await.expect("Input failed");
nvim.input(&input_command)
.await
.map(|_| ())
.context("Input failed")
}
SerialCommand::MouseButton {
button,
action,
grid_id,
position: (grid_x, grid_y),
modifier_string,
} => {
nvim.input_mouse(
} => nvim
.input_mouse(
&button,
&action,
&modifier_string,
Expand All @@ -69,15 +76,14 @@ impl SerialCommand {
grid_x as i64,
)
.await
.expect("Mouse Input Failed");
}
.context("Mouse Input Failed"),
SerialCommand::Scroll {
direction,
grid_id,
position: (grid_x, grid_y),
modifier_string,
} => {
nvim.input_mouse(
} => nvim
.input_mouse(
"wheel",
&direction,
&modifier_string,
Expand All @@ -86,15 +92,14 @@ impl SerialCommand {
grid_x as i64,
)
.await
.expect("Mouse Scroll Failed");
}
.context("Mouse Scroll Failed"),
SerialCommand::Drag {
button,
grid_id,
position: (grid_x, grid_y),
modifier_string,
} => {
nvim.input_mouse(
} => nvim
.input_mouse(
&button,
"drag",
&modifier_string,
Expand All @@ -103,8 +108,11 @@ impl SerialCommand {
grid_x as i64,
)
.await
.expect("Mouse Drag Failed");
}
.context("Mouse Drag Failed"),
};

if let Err(error) = result {
log::error!("{:?}", error);
}
}
}
Expand Down Expand Up @@ -205,6 +213,10 @@ async fn unregister_right_click(nvim: &Neovim<NeovimWriter>) -> Result<(), Box<C

impl ParallelCommand {
async fn execute(self, nvim: &Neovim<NeovimWriter>) {
// Don't panic here unless there's absolutely no chance of continuing the program, Instead
// just log the error and hope that it's something temporary or recoverable A normal reason
// for failure is when neovim has already quit, and a command, for example mouse move is
// being sent
let result = match self {
ParallelCommand::Quit => nvim
.command(
Expand Down

0 comments on commit 5fe0215

Please sign in to comment.