diff options
author | Teddy Wing | 2016-08-17 19:42:54 -0400 |
---|---|---|
committer | Teddy Wing | 2016-08-17 19:42:54 -0400 |
commit | 7cdc4aab7d142b83cf85cf42de92971874d53fce (patch) | |
tree | 12dd3f65faf7833b4308b739bb904abe800e09c2 | |
parent | 8f7fc4deea1e02116e4435d1e8a6068fa63e0afd (diff) | |
download | Passextract-7cdc4aab7d142b83cf85cf42de92971874d53fce.tar.bz2 |
Add support for `g` and `G` movements
`g`: moves the selection to the first option
`G`: moves the selection to the last option
This allows for faster selection if there are more than 2–3 options.
Using `g` still allows `gg` to work since doubling the command doesn't
change its meaning.
-rw-r--r-- | src/main.rs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs index c09eb4d..8e497c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,11 +34,10 @@ fn strip_key(line: &str) -> String { strings[1..].join(": ") } -fn move_selection(term: &mut Terminal, selection: &mut Point, style: Cell, amount: isize) { +fn move_selection(term: &mut Terminal, selection: &mut Point, style: Cell, y: usize) { term.printline(selection.x, selection.y, " "); - let y = selection.y as isize; - selection.y = (y + amount) as usize; + selection.y = y; term.printline_with_cell(selection.x, selection.y, "->", style); } @@ -122,14 +121,22 @@ fn main() { } 'j' => { if selection.y < options.len() + 1 { - move_selection(&mut term, &mut selection, knockout_cell, 1) + let y = selection.y; + move_selection(&mut term, &mut selection, knockout_cell, y + 1) } } 'k' => { if selection.y > 2 { - move_selection(&mut term, &mut selection, knockout_cell, -1) + let y = selection.y; + move_selection(&mut term, &mut selection, knockout_cell, y - 1) } } + 'g' => { + move_selection(&mut term, &mut selection, knockout_cell, 2) + } + 'G' => { + move_selection(&mut term, &mut selection, knockout_cell, options.len() + 1) + } '\x0D' => { match clipboard_ctx.set_contents(strip_key(&options[selection.y - 2]).to_owned()) { Ok(_) => { |