working ps

This commit is contained in:
2025-01-07 21:03:31 -05:00
parent 546dbc7db0
commit 41899480c0
6 changed files with 87 additions and 77 deletions

View File

@ -1,22 +1,29 @@
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub mod session;
pub mod commands;
pub mod ps;
pub mod rc;
pub mod vm;
pub trait MapDisplay<T, E: std::fmt::Display> {
#[inline]
pub fn shell_error<E: core::fmt::Display>(err: E) {
color_print::ceprintln!("<bold,r>[!]:</> {err}")
}
pub trait MapDisplay<T, E: core::fmt::Display> {
fn map_or_display<F: FnOnce(T)>(self, f: F);
fn map_or_display_none<R, F: FnOnce(T) -> Option<R>>(self, f: F) -> Option<R>;
}
impl<T, E: std::fmt::Display> MapDisplay<T, E> for Result<T, E> {
///Map and display an error
impl<T, E: core::fmt::Display> MapDisplay<T, E> for Result<T, E> {
///Map but display the error to stdout
#[inline]
fn map_or_display<F: FnOnce(T)>(self, f: F) {
self.map_or_else(|e| color_print::ceprintln!("<bold,r>[!]:</> {e}"), f)
self.map_or_else(|e| shell_error(e), f)
}
///Map and display an error but return `None`
///Map but display the error to stdout and return `None`
#[inline]
fn map_or_display_none<R, F: FnOnce(T) -> Option<R>>(self, f: F) -> Option<R> {
self.map_or_else(|e| { color_print::ceprintln!("<bold,r>[!]:</> {e}"); None }, f)
self.map_or_else(|e| { shell_error(e); None }, f)
}
}