diff --git a/src/funcs.rs b/src/funcs.rs index 15ffc34..61d3c88 100644 --- a/src/funcs.rs +++ b/src/funcs.rs @@ -68,6 +68,7 @@ pub fn run_tui( if !state.projects.is_empty() { project_list_state.select(Some(0)); } + let mut history_index = state.history.len(); loop { terminal.draw(|f| { let main_chunks = Layout::default() @@ -84,7 +85,11 @@ pub fn run_tui( .map(|p| ListItem::new(format!(" {} | {}", p.org_name, p.name))) .collect(); let projects_list = List::new(projects) - .block(Block::default().borders(Borders::ALL).title(" Projects ")) + .block( + Block::default() + .borders(Borders::ALL) + .title(" Projects (ctrl + arrow keys to select) "), + ) .highlight_style( Style::default() .bg(Color::Blue) @@ -185,6 +190,7 @@ pub fn run_tui( } state.curent_intput.clear(); } + history_index = state.history.len(); } KeyCode::Char(c) => { state.curent_intput.push(c); @@ -192,14 +198,38 @@ pub fn run_tui( KeyCode::Backspace => { state.curent_intput.pop(); } - KeyCode::Up => { + KeyCode::Up if key.modifiers.is_empty() => { + if !state.history.is_empty() && history_index > 0 { + history_index -= 1; + state.curent_intput = state.history[history_index].clone(); + } + } + KeyCode::Down if key.modifiers.is_empty() => { + if history_index < state.history.len() { + history_index += 1; + if history_index == state.history.len() { + state.curent_intput.clear(); // Clear back to a fresh prompt + } else { + state.curent_intput = state.history[history_index].clone(); + } + } + } + KeyCode::Up + if key + .modifiers + .contains(crossterm::event::KeyModifiers::CONTROL) => + { if let Some(selected) = project_list_state.selected() { if selected > 0 { project_list_state.select(Some(selected - 1)); } } } - KeyCode::Down => { + KeyCode::Down + if key + .modifiers + .contains(crossterm::event::KeyModifiers::CONTROL) => + { if let Some(selected) = project_list_state.selected() { if selected + 1 < state.projects.len() { project_list_state.select(Some(selected + 1)); diff --git a/src/main.rs b/src/main.rs index 52fd61f..3173d31 100644 --- a/src/main.rs +++ b/src/main.rs @@ -59,6 +59,6 @@ fn main() { exit(1); } appstate.initialize_modules(); - run_tui(appstate, rx); + let _res = run_tui(appstate, rx); } }