Skip to content

Commit

Permalink
Merge pull request #449 from gwenn/rustfmt
Browse files Browse the repository at this point in the history
Rustfmt
  • Loading branch information
gwenn authored Oct 11, 2020
2 parents e9408c9 + 77b4d00 commit 8f4d899
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ pub enum Cmd {
/// if cursor is in the middle of the text
///
/// If you support multi-line input:
/// * Use `accept_in_the_middle: true` for mostly single-line cases,
/// for example command-line.
/// * Use `accept_in_the_middle: false` for mostly multi-line cases,
/// for example SQL or JSON input.
/// * Use `accept_in_the_middle: true` for mostly single-line cases, for
/// example command-line.
/// * Use `accept_in_the_middle: false` for mostly multi-line cases, for
/// example SQL or JSON input.
AcceptOrInsertLine {
/// Whether this commands accepts input if the cursor not at the end
/// of the current input
accept_in_the_middle: bool
accept_in_the_middle: bool,
},
}

Expand Down
16 changes: 10 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,16 +603,20 @@ fn readline_edit<H: Helper>(
let valid = s.validate()?;
let end = s.line.is_end_of_input();
match (cmd, valid, end) {
| (Cmd::AcceptLine, _, _)
(Cmd::AcceptLine, ..)
| (Cmd::AcceptOrInsertLine { .. }, true, true)
| (Cmd::AcceptOrInsertLine { accept_in_the_middle: true }, true, _)
=> {
| (
Cmd::AcceptOrInsertLine {
accept_in_the_middle: true,
},
true,
_,
) => {
break;
}
| (Cmd::Newline, _, _)
(Cmd::Newline, ..)
| (Cmd::AcceptOrInsertLine { .. }, false, _)
| (Cmd::AcceptOrInsertLine { .. }, true, false)
=> {
| (Cmd::AcceptOrInsertLine { .. }, true, false) => {
s.edit_insert('\n', 1)?;
}
_ => unreachable!(),
Expand Down
7 changes: 6 additions & 1 deletion src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ fn complete_line() {
let keys = vec![KeyPress::Enter];
let mut rdr: IntoIter<KeyPress> = keys.into_iter();
let cmd = super::complete_line(&mut rdr, &mut s, &mut input_state, &Config::default()).unwrap();
assert_eq!(Some(Cmd::AcceptOrInsertLine { accept_in_the_middle: true }), cmd);
assert_eq!(
Some(Cmd::AcceptOrInsertLine {
accept_in_the_middle: true
}),
cmd
);
assert_eq!("rust", s.line.as_str());
assert_eq!(4, s.line.pos());
}
Expand Down

0 comments on commit 8f4d899

Please sign in to comment.