2019-08-12 17:42:33 +00:00
|
|
|
use super::{Context, Module};
|
|
|
|
|
2019-10-10 08:21:52 +00:00
|
|
|
use crate::config::{RootModuleConfig, SegmentConfig};
|
|
|
|
use crate::configs::jobs::JobsConfig;
|
|
|
|
|
2019-08-12 17:42:33 +00:00
|
|
|
/// Creates a segment to show if there are any active jobs running
|
|
|
|
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
2019-09-09 23:14:38 +00:00
|
|
|
let mut module = context.new_module("jobs");
|
2019-10-10 08:21:52 +00:00
|
|
|
let config: JobsConfig = JobsConfig::try_load(module.config);
|
2019-08-12 17:42:33 +00:00
|
|
|
|
2019-10-10 08:21:52 +00:00
|
|
|
module.set_style(config.style);
|
2019-08-12 17:42:33 +00:00
|
|
|
|
|
|
|
let arguments = &context.arguments;
|
|
|
|
let num_of_jobs = arguments
|
|
|
|
.value_of("jobs")
|
|
|
|
.unwrap_or("0")
|
2019-08-13 03:41:59 +00:00
|
|
|
.trim()
|
2019-08-12 17:42:33 +00:00
|
|
|
.parse::<i64>()
|
|
|
|
.ok()?;
|
|
|
|
if num_of_jobs == 0 {
|
|
|
|
return None;
|
|
|
|
}
|
2019-10-10 08:21:52 +00:00
|
|
|
module.create_segment("symbol", &config.symbol);
|
|
|
|
if num_of_jobs > config.threshold {
|
|
|
|
module.create_segment("number", &SegmentConfig::new(&num_of_jobs.to_string()));
|
2019-08-12 17:42:33 +00:00
|
|
|
}
|
|
|
|
module.get_prefix().set_value("");
|
|
|
|
|
|
|
|
Some(module)
|
|
|
|
}
|