Data input changed for easier extension

This commit is contained in:
Emmanuel BENOîT 2022-10-22 13:32:09 +02:00
parent 73c324286e
commit 89de3ee2e8

View file

@ -248,6 +248,7 @@ sub default_theme
our $HASCWD; our $HASCWD;
our $COLUMNS; our $COLUMNS;
our $RESET; our $RESET;
our %INPUT = ();
our %TCCACHE = (); our %TCCACHE = ();
our %TLEN = (); our %TLEN = ();
our %SCACHE = (); our %SCACHE = ();
@ -728,10 +729,10 @@ _gprompt_set_return() {
return "\${1:-0}" return "\${1:-0}"
} }
gprompt_command() { gprompt_command() {
_GPROMPT_CMD_STATUS=\$? local cmd_status=\$?
eval "\$_GPROMPT_PREVIOUS_PCMD" eval "\$_GPROMPT_PREVIOUS_PCMD"
eval "\$( perl \Q$gpPath\E "\$_GPROMPT_CMD_STATUS" )" eval "\$( perl \Q$gpPath\E "rc:\$cmd_status" )"
_gprompt_set_return "\$_GPROMPT_CMD_STATUS" _gprompt_set_return "\$cmd_status"
} }
shopt -s checkwinsize shopt -s checkwinsize
if [[ \$PROMPT_COMMAND != *"gprompt_command"* ]]; then if [[ \$PROMPT_COMMAND != *"gprompt_command"* ]]; then
@ -742,9 +743,23 @@ EOF
exit 0; exit 0;
} }
sub readArguments
{
printBashInit if @ARGV == 1 && $ARGV[0] eq 'init';
if (@ARGV == 1 && $ARGV[0] =~ /^\d+$/) {
# Backward compatibility
$INPUT{rc} = $ARGV[0];
} else {
foreach my $arg (@ARGV) {
next unless $arg =~ /^([a-z]+):(.*)$/;
$INPUT{$1} = $2;
}
}
}
sub main sub main
{ {
printBashInit if @ARGV && $ARGV[0] eq 'init'; readArguments;
$HASCWD = defined( getcwd ); $HASCWD = defined( getcwd );
chdir '/' unless $HASCWD; chdir '/' unless $HASCWD;
@ -885,7 +900,8 @@ sub render_prevcmd
my ( $ss , $sc , $pc , $cl ) = map { my ( $ss , $sc , $pc , $cl ) = map {
$CONFIG{ "pcmd_$_" } $CONFIG{ "pcmd_$_" }
} qw( show_symbol show_code pad_code colors ); } qw( show_symbol show_code pad_code colors );
my $status = scalar(@ARGV) ? $ARGV[0] : 255; return () unless exists $INPUT{rc};
my $status = $INPUT{rc};
$sc = ( $sc == 1 || ( $sc == 2 && $status ) ); $sc = ( $sc == 1 || ( $sc == 2 && $status ) );
return () unless $sc || $ss; return () unless $sc || $ss;