1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-11-16 01:57:07 +00:00
starship/src/modules/jobs.rs
Barnaby Keene 2c7e01cd62 refactor: improve as-a-library usage by removing ArgMatches depe… (#547)
This removes ArgMatches from the Context struct and replaces it with a simple HashMap. This work is towards getting Starship in a better place for use as a library in other shells written in Rust so they don't need to use a command-line interface to invoke and configure things.

Contributes to #521
2019-10-20 17:26:27 +09:00

31 lines
881 B
Rust

use super::{Context, Module};
use crate::config::{RootModuleConfig, SegmentConfig};
use crate::configs::jobs::JobsConfig;
/// Creates a segment to show if there are any active jobs running
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let mut module = context.new_module("jobs");
let config: JobsConfig = JobsConfig::try_load(module.config);
module.set_style(config.style);
let props = &context.properties;
let num_of_jobs = props
.get("jobs")
.unwrap_or(&"0".into())
.trim()
.parse::<i64>()
.ok()?;
if num_of_jobs == 0 {
return None;
}
module.create_segment("symbol", &config.symbol);
if num_of_jobs > config.threshold {
module.create_segment("number", &SegmentConfig::new(&num_of_jobs.to_string()));
}
module.get_prefix().set_value("");
Some(module)
}