Merge branch 'ft/clear-bg' into dev

This commit is contained in:
Emmanuel BENOîT 2020-10-23 12:55:27 +02:00
commit 3200aec75c
8 changed files with 178 additions and 113 deletions

View file

@ -189,10 +189,24 @@ background color indices, while values between `2` and `9` will refer to the
contents of the `transition` list.
In addition to the entries above, theme definitions contain entries that are
specific to the various generators. These entries are documented below. When
the generator-specific entries list color indices, the special `-1` value may
be used to indicate that the current area's foreground or background color
should be used.
specific to the various generators. These entries are documented below.
A few special values can be used to simplify writing theme definitions.
* The `thref` function may be used to copy values from other elements in the
current theme definition, for example:
bg_left => 1 ,
bg_middle => 2 ,
bg_right => thref 'bg_left' , # Left/right always use the same bg color
* The `TERM_DEFAULT` value may be used for either background or foreground
color definitions. The terminal's default color will be used for the text in
question.
* The `SECTION_DEFAULT` value may be used in generator-specific definitions to
indicate that the current section's foreground or background color should be
used.
## Generators

View file

@ -111,31 +111,31 @@ sub default_theme
# Extra colors for transition strings
'transition' => [ 7 ] ,
# Left side of top line
'bg_left' => 0,
'fg_left' => 7,
'bg_left' => -2,
'fg_left' => -2,
'left_prefix' => '' ,
'left_separator' => ' ' ,
'left_suffix' => '\f2 | ' ,
# Middle of top line
'bg_middle' => 0,
'fg_middle' => 7,
'bg_middle' => -2,
'fg_middle' => -2,
'middle_prefix' => ' ',
'middle_separator' => ' ',
'middle_suffix' => ' ',
# Right side of top line
'bg_right' => 0,
'fg_right' => 7,
'bg_right' => -2,
'fg_right' => -2,
'right_prefix' => '\f2 | ' ,
'right_separator' => ' ' ,
'right_suffix' => '' ,
# Input line
'bg_input' => 0,
'fg_input' => 7,
'bg_input' => -2,
'fg_input' => -2,
'input_prefix' => '' ,
'input_separator' => '\f2:' ,
'input_suffix' => '\f2 ; ' ,
# Secondary prompt
'bg_ps2' => 0,
'bg_ps2' => -2,
ps2_suffix => ' : ' ,
# Current working directory - Truncation string
@ -236,6 +236,14 @@ our %TCCACHE = ();
our %TLEN = ();
our %SCACHE = ();
our %THEME = ();
our %STYLES = (
none => '' ,
b => 'bold' ,
u => 'smul' ,
i => 'sitm' ,
bu => 'bold,smul' ,
iu => 'sitm,smul' ,
);
# Terminal commands ---------------------------------------------------------{{{
@ -260,6 +268,9 @@ sub set_color
sub thref($) { bless {r=>$_[0]}, 'ThemeRef'; }
sub TERM_DEFAULT() { -2 }
sub SECTION_DEFAULT() { -1 }
sub load_theme
{
my $theme = $CONFIG{layout_theme};
@ -462,6 +473,20 @@ sub add_transitions
return @out;
}
sub apply_style
{
my ( $bg , $fg , $style ) = @_;
my $out = tput_sequence( 'sgr0' );
$out .= set_color( 'b' , $bg ) unless $bg == -2;
$out .= set_color( 'f' , $fg ) unless $fg == -2;
if ( $style ne 'none' ) {
foreach my $ctrl ( split /,/, $STYLES{ $style } ) {
$out .= tput_sequence( $ctrl );
}
}
return $out;
}
sub render
{
my $name = shift;
@ -469,27 +494,53 @@ sub render
my $out = '';
my $mustSetFg = undef;
my $mustSetBg = undef;
my $mustSetStyle = undef;
my $bgDefault = themed( 'bg_' . $name );
my $fgDefault = themed( 'fg_' . $name );
my ( $fg , $bg , $style ) = ( -2 , -2 , 'none' );
foreach my $section ( @_ ) {
$mustSetBg = $section->{bg} if exists $section->{bg};
foreach my $part ( @{ $section->{content} } ) {
if ( ref $part ) {
$mustSetBg = $part->{bg} if exists $part->{bg};
$mustSetFg = $part->{fg} if exists $part->{fg};
$mustSetStyle = $part->{style} if exists $part->{style};
} else {
# Check background color changes
if ( defined $mustSetBg ) {
$mustSetBg = $bgDefault if $mustSetBg < 0;
$out .= set_color( 'b' , $mustSetBg );
$mustSetBg = $bgDefault if $mustSetBg == -1;
$mustSetBg = undef if $mustSetBg == $bg;
}
# Check foreground color changes
if ( defined $mustSetFg ) {
$mustSetFg = $fgDefault if $mustSetFg == -1;
$mustSetFg = undef if $mustSetFg == $fg;
}
# Check style changes
if ( defined( $mustSetStyle ) && ( $mustSetStyle eq $style
|| !exists( $STYLES{ $style } ) ) ) {
$mustSetStyle = undef;
}
# Change style and colors if necessary
if ( defined( $mustSetBg ) || defined( $mustSetFg )
|| defined( $mustSetStyle ) ) {
if ( defined $mustSetBg ) {
$bg = $mustSetBg;
$mustSetBg = undef;
}
if ( defined $mustSetFg ) {
$mustSetFg = $fgDefault if $mustSetFg < 0;
$out .= set_color( 'f' , $mustSetFg );
$fg = $mustSetFg;
$mustSetFg = undef;
}
if ( defined $mustSetStyle ) {
$style = $mustSetStyle;
$mustSetStyle = undef;
}
$out .= apply_style( $bg , $fg , $style );
}
$part =~ s/\\/\\\\/g;
$part =~ s/"/\\\"/g;
$out .= $part;
$mustSetBg = $mustSetFg = undef;
}
}
}

View file

@ -4,15 +4,15 @@
'padding' => '-',
# Extra colors for transition strings
'transition' => [ 0 , 230 ] ,
'transition' => [ TERM_DEFAULT , 230 ] ,
# Default background/foreground colors
'bg' => 0,
'bg' => TERM_DEFAULT,
'fg' => 7,
# Color gradient used in various parts
fg0 => 2 , bg0 => -1 ,
fg1 => 10 , bg1 => -1 ,
fg2 => 11 , bg2 => -1 ,
fg3 => 9 , bg3 => -1 ,
fg0 => 2 , bg0 => SECTION_DEFAULT ,
fg1 => 10 , bg1 => SECTION_DEFAULT ,
fg2 => 11 , bg2 => SECTION_DEFAULT ,
fg3 => 9 , bg3 => SECTION_DEFAULT ,
# Left side of top line
'bg_left' => thref 'bg',
@ -45,8 +45,8 @@
# Current working directory - Truncation string
cwd_trunc => '...' ,
# Current working directory - Foreground / background colors
'cwd_fg_color' => -1 ,
'cwd_bg_color' => -1 ,
'cwd_fg_color' => SECTION_DEFAULT ,
'cwd_bg_color' => SECTION_DEFAULT ,
# User@host - Remote host symbol
'uh_remote_symbol' => '(r)',
@ -58,27 +58,27 @@
'uh_root_bg' => thref 'bg3' ,
# Date/time - Colors
'dt_time_fg' => -1 ,
'dt_date_fg' => -1 ,
'dt_bg' => -1 ,
'dt_time_fg' => SECTION_DEFAULT ,
'dt_date_fg' => SECTION_DEFAULT ,
'dt_bg' => SECTION_DEFAULT ,
# Previous command state - Symbols
'pcmd_ok_sym' => ':-)',
'pcmd_err_sym' => ':-(',
# Previous command state - OK text / background color
'pcmd_ok_fg' => thref 'fg0',
'pcmd_ok_bg' => -1 ,
'pcmd_ok_bg' => SECTION_DEFAULT ,
# Previous command state - Error text / background color
'pcmd_err_fg' => thref 'fg3',
'pcmd_err_bg' => -1 ,
'pcmd_err_bg' => SECTION_DEFAULT ,
# Previous command state - Other text foreground
'pcmd_text_fg' => -1 ,
'pcmd_text_fg' => SECTION_DEFAULT ,
# Load average - Symbol or text
'load_title' => 'ld',
# Load average - Low load colors
'load_low_fg' => -1,
'load_low_bg' => -1,
'load_low_fg' => SECTION_DEFAULT,
'load_low_bg' => SECTION_DEFAULT,
# Load average - Medium load colors
'load_med_fg' => thref 'fg2',
'load_med_bg' => thref 'bg2',
@ -126,6 +126,6 @@
'git_stash_fg' => thref 'fg1' ,
# Python virtual environment section colors
'pyenv_fg' => -1,
'pyenv_bg' => -1,
'pyenv_fg' => SECTION_DEFAULT,
'pyenv_bg' => SECTION_DEFAULT,
}

