-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flexible AcceptLine, fix bug in multi-line accept #379
Conversation
src/lib.rs
Outdated
// Move to end, in case cursor was in the middle of the | ||
// line, so that next thing application prints goes after | ||
// the input | ||
s.edit_move_buffer_end()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If line
is empty, there is no need to move the cursor, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. But we need to clear the hint. Fixed.
* This commit allows keybinding for forcing accept line (even if validator fails). This is useful if you have a separate keybinding for accepting, such as `Alt-Enter`. It makes sense to show an error to user rather than insert an unexpected newline. * Forcing `Newline` is also accepted * `AcceptLine` meaning is changed (not it forces accept), but default `Enter` keybinding is not * `AcceptOrInsertLine` not has a flag that modifies it's behavior in the middle of the line (at the end it always submits, when validator returned false it's always a newline) * Fixed bug with exiting readline (both on success and error) when cursor is not on the last line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good to me. I will do some tests...
src/lib.rs
Outdated
@@ -281,15 +281,16 @@ fn page_completions<C: Candidate, H: Helper>( | |||
&& cmd != Cmd::SelfInsert(1, ' ') | |||
&& cmd != Cmd::Kill(Movement::BackwardChar(1)) | |||
&& cmd != Cmd::AcceptLine | |||
&& cmd != Cmd::AcceptOrInsertLine | |||
&& cmd != Cmd::Newline | |||
&& matches!(cmd, Cmd::AcceptOrInsertLine { .. }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&& !matches!(cmd, Cmd::AcceptOrInsertLine { .. })
(not matches)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
src/lib.rs
Outdated
@@ -509,8 +511,12 @@ fn readline_edit<H: Helper>( | |||
s.edit_overwrite_char(c)?; | |||
} | |||
Cmd::EndOfFile => { | |||
if s.has_hint() || !s.is_default_prompt() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only if line is empty or in vi mode ?
That is when the action is not edit_delete
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. But I'm not sure that if !input_state.is_emacs_mode() && !s.line.is_empty()
makes sense. Ctrl+D
should be "scroll downwards" in vim, not "submit".
=> { | ||
break; | ||
} | ||
| (Cmd::Newline, _, _) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unreachable ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Thanks!
(this is actually why I'd like the top-level match to be exhaustive, as this error would have been spotted by the compiler)
src/lib.rs
Outdated
// Move to end, in case cursor was in the middle of the | ||
// line, so that next thing application prints goes after | ||
// the input | ||
s.edit_move_end()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
edit_move_buffer_end ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's better. Thanks!
@@ -913,7 +929,9 @@ impl InputState { | |||
} | |||
} | |||
KeyPress::Ctrl('J') | | |||
KeyPress::Enter => Cmd::AcceptLine, | |||
KeyPress::Enter => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AcceptLine == AcceptOrInsertLine { accept_in_the_middle: true }
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, accept whatever is fully formed command or insert a newline otherwies. That's for backwards compatibility. As described in the docstring above this is what makes most sense for mostly-single-line cases (i.e. a command-line like in nushell).
Thanks you. |
} | ||
if s.line.is_empty() { | ||
return Err(error::ReadlineError::Eof); | ||
} else if !input_state.is_emacs_mode() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always true
validator fails). This is useful if you have a separate keybinding
for accepting, such as
Alt-Enter
. It makes sense to show an errorto user rather than insert an unexpected newline.
Newline
is also acceptedAcceptLine
meaning is changed (now it forces accept),but default
Enter
keybinding is notAcceptOrInsertLine
now has a flag that modifies it's behavior inthe middle of the line (at the end it always submits, when validator
returned false it's always a newline)
cursor is not on the last line
I'm not sure that current command-names are the best possible, so let me know if we can do better. The primary motivator was (1) from above.
This conflicts with #342. I'll rebase other one when either of them is merged.