Added jobs count section

This commit is contained in:
Emmanuel BENOîT 2022-10-22 15:56:58 +02:00
parent 89de3ee2e8
commit 8e1480c41e
9 changed files with 134 additions and 2 deletions

View file

@ -284,6 +284,24 @@ The theme entries belowed control the Git information sections' appearance:
* `git_stash_fg` and `git_stash_fg` define the background and foreground colors * `git_stash_fg` and `git_stash_fg` define the background and foreground colors
for the stash indicator. for the stash indicator.
### Running jobs
The `jobs` generator will output the amount of background jobs in the current
shell. It is controlled by the following configuration variables:
* `jobs_always` controls whether the job count should be displayed even when
it is zero.
The following theme entries control how the jobs section is displayed.
* `jobs_prefix` and `jobs_suffix` are the text of the prefix and suffix for
the job count.
* `jobs_bg` is the section's background color.
* `jobs_${element}_style` and `jobs_${element}_fg` control the style and
foreground color of the various parts of the section. `${element}` may be:
* `count` for the count itself,
* `prefix` or `suffix`.
### System load ### System load
The `load` generator will output the system's load average for the past minute The `load` generator will output the system's load average for the past minute

View file

@ -27,6 +27,7 @@
] , ] ,
# - Section generators for the input bar # - Section generators for the input bar
layout_input => [ layout_input => [
'jobs' ,
'load' , 'load' ,
'prevcmd' , 'prevcmd' ,
] , ] ,

View file

@ -86,6 +86,10 @@ our %CONFIG = (
# Success/failure colors for 0=nothing, 1=symbol, 2=code, 3=both # Success/failure colors for 0=nothing, 1=symbol, 2=code, 3=both
pcmd_colors => 1 , pcmd_colors => 1 ,
# JOBS
# - Always display?
jobs_always => 0 ,
# LOAD AVERAGE # LOAD AVERAGE
# - Minimal load average before the section is displayed # - Minimal load average before the section is displayed
load_min => 0 , load_min => 0 ,
@ -182,6 +186,21 @@ sub default_theme
# Previous command state - Other text foreground # Previous command state - Other text foreground
'pcmd_text_fg' => -1 , 'pcmd_text_fg' => -1 ,
# Job count - Prefix and suffix text
'jobs_prefix' => '&' ,
'jobs_suffix' => '',
# Job count - Background color
'jobs_bg' => -1 ,
# Job count - Style and foreground color for the job count
'jobs_count_style' => 'b' ,
'jobs_count_fg' => -1 ,
# Job count - Style and foreground color for the prefix
'jobs_prefix_style' => '' ,
'jobs_prefix_fg' => -1 ,
# Job count - Style and foreground color for the suffix
'jobs_suffix_style' => '' ,
'jobs_suffix_fg' => -1 ,
# Load average - Symbol or text # Load average - Symbol or text
'load_title' => 'ld', 'load_title' => 'ld',
# Load average - Low load colors # Load average - Low load colors
@ -730,8 +749,9 @@ _gprompt_set_return() {
} }
gprompt_command() { gprompt_command() {
local cmd_status=\$? local cmd_status=\$?
local jobs=(\$(jobs -p))
eval "\$_GPROMPT_PREVIOUS_PCMD" eval "\$_GPROMPT_PREVIOUS_PCMD"
eval "\$( perl \Q$gpPath\E "rc:\$cmd_status" )" eval "\$( perl \Q$gpPath\E "rc:\$cmd_status" "jobs:\${#jobs[@]}" )"
_gprompt_set_return "\$cmd_status" _gprompt_set_return "\$cmd_status"
} }
shopt -s checkwinsize shopt -s checkwinsize
@ -978,6 +998,41 @@ sub render_load
}; };
} }
# }}}
# Jobs ----------------------------------------------------------------------{{{
sub _render_jobs_part
{
my ($text, $themeName) = @_;
my $style = themed "jobs_${themeName}_style";
return (
{
style => $style ? $style : 'none' ,
fg => themed "jobs_${themeName}_fg" ,
},
$text
);
}
sub render_jobs
{
return () unless exists $INPUT{jobs};
my $jobs = $INPUT{jobs};
return () if $jobs == 0 && !$CONFIG{jobs_always};
my @output = ();
my $section = themed 'jobs_prefix';
@output = _render_jobs_part($section, 'prefix') if $section;
@output = (@output, _render_jobs_part($jobs, 'count'));
$section = themed 'jobs_suffix';
@output = (@output, _render_jobs_part($section, 'prefix')) if $section;
return {
bg => themed( 'jobs_bg' ) ,
content => [ @output ]
};
}
# }}} # }}}
# Git repository information ------------------------------------------------{{{ # Git repository information ------------------------------------------------{{{

View file

