#![cfg(test)]
pub(crate) use leviath_testkit::{PANIC_HOOK_LOCK, with_silenced_panics, with_tracing};
pub(crate) struct SilentPanics {
_lock: std::sync::MutexGuard<'static, ()>,
previous: PanicHook,
}
type PanicHook = Box<dyn Fn(&std::panic::PanicHookInfo<'_>) + Sync + Send + 'static>;
fn swallow_panic(_: &std::panic::PanicHookInfo<'_>) {}
impl SilentPanics {
pub(crate) fn install() -> Self {
let lock = PANIC_HOOK_LOCK
.lock()
.unwrap_or_else(std::sync::PoisonError::into_inner);
let previous = std::panic::take_hook();
std::panic::set_hook(Box::new(swallow_panic));
Self {
_lock: lock,
previous,
}
}
}
impl Drop for SilentPanics {
fn drop(&mut self) {
let previous = std::mem::replace(&mut self.previous, Box::new(swallow_panic));
std::panic::set_hook(previous);
}
}
pub(crate) fn hints(on: bool) -> leviath_core::config::PromptHints {
leviath_core::config::PromptHints {
batch_tool: on,
shell: on,
}
}