diff options
author | Teddy Wing | 2016-08-06 01:02:57 -0400 |
---|---|---|
committer | Teddy Wing | 2016-08-06 01:02:57 -0400 |
commit | 7f887ca1c11a421cda96ab241ebb117c3657841c (patch) | |
tree | 52470d7481357b872903dc0fd0efa59ac1024c71 /src/main.rs | |
parent | e0d5ae685c7f518647234f30978d1964a5802386 (diff) | |
download | Passextract-7f887ca1c11a421cda96ab241ebb117c3657841c.tar.bz2 |
Move the selection marker with `j` & `k`
The selection arrow can now be moved. Not liking the code duplication.
We'll have to figure something out to sort that.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/main.rs b/src/main.rs index 3b08ad6..fd60bee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,22 +5,9 @@ use rustty::ui::Painter; use std::time::Duration; -struct Selection<'a> { +struct Point { x: usize, y: usize, - terminal: &'a mut Terminal, -} - -impl<'a> Selection<'a> { - fn move_selection(&mut self, amount: usize) { - // Clear old selection cursor - self.terminal.printline(self.x, self.y, " "); - - self.y = self.y + amount; - - let knockout_cell = Cell::with_style(Color::Byte(0x07), Color::Black, Attr::Default); - self.terminal.printline_with_cell(0, 2, "->", knockout_cell); - } } fn main() { @@ -29,12 +16,12 @@ fn main() { let knockout_cell = Cell::with_style(Color::Byte(0x07), Color::Black, Attr::Default); - let selection = Selection { x: 2, y: 2, terminal: &mut term }; + let mut selection = Point { x: 0, y: 2 }; loop { term.printline(0, 0, "Passextract (Press q or Ctrl-C to quit)"); - term.printline_with_cell(0, 2, "->", knockout_cell); + term.printline_with_cell(selection.x, selection.y, "->", knockout_cell); term.printline(5, 2, "test"); let options = vec![ @@ -47,7 +34,7 @@ fn main() { term.printline(5, i + 3, s) } - term.set_cursor(2, 2).unwrap(); + term.set_cursor(selection.x + 2, selection.y).unwrap(); let evt = term.get_event(Duration::from_millis(100)).unwrap(); if let Some(Event::Key(ch)) = evt { @@ -56,9 +43,24 @@ fn main() { break; } 'j' => { - + if selection.y < options.len() + 2 { + term.printline(selection.x, selection.y, " "); + + selection.y = selection.y + 1; + + term.printline_with_cell(selection.x, selection.y, "->", knockout_cell); + term.set_cursor(selection.x + 2, selection.y).unwrap(); + } } '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); + term.set_cursor(selection.x + 2, selection.y).unwrap(); + } } c @ _ => { } |