updated tui logic to allow for history recall, and ctrl of selected

project.
This commit is contained in:
2026-05-20 14:01:53 -05:00
parent e3cb4628f8
commit 2c78f26dd2
2 changed files with 34 additions and 4 deletions
+33 -3
View File
@@ -68,6 +68,7 @@ pub fn run_tui(
if !state.projects.is_empty() { if !state.projects.is_empty() {
project_list_state.select(Some(0)); project_list_state.select(Some(0));
} }
let mut history_index = state.history.len();
loop { loop {
terminal.draw(|f| { terminal.draw(|f| {
let main_chunks = Layout::default() let main_chunks = Layout::default()
@@ -84,7 +85,11 @@ pub fn run_tui(
.map(|p| ListItem::new(format!(" {} | {}", p.org_name, p.name))) .map(|p| ListItem::new(format!(" {} | {}", p.org_name, p.name)))
.collect(); .collect();
let projects_list = List::new(projects) 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( .highlight_style(
Style::default() Style::default()
.bg(Color::Blue) .bg(Color::Blue)
@@ -185,6 +190,7 @@ pub fn run_tui(
} }
state.curent_intput.clear(); state.curent_intput.clear();
} }
history_index = state.history.len();
} }
KeyCode::Char(c) => { KeyCode::Char(c) => {
state.curent_intput.push(c); state.curent_intput.push(c);
@@ -192,14 +198,38 @@ pub fn run_tui(
KeyCode::Backspace => { KeyCode::Backspace => {
state.curent_intput.pop(); 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 let Some(selected) = project_list_state.selected() {
if selected > 0 { if selected > 0 {
project_list_state.select(Some(selected - 1)); 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 let Some(selected) = project_list_state.selected() {
if selected + 1 < state.projects.len() { if selected + 1 < state.projects.len() {
project_list_state.select(Some(selected + 1)); project_list_state.select(Some(selected + 1));
+1 -1
View File
@@ -59,6 +59,6 @@ fn main() {
exit(1); exit(1);
} }
appstate.initialize_modules(); appstate.initialize_modules();
run_tui(appstate, rx); let _res = run_tui(appstate, rx);
} }
} }