View file

@ -4,15 +4,15 @@
'padding' => '-',
# Extra colors for transition strings
'transition' => [ 0 , 189 ] ,
'transition' => [ TERM_DEFAULT , 189 ] ,
# Default background/foreground colors
'bg' => 0,
'bg' => TERM_DEFAULT,
'fg' => 7,
# Color gradient used in various parts
fg0 => 69 , bg0 => -1 ,
fg1 => 117 , bg1 => -1 ,
fg2 => 178 , bg2 => -1 ,
fg3 => 226 , bg3 => -1 ,
fg0 => 69 , bg0 => SECTION_DEFAULT ,
fg1 => 117 , bg1 => SECTION_DEFAULT ,
fg2 => 178 , bg2 => SECTION_DEFAULT ,
fg3 => 226 , bg3 => SECTION_DEFAULT ,
# Left side of top line
'bg_left' => thref 'bg',
@ -45,8 +45,8 @@
# Current working directory - Truncation string
cwd_trunc => '...' ,
# Current working directory - Foreground / background colors
'cwd_fg_color' => -1 ,
'cwd_bg_color' => -1 ,
'cwd_fg_color' => SECTION_DEFAULT ,
'cwd_bg_color' => SECTION_DEFAULT ,
# User@host - Remote host symbol
'uh_remote_symbol' => '(r)',
@ -58,27 +58,27 @@
'uh_root_bg' => thref 'bg3' ,
# Date/time - Colors
'dt_time_fg' => -1 ,
'dt_date_fg' => -1 ,
'dt_bg' => -1 ,
'dt_time_fg' => SECTION_DEFAULT ,
'dt_date_fg' => SECTION_DEFAULT ,
'dt_bg' => SECTION_DEFAULT ,
# Previous command state - Symbols
'pcmd_ok_sym' => ':-)',
'pcmd_err_sym' => ':-(',
# Previous command state - OK text / background color
'pcmd_ok_fg' => thref 'fg0',
'pcmd_ok_bg' => -1 ,
'pcmd_ok_bg' => SECTION_DEFAULT ,
# Previous command state - Error text / background color
'pcmd_err_fg' => thref 'fg3',
'pcmd_err_bg' => -1 ,
'pcmd_err_bg' => SECTION_DEFAULT ,
# Previous command state - Other text foreground
'pcmd_text_fg' => -1 ,
'pcmd_text_fg' => SECTION_DEFAULT ,
# Load average - Symbol or text
'load_title' => 'ld',
# Load average - Low load colors
'load_low_fg' => -1,
'load_low_bg' => -1,
'load_low_fg' => SECTION_DEFAULT,
'load_low_bg' => SECTION_DEFAULT,
# Load average - Medium load colors
'load_med_fg' => thref 'fg2',
'load_med_bg' => thref 'bg2',
@ -126,6 +126,6 @@
'git_stash_fg' => thref 'fg1' ,
# Python virtual environment section colors
'pyenv_fg' => -1,
'pyenv_bg' => -1,
'pyenv_fg' => SECTION_DEFAULT,
'pyenv_bg' => SECTION_DEFAULT,
}

