aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorTeddy Wing2016-08-06 05:38:02 -0400
committerTeddy Wing2016-08-06 05:38:02 -0400
commit833339151a14866ccf499dd57f1849766c7c3555 (patch)
tree48e1d80f79beb3d3bdc4e060cd48c681d81eecdb /src/main.rs
parentb4e150f01e9d282a6dab318ee7bb0ee9884b2263 (diff)
downloadPassextract-833339151a14866ccf499dd57f1849766c7c3555.tar.bz2
Make selection arrow movement code DRY
Remove the duplication of these lines for the `j` and `k` commands by extracting them to a function.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/main.rs b/src/main.rs
index 23f808e..04f2738 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -20,6 +20,15 @@ fn strip_key(line: &str) -> &str {
strings[1]
}
+fn move_selection(term: &mut Terminal, selection: &mut Point, style: Cell, amount: isize) {
+ term.printline(selection.x, selection.y, " ");
+
+ let y = selection.y as isize;
+ selection.y = (y + amount) as usize;
+
+ term.printline_with_cell(selection.x, selection.y, "->", style);
+}
+
fn main() {
let mut options = Vec::new();
let stdin = io::stdin();
@@ -65,20 +74,12 @@ fn main() {
}
'j' => {
if selection.y < options.len() + 1 {
- term.printline(selection.x, selection.y, " ");
-
- selection.y = selection.y + 1;
-
- term.printline_with_cell(selection.x, selection.y, "->", knockout_cell);
+ move_selection(&mut term, &mut selection, knockout_cell, 1)
}
}
'k' => {
if selection.y > 2 {
- term.printline(selection.x, selection.y, " ");
-
- selection.y = selection.y - 1;
-
- term.printline_with_cell(selection.x, selection.y, "->", knockout_cell);
+ move_selection(&mut term, &mut selection, knockout_cell, -1)
}
}
'\x0D' => {