Skip to content

Commit

Permalink
tile: Use anyhow extension traits
Browse files Browse the repository at this point in the history
to make logging and panicking behavior more concise in the code.
  • Loading branch information
har7an committed Aug 19, 2022
1 parent 526d9c2 commit f9d58dc
Showing 1 changed file with 32 additions and 33 deletions.
65 changes: 32 additions & 33 deletions zellij-tile/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,52 +57,51 @@ macro_rules! register_plugin {
thread_local! {
static STATE: std::cell::RefCell<$t> = std::cell::RefCell::new(Default::default());
}
use zellij_tile::prelude::errors::FatalError;
use zellij_tile::prelude::errors::LoggableError;

fn main() {
catch_fatal(
STATE
.with(|state| {
catch_fatal(
state
.try_borrow_mut()
.context("Failed to borrow plugin state for loading"),
)
STATE
.with(|state| {
state
.try_borrow_mut()
.context("Failed to borrow plugin state for loading")
.fatal()
.load()
})
.context("Failed to get plugin for loading"),
);
})
.context("Failed to get plugin for loading")
.fatal()
}

#[no_mangle]
pub fn update() {
catch(
STATE
.with(|state| {
catch_fatal(
state
.try_borrow_mut()
.context("Failed to borrow plugin state for updating"),
)
.update(catch_fatal(
STATE
.with(|state| {
state
.try_borrow_mut()
.context("Failed to borrow plugin state for updating")
.fatal()
.update(
$crate::shim::object_from_stdin()
.context("Failed to read plugin input for updating"),
))
})
.context("Failed to get plugin for updating"),
);
.context("Failed to read plugin input for updating")
.fatal(),
)
})
.context("Failed to get plugin for updating")
.to_stdout()
.non_fatal();
}

#[no_mangle]
pub fn render(rows: i32, cols: i32) {
STATE.with(|state| {
catch(
catch_fatal(
state
.try_borrow_mut()
.context("Failed to borrow plugin state for rendering"),
)
.render(rows as usize, cols as usize),
)
state
.try_borrow_mut()
.context("Failed to borrow plugin state for rendering")
.fatal()
.render(rows as usize, cols as usize)
.to_stdout()
.non_fatal()
});
}
};
Expand Down

0 comments on commit f9d58dc

Please sign in to comment.