View file

@ -4,15 +4,15 @@
'padding' => "\x{2500}",
# Extra colors for transition strings
'transition' => [ 0 , 230 ] ,
'transition' => [ TERM_DEFAULT , 230 ] ,
# Default background/foreground colors
'bg' => 0,
'bg' => TERM_DEFAULT,
'fg' => 7,
# Color gradient used in various parts
fg0 => 2 , bg0 => -1 ,
fg1 => 10 , bg1 => -1 ,
fg2 => 11 , bg2 => -1 ,
fg3 => 9 , bg3 => -1 ,
fg0 => 2 , bg0 => SECTION_DEFAULT ,
fg1 => 10 , bg1 => SECTION_DEFAULT ,
fg2 => 11 , bg2 => SECTION_DEFAULT ,
fg3 => 9 , bg3 => SECTION_DEFAULT ,
# Left side of top line
'bg_left' => thref 'bg',
@ -45,8 +45,8 @@
# Current working directory - Truncation string
'cwd_trunc' => "\x{2026}",
# Current working directory - Foreground / background colors
'cwd_fg_color' => -1 ,
'cwd_bg_color' => -1 ,
'cwd_fg_color' => SECTION_DEFAULT ,
'cwd_bg_color' => SECTION_DEFAULT ,
# User@host - Remote host symbol
'uh_remote_symbol' => "\x{21a5}",
@ -58,27 +58,27 @@
'uh_root_bg' => thref 'bg3' ,
# Date/time - Colors
'dt_time_fg' => -1 ,
'dt_date_fg' => -1 ,
'dt_bg' => -1 ,
'dt_time_fg' => SECTION_DEFAULT ,
'dt_date_fg' => SECTION_DEFAULT ,
'dt_bg' => SECTION_DEFAULT ,
# Previous command state - Symbols
'pcmd_ok_sym' => "\x{2713}",
'pcmd_err_sym' => "\x{2717}",
# Previous command state - OK text / background color
'pcmd_ok_fg' => thref 'fg0',
'pcmd_ok_bg' => -1 ,
'pcmd_ok_bg' => SECTION_DEFAULT ,
# Previous command state - Error text / background color
'pcmd_err_fg' => thref 'fg3',
'pcmd_err_bg' => -1 ,
'pcmd_err_bg' => SECTION_DEFAULT ,
# Previous command state - Other text foreground
'pcmd_text_fg' => -1 ,
'pcmd_text_fg' => SECTION_DEFAULT ,
# Load average - Symbol or text
'load_title' => "\x{219f}",
# Load average - Low load colors
'load_low_fg' => -1,
'load_low_bg' => -1,
'load_low_fg' => SECTION_DEFAULT,
'load_low_bg' => SECTION_DEFAULT,
# Load average - Medium load colors
'load_med_fg' => thref 'fg2',
'load_med_bg' => thref 'bg2',
@ -126,6 +126,6 @@
'git_stash_fg' => thref 'fg1' ,
# Python virtual environment section colors
'pyenv_fg' => -1,
'pyenv_bg' => -1,
'pyenv_fg' => SECTION_DEFAULT,
'pyenv_bg' => SECTION_DEFAULT,
}

