feat: selection of either the list or input fields
This commit is contained in:
parent
2c19b5cdee
commit
e48ac881f1
|
@ -61,6 +61,8 @@ pub struct App {
|
|||
pub chunk: usize,
|
||||
/// Which list item is currently selected?
|
||||
pub list: ResultList,
|
||||
/// Is the user in an input field?
|
||||
pub editing: bool,
|
||||
}
|
||||
|
||||
impl Default for App {
|
||||
|
@ -75,6 +77,7 @@ impl Default for App {
|
|||
items: Vec::new(),
|
||||
last_selected: None,
|
||||
},
|
||||
editing: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,10 +30,14 @@ pub async fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<
|
|||
last_selected: app.list.last_selected,
|
||||
};
|
||||
app.chunk = 2;
|
||||
app.editing = false;
|
||||
app.input.reset();
|
||||
}
|
||||
_ => {
|
||||
if app.editing == true {
|
||||
app.input.handle_event(&Event::Key(key_event));
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}
|
||||
match key_event.code {
|
||||
|
|
10
src/ui.rs
10
src/ui.rs
|
@ -38,7 +38,10 @@ pub fn render(app: &mut App, frame: &mut Frame) {
|
|||
|
||||
let scroll = app.input.visual_scroll(width as usize);
|
||||
let input = Paragraph::new(app.input.value())
|
||||
.style(Style::default().fg(Color::Yellow))
|
||||
.style(match app.editing {
|
||||
false => Style::default(),
|
||||
true => Style::default().fg(Color::Yellow),
|
||||
})
|
||||
.scroll((0, scroll as u16))
|
||||
.block(
|
||||
Block::default()
|
||||
|
@ -55,7 +58,10 @@ pub fn render(app: &mut App, frame: &mut Frame) {
|
|||
|
||||
let list = List::new(results)
|
||||
.block(Block::bordered().title("Search Results"))
|
||||
.style(Style::default().fg(Color::White))
|
||||
.style(match app.editing {
|
||||
true => Style::default(),
|
||||
false => Style::default().fg(Color::Yellow),
|
||||
})
|
||||
.highlight_style(Style::default().add_modifier(Modifier::ITALIC))
|
||||
.highlight_symbol("┃ ")
|
||||
.repeat_highlight_symbol(true)
|
||||
|
|
Reference in a new issue