From 8e1480c41ea058157011bea8542be181f24782a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Sat, 22 Oct 2022 15:56:58 +0200 Subject: [PATCH] Added jobs count section --- README.md | 18 +++++++++++++ example-gprompt.rc | 1 + gprompt.pl | 57 ++++++++++++++++++++++++++++++++++++++++- themes/ascii_gyr.pm | 9 +++++++ themes/ascii_yb.pm | 9 +++++++ themes/blocks_gyr.pm | 9 +++++++ themes/blocks_yb.pm | 9 +++++++ themes/powerline_gyr.pm | 13 +++++++++- themes/powerline_yb.pm | 11 ++++++++ 9 files changed, 134 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f182cdd..13934a8 100644 --- a/README.md +++ b/README.md @@ -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 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 The `load` generator will output the system's load average for the past minute diff --git a/example-gprompt.rc b/example-gprompt.rc index bc8545f..1c4b33e 100644 --- a/example-gprompt.rc +++ b/example-gprompt.rc @@ -27,6 +27,7 @@ ] , # - Section generators for the input bar layout_input => [ + 'jobs' , 'load' , 'prevcmd' , ] , diff --git a/gprompt.pl b/gprompt.pl index 754830a..c0aab0e 100644 --- a/gprompt.pl +++ b/gprompt.pl @@ -86,6 +86,10 @@ our %CONFIG = ( # Success/failure colors for 0=nothing, 1=symbol, 2=code, 3=both pcmd_colors => 1 , + # JOBS + # - Always display? + jobs_always => 0 , + # LOAD AVERAGE # - Minimal load average before the section is displayed load_min => 0 , @@ -182,6 +186,21 @@ sub default_theme # Previous command state - Other text foreground '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_title' => 'ld', # Load average - Low load colors @@ -730,8 +749,9 @@ _gprompt_set_return() { } gprompt_command() { local cmd_status=\$? + local jobs=(\$(jobs -p)) 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" } 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 ------------------------------------------------{{{ diff --git a/themes/ascii_gyr.pm b/themes/ascii_gyr.pm index 2950993..4339e93 100644 --- a/themes/ascii_gyr.pm +++ b/themes/ascii_gyr.pm @@ -79,6 +79,15 @@ # Previous command state - Other text foreground '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_title' => 'ld', # Load average - Low load colors diff --git a/themes/ascii_yb.pm b/themes/ascii_yb.pm index 82b429d..39ebc3e 100644 --- a/themes/ascii_yb.pm +++ b/themes/ascii_yb.pm @@ -79,6 +79,15 @@ # Previous command state - Other text foreground '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_title' => 'ld', # Load average - Low load colors diff --git a/themes/blocks_gyr.pm b/themes/blocks_gyr.pm index 4f24263..703c4ab 100644 --- a/themes/blocks_gyr.pm +++ b/themes/blocks_gyr.pm @@ -79,6 +79,15 @@ # Previous command state - Other text foreground '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_title' => "\x{219f}", # Load average - Low load colors diff --git a/themes/blocks_yb.pm b/themes/blocks_yb.pm index 4366900..76e1708 100644 --- a/themes/blocks_yb.pm +++ b/themes/blocks_yb.pm @@ -79,6 +79,15 @@ # Previous command state - Other text foreground '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_title' => "\x{219f}", # Load average - Low load colors diff --git a/themes/powerline_gyr.pm b/themes/powerline_gyr.pm index d871f74..3db23f7 100644 --- a/themes/powerline_gyr.pm +++ b/themes/powerline_gyr.pm @@ -8,7 +8,7 @@ # Default foreground color 'fg' => 15, # Color gradient used in various parts - fg0 => 0 , bg0 => 2 , + fg0 => 11 , bg0 => 22 , fg1 => 0 , bg1 => 10 , fg2 => 0 , bg2 => 11 , fg3 => 11, bg3 => 1 , @@ -78,6 +78,17 @@ # Previous command state - Other text foreground '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_title' => "\x{219f}", # Load average - Low load colors diff --git a/themes/powerline_yb.pm b/themes/powerline_yb.pm index f7d1f0b..aa02959 100644 --- a/themes/powerline_yb.pm +++ b/themes/powerline_yb.pm @@ -78,6 +78,17 @@ # Previous command state - Other text foreground '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_title' => "\x{219f}", # Load average - Low load colors