Skip to content

Commit

Permalink
Reflecting updates to the bash sample program
Browse files Browse the repository at this point in the history
  • Loading branch information
hirooih committed Dec 2, 2024
1 parent 47eddf3 commit 981b6e1
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
4 changes: 3 additions & 1 deletion eg/excallback
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ sub change_prompt {
$prompt = !$prompt;
$t->set_prompt(get_prompt());
}
sub change_promptx {

# The original implementation of change_prompt before rl_set_prompt was introduced.
sub change_prompt_original {
# toggle the prompt variable
$prompt = !$prompt;

Expand Down
15 changes: 10 additions & 5 deletions eg/manexamp
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,29 @@ sub invert_case_line {

my $start = $a->{point};

return 0 if $start >= $a->{end};

# Find the end of the range to modify.
my $end = $start + $count;

# Force it to be within range.
if ($end > $a->{end}) {
$end = $a->{end};
} elsif ($end < 0) {
$end = -1;
$end = 0;
}

return 0 if $start == $end;

# For positive arguments, put point after the last changed character. For
# negative arguments, put point before the last changed character.
$a->{point} = $end;

# Swap start and end if we are moving backwards.
if ($start > $end) {
my $temp = $start;
$start = $end + 1;
$end = $temp + 1;
$start = $end;
$end = $temp;
}

# Tell readline that we are modifying the line, so it will save
Expand All @@ -64,8 +71,6 @@ sub invert_case_line {
# I'm happy with Perl :-)
substr($a->{line_buffer}, $start, $end - $start) =~ tr/A-Za-z/a-zA-Z/;

# Move point to on top of the last character changed.
$a->{point} = $count < 0 ? $start : $end - 1;
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions eg/rl-callbacktest
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ my $sigint_received = 0;
my $running = 0;
my $prompt = 'rltest$ ';

# Handle SIGWINCH and window size changes when readline is not active and
# reading a character.
# Handle window size changes when readline is not active and reading
# characters.
sub sigwinch_handler {
my $sig = shift;
$sigwinch_received = 1;
Expand Down
2 changes: 0 additions & 2 deletions eg/rl-callbacktest2
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ sub sigint_handler {
$t->cleanup_after_signal();
$t->callback_handler_remove();
$saw_signal = 0;
printf STDERR ("sigint_handler: readline state = 0x%lx\n",
$a->{readline_state});
return $s;
}

Expand Down
16 changes: 10 additions & 6 deletions t/readline.t
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,11 @@ sub reverse_line { # reverse a whole line
# From the GNU Readline Library Manual
# Invert the case of the COUNT following characters.
sub invert_case_line {
my($count, $key) = @_;
my ($count, $key) = @_;

my $start = $a->{point};
return 0 if ($start >= $a->{end});

return 0 if $start >= $a->{end};

# Find the end of the range to modify.
my $end = $start + $count;
Expand All @@ -186,21 +187,24 @@ sub invert_case_line {

return 0 if $start == $end;

# For positive arguments, put point after the last changed character. For
# negative arguments, put point before the last changed character.
$a->{point} = $end;

# Swap start and end if we are moving backwards.
if ($start > $end) {
my $temp = $start;
$start = $end;
$end = $temp;
$end = $temp;
}

# Tell readline that we are modifying the line, so it will save
# undo information.
$t->modifying($start, $end);

# I'm happy with Perl :-)
substr($a->{line_buffer}, $start, $end-$start) =~ tr/a-zA-Z/A-Za-z/;
substr($a->{line_buffer}, $start, $end - $start) =~ tr/A-Za-z/a-zA-Z/;

# Move point to on top of the last character changed.
$a->{point} = $count < 0 ? $start : $end - 1;
return 0;
}

Expand Down

0 comments on commit 981b6e1

Please sign in to comment.