pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
    let mut module = context.new_module("cmd_duration");
    let config: CmdDurationConfig = CmdDurationConfig::try_load(module.config);

    if config.min_time < 0 {
        log::warn!(
            "min_time in [cmd_duration] ({}) was less than zero",
            config.min_time
        );
        return None;
    }

    let elapsed = context.get_cmd_duration()?;
    let config_min = config.min_time as u128;

    if elapsed < config_min {
        return None;
    }

    let parsed = StringFormatter::new(config.format).and_then(|formatter| {
        formatter
            .map_style(|variable| match variable {
                "style" => Some(Ok(config.style)),
                _ => None,
            })
            .map(|variable| match variable {
                "duration" => Some(Ok(render_time(elapsed, config.show_milliseconds))),
                _ => None,
            })
            .parse(None)
    });

    module.set_segments(match parsed {
        Ok(segments) => segments,
        Err(error) => {
            log::warn!("Error in module `cmd_duration`: \n{}", error);
            return None;
        }
    });

    Some(undistract_me(module, &config, elapsed))
}
/// Outputs the time it took the last command to execute
///
/// Will only print if last command took more than a certain amount of time to
/// execute. Default is two seconds, but can be set by config option `min_time`.
Outputs the time it took the last command to execute
Will only print if last command took more than a certain amount of time to
execute. Default is two seconds, but can be set by config option `min_time`.
Outputs the time it took the last command to execute Will only print if last command took more than a certain amount of time to execute . Default is two seconds but can be set by config option ` min_time ` .
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
    let mut module = context.new_module("cmd_duration");
    let config: CmdDurationConfig = CmdDurationConfig::try_load(module.config);
    if config.min_time < 0 {
        log::warn!(
            "min_time in [cmd_duration] ({}) was less than zero",
            config.min_time
        );
        return None;
    }
    let elapsed = context.get_cmd_duration()?;
    let config_min = config.min_time as u128;
    if elapsed < config_min {
        return None;
    }
    let parsed = StringFormatter::new(config.format).and_then(|formatter| {
        formatter
            .map_style(|variable| match variable {
                "style" => Some(Ok(config.style)),
                _ => None,
            })
            .map(|variable| match variable {
                "duration" => Some(Ok(render_time(elapsed, config.show_milliseconds))),
                _ => None,
            })
            .parse(None)
    });
    module.set_segments(match parsed {
        Ok(segments) => segments,
        Err(error) => {
            log::warn!("Error in module `cmd_duration`: \n{}", error);
            return None;
        }
    });
    Some(undistract_me(module, &config, elapsed))
}
pub fn module < ' a > ( context : & ' a Context ) -> Option < Module < ' a > > { let mut module = context . new_module ( " " ) ; let config : CmdDurationConfig = CmdDurationConfig :: try_load ( module . config ) ; if config . min_time < 0 { log :: warn ! ( " " config min_time ) ; return None ; } let elapsed = context . get_cmd_duration ( ) ? ; let config_min = config . min_time as u128 ; if elapsed < config_min { return None ; } let parsed = StringFormatter :: new ( config . format ) . and_then ( | formatter | { formatter . map_style ( | variable | match variable { " " => Some ( Ok ( config . style ) ) , _ => None , } ) . map ( | variable | match variable { " " => Some ( Ok ( render_time ( elapsed , config . show_milliseconds ) ) ) , _ => None , } ) . parse ( None ) } ) ; module . set_segments ( match parsed { Ok ( segments ) => segments , Err ( error ) => { log :: warn ! ( " \n " error ) ; return None ; } } ) ; Some ( undistract_me ( module , & config , elapsed ) ) }
Outputs the time it took the last command to execute
Will only print if last command took more than a certain amount of time to
execute.
Outputs the time it took the last command to execute Will only print if last command took more than a certain amount of time to execute .
context
&'a Context