input: Let function_pop_arg return an Option

This would crash if you ran `commandline -f backward-jump`.

The C++ version would read a char (but badly), this doesn't anymore.

So, at least instead of crashing, just do nothing.
This commit is contained in:
Fabian Boehm 2024-06-10 16:59:43 +02:00
parent 19d92a9476
commit c7d878a8d2
3 changed files with 9 additions and 5 deletions

View File

@ -495,10 +495,9 @@ impl Inputter {
self.input_function_args.push(arg);
}
pub fn function_pop_arg(&mut self) -> char {
pub fn function_pop_arg(&mut self) -> Option<char> {
self.input_function_args
.pop()
.expect("function_pop_arg underflow")
}
fn function_push_args(&mut self, code: ReadlineCmd) {

View File

@ -3072,10 +3072,11 @@ impl ReaderData {
_ => unreachable!(),
};
let (elt, _el) = self.active_edit_line();
let target = self.inputter.function_pop_arg();
let success = self.jump(direction, precision, elt, target);
if let Some(target) = self.inputter.function_pop_arg() {
let success = self.jump(direction, precision, elt, target);
self.inputter.function_set_status(success);
self.inputter.function_set_status(success);
}
}
rl::RepeatJump => {
let (elt, _el) = self.active_edit_line();

View File

@ -372,6 +372,10 @@ send('\x07') # ctrl-g
send('\r')
expect_prompt("foobar")
# This should do nothing instead of crash
sendline("commandline -f backward-jump")
expect_prompt()
# Check that the builtin version of `exit` works
# (for obvious reasons this MUST BE LAST)
sendline("function myexit; echo exit; exit; end; bind ctrl-z myexit")