Merge branch 'dev'

This commit is contained in:
Emmanuel BENOîT 2020-10-23 21:16:50 +02:00
commit 09a20826f9
8 changed files with 68 additions and 17 deletions

View file

@ -221,6 +221,9 @@ following theme entries are required:
when it is too long compared to the terminal's width. when it is too long compared to the terminal's width.
* `cwd_fg_color` and `cwd_bg_color` are the foreground and background color * `cwd_fg_color` and `cwd_bg_color` are the foreground and background color
indices for the section. indices for the section.
* `cwd_missing_fg_color` and `cwd_missing_bg_color` are the foreground and
background color indices that will be used if the current directory is in
fact missing.
### Date/time ### Date/time

View file

@ -13,6 +13,7 @@ use warnings;
use utf8; use utf8;
use open ':std', ':encoding(UTF-8)'; use open ':std', ':encoding(UTF-8)';
use POSIX qw(strftime); use POSIX qw(strftime);
use Cwd;
# DEFAULT CONFIGURATION ====================================================={{{ # DEFAULT CONFIGURATION ====================================================={{{
@ -143,6 +144,9 @@ sub default_theme
# Current working directory - Foreground / background colors # Current working directory - Foreground / background colors
'cwd_fg_color' => 12 , 'cwd_fg_color' => 12 ,
'cwd_bg_color' => -1 , 'cwd_bg_color' => -1 ,
# Current working directory - Colors when directory is missing
'cwd_missing_fg_color' => 1 ,
'cwd_missing_bg_color' => -1 ,
# User@host - Remote host symbol # User@host - Remote host symbol
'uh_remote_symbol' => '(r)', 'uh_remote_symbol' => '(r)',
@ -231,6 +235,7 @@ sub default_theme
# }}} # }}}
# MAIN PROGRAM =============================================================={{{ # MAIN PROGRAM =============================================================={{{
our $HASCWD;
our $COLUMNS; our $COLUMNS;
our %TCCACHE = (); our %TCCACHE = ();
our %TLEN = (); our %TLEN = ();
@ -558,26 +563,26 @@ sub gen_top_line
return "" unless ( @left || @right || $midGen ); return "" unless ( @left || @right || $midGen );
# Generate content # Generate content
my ( @lm , @middle , @mr ) = ( ); my @middle = ( );
my $mc = themed 'bg_middle'; my $mc = themed 'bg_middle';
@left = gen_prompt_sections( 0 , @left ); @left = gen_prompt_sections( 0 , @left );
if ( defined $midGen ) { if ( defined $midGen ) {
@middle = ( gen_prompt_section( $midGen ) ); @middle = ( gen_prompt_section( $midGen ) );
if ( @middle ) { if ( @middle ) {
@lm = ( @middle = (
gen_transition( themed('middle_prefix') , $mc , $mc ) , add_transitions( 'middle' , themed( 'bg_left' ) ,
{ bg => themed('bg_middle') } , themed( 'bg_right' ) , @middle )
); );
@mr = gen_transition( themed('middle_suffix') , $mc , $mc );
foreach my $entry ( @middle ) { foreach my $entry ( @middle ) {
delete $entry->{bg}; delete $entry->{bg};
} }
unshift @middle , { bg => themed('bg_middle') };
} }
} }
@right = gen_prompt_sections( 1 , @right ); @right = gen_prompt_sections( 1 , @right );
# Adapt to width # Adapt to width
my $len = get_length( ( @lm , @middle , @mr ) ); my $len = get_length( ( @middle ) );
@left = adapt_to_width( \$len , 'left' , @left ); @left = adapt_to_width( \$len , 'left' , @left );
@right = reverse adapt_to_width( \$len , 'right' , reverse @right ); @right = reverse adapt_to_width( \$len , 'right' , reverse @right );
@ -591,7 +596,7 @@ sub gen_top_line
# Render # Render
my $txt = render( 'left' , add_transitions( 'left' , 0 , $mc , @left ) ); my $txt = render( 'left' , add_transitions( 'left' , 0 , $mc , @left ) );
$txt .= render( 'middle' , @lm , @middle , @mr , @mpad ); $txt .= render( 'middle' , @middle , @mpad );
$txt .= render( 'right' , add_transitions( 'right' , $mc , 0 , @right ) ); $txt .= render( 'right' , add_transitions( 'right' , $mc , 0 , @right ) );
return $txt . tput_sequence( 'sgr0' ) . "\\n"; return $txt . tput_sequence( 'sgr0' ) . "\\n";
} }
@ -702,6 +707,9 @@ sub load_config
sub main sub main
{ {
$HASCWD = defined( getcwd );
chdir '/' unless $HASCWD;
load_config; load_config;
chop( $COLUMNS = `tput cols` ); chop( $COLUMNS = `tput cols` );
%TLEN = compute_trans_lengths; %TLEN = compute_trans_lengths;
@ -741,8 +749,28 @@ sub render_datetime
sub render_cwd sub render_cwd
{ {
use Cwd; my @out = ( );
my $cwd = getcwd; my $cwd = getcwd;
my @cols;
unless ( $HASCWD ) {
@cols = map { themed $_ } qw(
cwd_missing_bg_color cwd_missing_fg_color );
push @out , {
bg => $cols[0] ,
content => [
{
fg => $cols[1] ,
style => 'i' ,
} ,
'(no cwd)'
] ,
};
return @out unless exists $ENV{PWD};
$cwd = $ENV{PWD};
} else {
@cols = map { themed $_ } qw( cwd_bg_color cwd_fg_color );
$cwd = getcwd;
}
( my $dir = $cwd ) =~ s!^.*/!!; ( my $dir = $cwd ) =~ s!^.*/!!;
my $max_len = int( $COLUMNS * $CONFIG{cwd_max_width} / 100 ); my $max_len = int( $COLUMNS * $CONFIG{cwd_max_width} / 100 );
@ -756,10 +784,11 @@ sub render_cwd
$dir =~ s!^[^/]*/!$t/!; $dir =~ s!^[^/]*/!$t/!;
} }
return { push @out , {
bg => themed 'cwd_bg_color' , bg => $cols[0] ,
content => [ {fg=>themed 'cwd_fg_color'} , $dir ] content => [ {fg=>$cols[1]} , $dir ]
}; };
return @out;
} }
# }}} # }}}
@ -1048,6 +1077,7 @@ sub _render_git_stash
sub render_git sub render_git
{ {
my @out = ( ); my @out = ( );
return @out unless $HASCWD;
system( 'git rev-parse --is-inside-work-tree >/dev/null 2>&1' ); system( 'git rev-parse --is-inside-work-tree >/dev/null 2>&1' );
return @out if $? != 0; return @out if $? != 0;
@out = ( @out , _render_git_branch , _render_git_repstate ); @out = ( @out , _render_git_branch , _render_git_repstate );

View file

@ -24,7 +24,7 @@
'bg_middle' => thref 'bg', 'bg_middle' => thref 'bg',
'fg_middle' => 230, 'fg_middle' => 230,
'middle_prefix' => ' ', 'middle_prefix' => ' ',
'middle_separator' => ' | ', 'middle_separator' => '\f2 | ',
'middle_suffix' => ' ', 'middle_suffix' => ' ',
# Right side of top line # Right side of top line
'bg_right' => thref 'bg', 'bg_right' => thref 'bg',
@ -47,6 +47,9 @@
# Current working directory - Foreground / background colors # Current working directory - Foreground / background colors
'cwd_fg_color' => SECTION_DEFAULT , 'cwd_fg_color' => SECTION_DEFAULT ,
'cwd_bg_color' => SECTION_DEFAULT , 'cwd_bg_color' => SECTION_DEFAULT ,
# Current working directory - Colors when directory is missing
'cwd_missing_fg_color' => thref 'fg3' ,
'cwd_missing_bg_color' => thref 'bg3' ,
# User@host - Remote host symbol # User@host - Remote host symbol
'uh_remote_symbol' => '(r)', 'uh_remote_symbol' => '(r)',

View file

@ -24,7 +24,7 @@
'bg_middle' => thref 'bg', 'bg_middle' => thref 'bg',
'fg_middle' => 189, 'fg_middle' => 189,
'middle_prefix' => ' ', 'middle_prefix' => ' ',
'middle_separator' => ' | ', 'middle_separator' => '\f2 | ',
'middle_suffix' => ' ', 'middle_suffix' => ' ',
# Right side of top line # Right side of top line
'bg_right' => thref 'bg', 'bg_right' => thref 'bg',
@ -47,6 +47,9 @@
# Current working directory - Foreground / background colors # Current working directory - Foreground / background colors
'cwd_fg_color' => SECTION_DEFAULT , 'cwd_fg_color' => SECTION_DEFAULT ,
'cwd_bg_color' => SECTION_DEFAULT , 'cwd_bg_color' => SECTION_DEFAULT ,
# Current working directory - Colors when directory is missing
'cwd_missing_fg_color' => thref 'fg3' ,
'cwd_missing_bg_color' => thref 'bg3' ,
# User@host - Remote host symbol # User@host - Remote host symbol
'uh_remote_symbol' => '(r)', 'uh_remote_symbol' => '(r)',

View file

@ -24,7 +24,7 @@
'bg_middle' => thref 'bg', 'bg_middle' => thref 'bg',
'fg_middle' => 230, 'fg_middle' => 230,
'middle_prefix' => ' ', 'middle_prefix' => ' ',
'middle_separator' => ' | ', 'middle_separator' => "\\f2 \x{2551} ",
'middle_suffix' => ' ', 'middle_suffix' => ' ',
# Right side of top line # Right side of top line
'bg_right' => thref 'bg', 'bg_right' => thref 'bg',
@ -47,6 +47,9 @@
# Current working directory - Foreground / background colors # Current working directory - Foreground / background colors
'cwd_fg_color' => SECTION_DEFAULT , 'cwd_fg_color' => SECTION_DEFAULT ,
'cwd_bg_color' => SECTION_DEFAULT , 'cwd_bg_color' => SECTION_DEFAULT ,
# Current working directory - Colors when directory is missing
'cwd_missing_fg_color' => thref 'fg3' ,
'cwd_missing_bg_color' => thref 'bg3' ,
# User@host - Remote host symbol # User@host - Remote host symbol
'uh_remote_symbol' => "\x{21a5}", 'uh_remote_symbol' => "\x{21a5}",

View file

@ -24,7 +24,7 @@
'bg_middle' => thref 'bg', 'bg_middle' => thref 'bg',
'fg_middle' => 189, 'fg_middle' => 189,
'middle_prefix' => ' ', 'middle_prefix' => ' ',
'middle_separator' => ' | ', 'middle_separator' => "\\f2 \x{2551} ",
'middle_suffix' => ' ', 'middle_suffix' => ' ',
# Right side of top line # Right side of top line
'bg_right' => thref 'bg', 'bg_right' => thref 'bg',
@ -47,6 +47,9 @@
# Current working directory - Foreground / background colors # Current working directory - Foreground / background colors
'cwd_fg_color' => SECTION_DEFAULT , 'cwd_fg_color' => SECTION_DEFAULT ,
'cwd_bg_color' => SECTION_DEFAULT , 'cwd_bg_color' => SECTION_DEFAULT ,
# Current working directory - Colors when directory is missing
'cwd_missing_fg_color' => thref 'fg3' ,
'cwd_missing_bg_color' => thref 'bg3' ,
# User@host - Remote host symbol # User@host - Remote host symbol
'uh_remote_symbol' => "\x{21a5}", 'uh_remote_symbol' => "\x{21a5}",

View file

@ -23,7 +23,7 @@
'bg_middle' => 235, 'bg_middle' => 235,
'fg_middle' => thref 'fg', 'fg_middle' => thref 'fg',
'middle_prefix' => '', 'middle_prefix' => '',
'middle_separator' => ' | ', 'middle_separator' => "\\f2\x{2590}\x{258c}",
'middle_suffix' => '', 'middle_suffix' => '',
# Right side of top line # Right side of top line
'bg_right' => 239, 'bg_right' => 239,
@ -46,6 +46,9 @@
# Current working directory - Foreground / background colors # Current working directory - Foreground / background colors
'cwd_fg_color' => SECTION_DEFAULT , 'cwd_fg_color' => SECTION_DEFAULT ,
'cwd_bg_color' => SECTION_DEFAULT , 'cwd_bg_color' => SECTION_DEFAULT ,
# Current working directory - Colors when directory is missing
'cwd_missing_fg_color' => thref 'bg3' ,
'cwd_missing_bg_color' => SECTION_DEFAULT ,
# User@host - Remote host symbol # User@host - Remote host symbol
'uh_remote_symbol' => "\x{21a5}", 'uh_remote_symbol' => "\x{21a5}",

View file

@ -23,7 +23,7 @@
'bg_middle' => 235, 'bg_middle' => 235,
'fg_middle' => thref 'fg', 'fg_middle' => thref 'fg',
'middle_prefix' => '', 'middle_prefix' => '',
'middle_separator' => ' | ', 'middle_separator' => "\\f2\x{2590}\x{258c}",
'middle_suffix' => '', 'middle_suffix' => '',
# Right side of top line # Right side of top line
'bg_right' => 239, 'bg_right' => 239,
@ -46,6 +46,9 @@
# Current working directory - Foreground / background colors # Current working directory - Foreground / background colors
'cwd_fg_color' => SECTION_DEFAULT , 'cwd_fg_color' => SECTION_DEFAULT ,
'cwd_bg_color' => SECTION_DEFAULT , 'cwd_bg_color' => SECTION_DEFAULT ,
# Current working directory - Colors when directory is missing
'cwd_missing_fg_color' => thref 'bg3' ,
'cwd_missing_bg_color' => SECTION_DEFAULT ,
# User@host - Remote host symbol # User@host - Remote host symbol
'uh_remote_symbol' => "\x{21a5}", 'uh_remote_symbol' => "\x{21a5}",