updated tui logic to allow for history recall, and ctrl of selected
project.
This commit is contained in:
+33
-3
@@ -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
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user