# Without this feature enabled, `leanify` subprocesses will receive terminating `SIGINT`s as normal.
shutdown=["libc"]
# TODO: Implement this to: Capture `SIGWINCH` events and re-size + re-render the progress bar to the new terminal width. (XXX: Use a background thread (outside the thread-pool, as it's blocking) listening on `signal_hooks::Signals.forever()` for this that sends events through a shared Tokio `CondVar<TerminalWidth>` notify_all() call.)
# Capture `SIGWINCH` events and re-size + re-render the progress bar to the new terminal width when appropriate.
/// Should we watch for `SIGWINCH` to dynamically resize the progress bar?
///
/// This will return false if there is either: not an output window that can be resized, no rendered progress bar (specified by user,) no dynamic-resize of progress bar (specified by user,) or the `progress-reactive` feature was not enabled at build-time.
@ -144,12 +144,43 @@ where I: IntoIterator<Item=T>,
}
};
// To close the backing handle and un-hook the signals: `close_resize_handle().await.expect("Failed to close reactive handle")`
/// Coerce a potentially-`None` thunk's return type into an `Option`, so that `Option<Fn() -> T>` becomes `Fn() -> Option<T>`.
///
/// # `Option` mapping
/// Example usage would be `maybe_func!(if flag { Some(some_thunk_expr) } else { None })` will map the return type to `Option`, creating a thunk with the same signature as `some_thunk_expr` but an `Option`-wrapped return type.
///
/// ## Internal type-coercion
/// The return-type can also be coerced itself via `maybe_func!(U: option_thunk_expression)` (where `U: From<Option<T>>`,) creating `for<U: From<Option<T>>> Option<Fn() -> T> -> Fn() -> Option<U>`.
macro_rules!maybe_func{
($type:ty: $func:expr)=>{{
letfunc=$func;
move||-> $type{
ifletSome(func)=func{
Some(func()).into()
}else{
None.into()
}
}
}};
($func:expr)=>{{
letfunc=$func;
move||{
ifletSome(func)=func{
Some(func())
}else{
None
}
}
}}
}
// To close the backing handle and un-hook the signals: `close_resize_handle().await[.expect("Failed to close reactive handle")]`
// NOTE: This must be called *before* shutting down the progress-bar.
// The return type is coerced to `Option<io::Result<()>>` (`None` is for if `flags.sigwinch()` is false.)
@ -177,14 +208,16 @@ where I: IntoIterator<Item=T>,
}
});
usestd::io;
asyncmove||-> io::Result<()>{
Some(asyncmove||-> io::Result<()>{
ifhandle.close()?==false{
returnErr(io::Error::new(io::ErrorKind::BrokenPipe,"The `resize_handle` task has already exited before it was requested to (BUG: This is not a problem, but means the resize-handle has not been closed in the right order in the bringdown code.)"));
let_=progress.eprintln(format!("[{}] Warning! Failed to close progress-reactive resize handle: {:?}",colour::style(colour!(Color::Yellow),"!"),e)).await;