View file

@ -4,15 +4,15 @@
'padding' => "\x{2500}",
# Extra colors for transition strings
'transition' => [ 0, 189 ],
'transition' => [ TERM_DEFAULT, 189 ],
# Default background/foreground colors
'bg' => 0,
'bg' => TERM_DEFAULT,
'fg' => 7,
# Color gradient used in various parts
fg0 => 69, bg0 => -1,
fg1 => 117, bg1 => -1,
fg2 => 178, bg2 => -1,
fg3 => 226, bg3 => -1,
fg0 => 69, bg0 => SECTION_DEFAULT,
fg1 => 117, bg1 => SECTION_DEFAULT,
fg2 => 178, bg2 => SECTION_DEFAULT,
fg3 => 226, bg3 => SECTION_DEFAULT,
# Left side of top line
'bg_left' => thref 'bg',
@ -45,8 +45,8 @@
# Current working directory - Truncation string
'cwd_trunc' => "\x{2026}",
# Current working directory - Foreground / background colors
'cwd_fg_color' => -1 ,
'cwd_bg_color' => -1 ,
'cwd_fg_color' => SECTION_DEFAULT ,
'cwd_bg_color' => SECTION_DEFAULT ,
# User@host - Remote host symbol
'uh_remote_symbol' => "\x{21a5}",
@ -58,27 +58,27 @@
'uh_root_bg' => thref 'bg3' ,
# Date/time - Colors
'dt_time_fg' => -1 ,
'dt_date_fg' => -1 ,
'dt_bg' => -1 ,
'dt_time_fg' => SECTION_DEFAULT ,
'dt_date_fg' => SECTION_DEFAULT ,
'dt_bg' => SECTION_DEFAULT ,
# Previous command state - Symbols
'pcmd_ok_sym' => "\x{2713}",
'pcmd_err_sym' => "\x{2717}",
# Previous command state - OK text / background color
'pcmd_ok_fg' => thref 'fg0',
'pcmd_ok_bg' => -1 ,
'pcmd_ok_bg' => SECTION_DEFAULT ,
# Previous command state - Error text / background color
'pcmd_err_fg' => thref 'fg3',
'pcmd_err_bg' => -1 ,
'pcmd_err_bg' => SECTION_DEFAULT ,
# Previous command state - Other text foreground
'pcmd_text_fg' => -1 ,
'pcmd_text_fg' => SECTION_DEFAULT ,
# Load average - Symbol or text
'load_title' => "\x{219f}",
# Load average - Low load colors
'load_low_fg' => -1,
'load_low_bg' => -1,
'load_low_fg' => SECTION_DEFAULT,
'load_low_bg' => SECTION_DEFAULT,
# Load average - Medium load colors
'load_med_fg' => thref 'fg2',
'load_med_bg' => thref 'bg2',
@ -126,6 +126,6 @@
'git_stash_fg' => thref 'fg1' ,
# Python virtual environment section colors
'pyenv_fg' => -1,
'pyenv_bg' => -1,
'pyenv_fg' => SECTION_DEFAULT,
'pyenv_bg' => SECTION_DEFAULT,
}

