summaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
authorJeff Zhao <jeff.no.zhao@gmail.com>2021-10-02 08:21:43 -0400
committerJeff Zhao <jeff.no.zhao@gmail.com>2021-10-02 08:21:43 -0400
commit4a22c9a36c2895b3937daa23568b4f1cef599ed9 (patch)
tree9e919560125b3e9a654238bc01c47bdb3d64c065 /src/ui
parentfdbedc755be268884e111c357c8156561cd10f3d (diff)
add basic support for command history
- move worker processing into input.rs - change readline to read_and_execute
Diffstat (limited to 'src/ui')
-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;