@ -79,6 +79,15 @@
# Previous command state - Other text foreground # Previous command state - Other text foreground
'pcmd_text_fg' => SECTION_DEFAULT , 'pcmd_text_fg' => SECTION_DEFAULT ,
# Job count - Prefix and suffix text
'jobs_prefix' => '&' ,
# Job count - Style and foreground color for the job count
'jobs_count_style' => '' ,
'jobs_count_fg' => thref 'fg0' ,
# Job count - Style and foreground color for the prefix
'jobs_prefix_style' => 'd' ,
'jobs_prefix_fg' => thref 'fg0' ,
# Load average - Symbol or text # Load average - Symbol or text
'load_title' => 'ld', 'load_title' => 'ld',
# Load average - Low load colors # Load average - Low load colors

View file

@ -79,6 +79,15 @@
# Previous command state - Other text foreground # Previous command state - Other text foreground
'pcmd_text_fg' => SECTION_DEFAULT , 'pcmd_text_fg' => SECTION_DEFAULT ,
# Job count - Prefix and suffix text
'jobs_prefix' => '&' ,
# Job count - Style and foreground color for the job count
'jobs_count_style' => '' ,
'jobs_count_fg' => thref 'fg0' ,
# Job count - Style and foreground color for the prefix
'jobs_prefix_style' => 'd' ,
'jobs_prefix_fg' => thref 'fg0' ,
# Load average - Symbol or text # Load average - Symbol or text
'load_title' => 'ld', 'load_title' => 'ld',
# Load average - Low load colors # Load average - Low load colors

View file

@ -79,6 +79,15 @@
# Previous command state - Other text foreground # Previous command state - Other text foreground
'pcmd_text_fg' => SECTION_DEFAULT , 'pcmd_text_fg' => SECTION_DEFAULT ,
# Job count - Prefix and suffix text
'jobs_prefix' => "\x{2726}" ,
# Job count - Style and foreground color for the job count
'jobs_count_style' => '' ,
'jobs_count_fg' => 35 ,
# Job count - Style and foreground color for the prefix
'jobs_prefix_style' => 'd' ,
'jobs_prefix_fg' => 35 ,
# Load average - Symbol or text # Load average - Symbol or text
'load_title' => "\x{219f}", 'load_title' => "\x{219f}",
# Load average - Low load colors # Load average - Low load colors

View file

@ -79,6 +79,15 @@
# Previous command state - Other text foreground # Previous command state - Other text foreground
'pcmd_text_fg' => SECTION_DEFAULT , 'pcmd_text_fg' => SECTION_DEFAULT ,
# Job count - Prefix and suffix text
'jobs_prefix' => "\x{2726}" ,
# Job count - Style and foreground color for the job count
'jobs_count_style' => '' ,
'jobs_count_fg' => 39 ,
# Job count - Style and foreground color for the prefix
'jobs_prefix_style' => 'd' ,
'jobs_prefix_fg' => 39 ,
# Load average - Symbol or text # Load average - Symbol or text
'load_title' => "\x{219f}", 'load_title' => "\x{219f}",
# Load average - Low load colors # Load average - Low load colors

View file

@ -8,7 +8,7 @@
# Default foreground color # Default foreground color
'fg' => 15, 'fg' => 15,
# Color gradient used in various parts # Color gradient used in various parts
fg0 => 0 , bg0 => 2 , fg0 => 11 , bg0 => 22 ,
fg1 => 0 , bg1 => 10 , fg1 => 0 , bg1 => 10 ,
fg2 => 0 , bg2 => 11 , fg2 => 0 , bg2 => 11 ,
fg3 => 11, bg3 => 1 , fg3 => 11, bg3 => 1 ,
@ -78,6 +78,17 @@
# Previous command state - Other text foreground # Previous command state - Other text foreground
'pcmd_text_fg' => SECTION_DEFAULT , 'pcmd_text_fg' => SECTION_DEFAULT ,
# Job count - Prefix and suffix text
'jobs_prefix' => "\x{2726}" ,
# Job count - Background color
'jobs_bg' => thref 'bg0' ,
# Job count - Style and foreground color for the job count
'jobs_count_style' => '' ,
'jobs_count_fg' => thref 'fg0' ,
# Job count - Style and foreground color for the prefix
'jobs_prefix_style' => 'd' ,
'jobs_prefix_fg' => thref 'fg0' ,
# Load average - Symbol or text # Load average - Symbol or text
'load_title' => "\x{219f}", 'load_title' => "\x{219f}",
# Load average - Low load colors # Load average - Low load colors

View file

@ -78,6 +78,17 @@
# Previous command state - Other text foreground # Previous command state - Other text foreground
'pcmd_text_fg' => SECTION_DEFAULT , 'pcmd_text_fg' => SECTION_DEFAULT ,
# Job count - Prefix and suffix text
'jobs_prefix' => "\x{2726}" ,
# Job count - Background color
'jobs_bg' => thref 'bg0' ,
# Job count - Style and foreground color for the job count
'jobs_count_style' => '' ,
'jobs_count_fg' => thref 'fg0' ,
# Job count - Style and foreground color for the prefix
'jobs_prefix_style' => 'd' ,
'jobs_prefix_fg' => thref 'fg0' ,
# Load average - Symbol or text # Load average - Symbol or text
'load_title' => "\x{219f}", 'load_title' => "\x{219f}",
# Load average - Low load colors # Load average - Low load colors