feat: Implement the prompt module for jobs (#85)

This commit is contained in:
John Letey
2019-08-12 18:42:33 +01:00
committed by Matan Kushner
parent 3f6fe50adb
commit 82cf484ced
9 changed files with 161 additions and 8 deletions
+32
View File
@@ -0,0 +1,32 @@
use ansi_term::Color;
use super::{Context, Module};
/// 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 threshold = module.config_value_i64("threshold").unwrap_or(1);
const JOB_CHAR: &str = "";
let module_color = Color::Blue.bold();
module.set_style(module_color);
let arguments = &context.arguments;
let num_of_jobs = arguments
.value_of("jobs")
.unwrap_or("0")
.parse::<i64>()
.ok()?;
if num_of_jobs == 0 {
return None;
}
module.new_segment("symbol", JOB_CHAR);
if num_of_jobs > threshold {
module.new_segment("number", &num_of_jobs.to_string());
}
module.get_prefix().set_value("");
Some(module)
}
+2
View File
@@ -5,6 +5,7 @@ mod directory;
mod git_branch;
mod git_status;
mod golang;
mod jobs;
mod line_break;
mod nodejs;
mod package;
@@ -30,6 +31,7 @@ pub fn handle<'a>(module: &str, context: &'a Context) -> Option<Module<'a>> {
"username" => username::module(context),
"battery" => battery::module(context),
"cmd_duration" => cmd_duration::module(context),
"jobs" => jobs::module(context),
_ => panic!("Unknown module: {}", module),
}