diff --git a/src/app.rs b/src/app.rs index 4543cdc..9ec995b 100644 --- a/src/app.rs +++ b/src/app.rs @@ -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, } } } diff --git a/src/handler.rs b/src/handler.rs index ee59053..7713490 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -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(); } _ => { - 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 { diff --git a/src/ui.rs b/src/ui.rs index 57b2dc0..526c042 100644 --- a/src/ui.rs +++ b/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)