summaryrefslogtreecommitdiffstats
path: root/src/ui/views/tui_textfield.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/views/tui_textfield.rs')
-rw-r--r--src/ui/views/tui_textfield.rs38
1 files changed, 36 insertions, 2 deletions
diff --git a/src/ui/views/tui_textfield.rs b/src/ui/views/tui_textfield.rs
index c86b49f..348c0f4 100644
--- a/src/ui/views/tui_textfield.rs
+++ b/src/ui/views/tui_textfield.rs
@@ -86,6 +86,8 @@ impl<'a> TuiTextField<'a> {
let terminal = backend.terminal_mut();
let _ = terminal.show_cursor();
+ let mut curr_history_index = context.commandline_context_ref().history_ref().len();
+
loop {
terminal
.draw(|frame| {
@@ -186,8 +188,40 @@ impl<'a> TuiTextField<'a> {
line_buffer.move_end();
completion_tracker.take();
}
- Key::Up => {}
- Key::Down => {}
+ Key::Up => {
+ curr_history_index = if curr_history_index > 0 {
+ curr_history_index - 1
+ } else {
+ 0
+ };
+ line_buffer.move_home();
+ line_buffer.kill_line();
+ if let Some(s) = context
+ .commandline_context_ref()
+ .history_ref()
+ .get(curr_history_index)
+ {
+ line_buffer.insert_str(0, s);
+ }
+ }
+ Key::Down => {
+ curr_history_index = if curr_history_index
+ < context.commandline_context_ref().history_ref().len()
+ {
+ curr_history_index + 1
+ } else {
+ curr_history_index
+ };
+ line_buffer.move_home();
+ line_buffer.kill_line();
+ if let Some(s) = context
+ .commandline_context_ref()
+ .history_ref()
+ .get(curr_history_index)
+ {
+ line_buffer.insert_str(0, s);
+ }
+ }
Key::Esc => {
let _ = terminal.hide_cursor();
return None;