mirror of
https://github.com/chmln/handlr.git
synced 2024-11-23 09:41:45 +01:00
Better handle cancellation
This commit is contained in:
parent
3ce7a69d46
commit
29534ae341
3 changed files with 17 additions and 6 deletions
|
@ -57,6 +57,10 @@ impl Config {
|
|||
output.trim_end().to_owned()
|
||||
};
|
||||
|
||||
Ok(output)
|
||||
if output.is_empty() {
|
||||
Err(Error::Cancelled)
|
||||
} else {
|
||||
Ok(output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ pub enum Error {
|
|||
MimeDetect(#[from] mime_detective::DetectiveError),
|
||||
#[error("error spawning selector process '{0}'")]
|
||||
Selector(String),
|
||||
#[error("selection cancelled")]
|
||||
Cancelled,
|
||||
}
|
||||
|
||||
pub type Result<T, E = Error> = std::result::Result<T, E>;
|
||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -54,14 +54,19 @@ fn main() -> Result<()> {
|
|||
}();
|
||||
|
||||
match (res, atty::is(atty::Stream::Stdout)) {
|
||||
(Err(e), true) => eprintln!("{}", e),
|
||||
(Err(e), _) if matches!(e, Error::Cancelled) => {
|
||||
std::process::exit(1);
|
||||
}
|
||||
(Err(e), true) => {
|
||||
eprintln!("{}", e);
|
||||
std::process::exit(1);
|
||||
}
|
||||
(Err(e), false) => {
|
||||
std::process::Command::new("notify-send")
|
||||
.args(&["handlr error", &e.to_string()])
|
||||
.spawn()?;
|
||||
std::process::exit(1);
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
|
||||
Ok(())
|
||||
_ => Ok(()),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue