summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/config/README.md3
-rw-r--r--src/modules/jobs.rs41
2 files changed, 41 insertions, 3 deletions
diff --git a/docs/config/README.md b/docs/config/README.md
index 1433f4691..b7e53246b 100644
--- a/docs/config/README.md
+++ b/docs/config/README.md
@@ -1453,7 +1453,8 @@ symbol = "🌟 "
The `jobs` module shows the current number of jobs running.
The module will be shown only if there are background jobs running.
The module will show the number of jobs running if there is more than 1 job, or
-more than the `threshold` config value, if it exists.
+more than the `threshold` config value, if it exists. If `threshold` is set to 0,
+then the module will also show when there are 0 jobs running.
::: warning
diff --git a/src/modules/jobs.rs b/src/modules/jobs.rs
index ecb75aff4..e045ec0fd 100644
--- a/src/modules/jobs.rs
+++ b/src/modules/jobs.rs
@@ -15,11 +15,20 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
.trim()
.parse::<i64>()
.ok()?;
- if num_of_jobs == 0 {
+
+ if config.threshold < 0 {
+ log::warn!(
+ "threshold in [jobs] ({}) was less than zero",
+ config.threshold
+ );
+ return None;
+ }
+
+ if num_of_jobs == 0 && config.threshold > 0 {
return None;
}
- let module_number = if num_of_jobs > config.threshold {
+ let module_number = if num_of_jobs > config.threshold || config.threshold == 0 {
num_of_jobs.to_string()
} else {
"".to_string()
@@ -109,4 +118,32 @@ mod test {
let expected = Some(format!("{} ", Color::Blue.bold().paint("✦3")));
assert_eq!(expected, actual);
}
+
+ #[test]
+ fn config_0_job_0() {
+ let actual = ModuleRenderer::new("jobs")
+ .config(toml::toml! {
+ [jobs]
+ threshold = 0
+ })
+ .jobs(0)
+ .collect();
+
+ let expected = Some(format!("{} ", Color::Blue.bold().paint("✦0")));
+ assert_eq!(expected, actual);
+ }
+
+ #[test]
+ fn config_0_job_1() {
+ let actual = ModuleRenderer::new("jobs")
+ .config(toml::toml! {
+ [jobs]
+ threshold = 0
+ })
+ .jobs(1)
+ .collect();
+
+ let expected = Some(format!("{} ", Color::Blue.bold().paint("✦1")));
+ assert_eq!(expected, actual);
+ }
}