feat: selection of either the list or input fields

This commit is contained in:
Muhammad Nauman Raza 2024-05-28 21:20:59 +01:00
parent 2c19b5cdee
commit e48ac881f1
Signed by: devraza
GPG key ID: 91EAD6081011574B
3 changed files with 16 additions and 3 deletions

View file

@ -61,6 +61,8 @@ pub struct App {
pub chunk: usize, pub chunk: usize,
/// Which list item is currently selected? /// Which list item is currently selected?
pub list: ResultList, pub list: ResultList,
/// Is the user in an input field?
pub editing: bool,
} }
impl Default for App { impl Default for App {
@ -75,6 +77,7 @@ impl Default for App {
items: Vec::new(), items: Vec::new(),
last_selected: None, last_selected: None,
}, },
editing: true,
} }
} }
} }

View file

@ -30,10 +30,14 @@ pub async fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<
last_selected: app.list.last_selected, last_selected: app.list.last_selected,
}; };
app.chunk = 2; app.chunk = 2;
app.editing = false;
app.input.reset(); app.input.reset();
} }
_ => { _ => {
app.input.handle_event(&Event::Key(key_event)); if app.editing == true {
app.input.handle_event(&Event::Key(key_event));
} else {
}
} }
} }
match key_event.code { match key_event.code {

View file

@ -38,7 +38,10 @@ pub fn render(app: &mut App, frame: &mut Frame) {
let scroll = app.input.visual_scroll(width as usize); let scroll = app.input.visual_scroll(width as usize);
let input = Paragraph::new(app.input.value()) 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)) .scroll((0, scroll as u16))
.block( .block(
Block::default() Block::default()
@ -55,7 +58,10 @@ pub fn render(app: &mut App, frame: &mut Frame) {
let list = List::new(results) let list = List::new(results)
.block(Block::bordered().title("Search 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_style(Style::default().add_modifier(Modifier::ITALIC))
.highlight_symbol("") .highlight_symbol("")
.repeat_highlight_symbol(true) .repeat_highlight_symbol(true)