View file

@ -44,8 +44,8 @@
# Current working directory - Truncation string
'cwd_trunc' => "\x{2026}",
# Current working directory - Foreground / background colors
'cwd_fg_color' => -1 ,
'cwd_bg_color' => -1 ,
'cwd_fg_color' => SECTION_DEFAULT ,
'cwd_bg_color' => SECTION_DEFAULT ,
# User@host - Remote host symbol
'uh_remote_symbol' => "\x{21a5}",
@ -57,27 +57,27 @@
'uh_root_bg' => thref 'bg3' ,
# Date/time - Colors
'dt_time_fg' => -1 ,
'dt_date_fg' => -1 ,
'dt_bg' => -1 ,
'dt_time_fg' => SECTION_DEFAULT ,
'dt_date_fg' => SECTION_DEFAULT ,
'dt_bg' => SECTION_DEFAULT ,
# Previous command state - Symbols
'pcmd_ok_sym' => "\x{2713}",
'pcmd_err_sym' => "\x{2717}",
# Previous command state - OK text / background color
'pcmd_ok_fg' => 10 ,
'pcmd_ok_bg' => -1 ,
'pcmd_ok_bg' => SECTION_DEFAULT ,
# Previous command state - Error text / background color
'pcmd_err_fg' => 11 ,
'pcmd_err_bg' => 1 ,
# Previous command state - Other text foreground
'pcmd_text_fg' => -1 ,
'pcmd_text_fg' => SECTION_DEFAULT ,
# Load average - Symbol or text
'load_title' => "\x{219f}",
# Load average - Low load colors
'load_low_fg' => -1,
'load_low_bg' => -1,
'load_low_fg' => SECTION_DEFAULT,
'load_low_bg' => SECTION_DEFAULT,
# Load average - Medium load colors
'load_med_fg' => thref 'fg2',
'load_med_bg' => thref 'bg2',
@ -125,6 +125,6 @@
'git_stash_fg' => thref 'fg1' ,
# Python virtual environment section colors
'pyenv_fg' => -1,
'pyenv_bg' => -1,
'pyenv_fg' => SECTION_DEFAULT,
'pyenv_bg' => SECTION_DEFAULT,
}

View file

@ -44,8 +44,8 @@
# Current working directory - Truncation string
'cwd_trunc' => "\x{2026}",
# Current working directory - Foreground / background colors
'cwd_fg_color' => -1 ,
'cwd_bg_color' => -1 ,
'cwd_fg_color' => SECTION_DEFAULT ,
'cwd_bg_color' => SECTION_DEFAULT ,
# User@host - Remote host symbol
'uh_remote_symbol' => "\x{21a5}",
@ -57,27 +57,27 @@
'uh_root_bg' => thref 'bg3' ,
# Date/time - Colors
'dt_time_fg' => -1 ,
'dt_date_fg' => -1 ,
'dt_bg' => -1 ,
'dt_time_fg' => SECTION_DEFAULT ,
'dt_date_fg' => SECTION_DEFAULT ,
'dt_bg' => SECTION_DEFAULT ,
# Previous command state - Symbols
'pcmd_ok_sym' => "\x{2713}",
'pcmd_err_sym' => "\x{2717}",
# Previous command state - OK text / background color
'pcmd_ok_fg' => thref( 'fg3' ) ,
'pcmd_ok_bg' => -1 ,
'pcmd_ok_bg' => SECTION_DEFAULT ,
# Previous command state - Error text / background color
'pcmd_err_fg' => thref( 'fg0' ) ,
'pcmd_err_bg' => -1 ,
'pcmd_err_bg' => SECTION_DEFAULT ,
# Previous command state - Other text foreground
'pcmd_text_fg' => -1 ,
'pcmd_text_fg' => SECTION_DEFAULT ,
# Load average - Symbol or text
'load_title' => "\x{219f}",
# Load average - Low load colors
'load_low_fg' => -1,
'load_low_bg' => -1,
'load_low_fg' => SECTION_DEFAULT,
'load_low_bg' => SECTION_DEFAULT,
# Load average - Medium load colors
'load_med_fg' => thref 'fg2',
'load_med_bg' => thref 'bg2',
@ -125,6 +125,6 @@
'git_stash_fg' => thref 'fg1' ,
# Python virtual environment section colors
'pyenv_fg' => -1,
'pyenv_bg' => -1,
'pyenv_fg' => SECTION_DEFAULT,
'pyenv_bg' => SECTION_DEFAULT,
}