From a307b0d04d63ae760f395a7fa96cbc863aedd1eb Mon Sep 17 00:00:00 2001 From: achristmascarl Date: Mon, 3 Jun 2024 16:37:42 -0400 Subject: [PATCH] focusing, input --- .config/config.json5 | 18 +++++++++--------- src/app.rs | 20 ++++++++++++++++---- src/components/ide.rs | 15 +++++++-------- src/config.rs | 1 + 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/.config/config.json5 b/.config/config.json5 index b845a49..0bfbbbd 100644 --- a/.config/config.json5 +++ b/.config/config.json5 @@ -3,22 +3,22 @@ "Menu": { "": "Quit", // Quit the application "": "Quit", // Yet another way to quit - "": "FocusMenu", - "": "FocusIDE", - "": "FocusData" + "": "FocusMenu", + "": "FocusIDE", + "": "FocusData" }, "IDE": { "": "Quit", - "": "FocusMenu", - "": "FocusIDE", - "": "FocusData" + "": "FocusMenu", + "": "FocusIDE", + "": "FocusData" }, "Data": { "": "Quit", "": "Quit", - "": "FocusMenu", - "": "FocusIDE", - "": "FocusData" + "": "FocusMenu", + "": "FocusIDE", + "": "FocusData" } } } diff --git a/src/app.rs b/src/app.rs index 4b74089..dcea4c6 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,7 +1,11 @@ -use std::sync::{Arc, Mutex}; +use std::{ + fmt::format, + sync::{Arc, Mutex}, +}; use color_eyre::eyre::Result; use crossterm::event::KeyEvent; +use log::log; use ratatui::{ layout::{Constraint, Direction, Layout}, prelude::Rect, @@ -85,6 +89,7 @@ impl App { loop { if let Some(e) = tui.next().await { + let mut consumed = false; match e { tui::Event::Quit => action_tx.send(Action::Quit)?, tui::Event::Tick => action_tx.send(Action::Tick)?, @@ -95,6 +100,7 @@ impl App { if let Some(action) = keymap.get(&vec![key]) { log::info!("Got action: {action:?}"); action_tx.send(action.clone())?; + consumed = true; } else { // If the key was not handled as a single key action, // then consider it for multi-key combinations. @@ -104,15 +110,18 @@ impl App { if let Some(action) = keymap.get(&self.last_tick_key_events) { log::info!("Got action: {action:?}"); action_tx.send(action.clone())?; + consumed = true; } } }; }, _ => {}, } - for component in self.components.to_array().iter_mut() { - if let Some(action) = component.handle_events(Some(e.clone()))? { - action_tx.send(action)?; + if !consumed { + for component in self.components.to_array().iter_mut() { + if let Some(action) = component.handle_events(Some(e.clone()))? { + action_tx.send(action)?; + } } } } @@ -154,14 +163,17 @@ impl App { })?; }, Action::FocusMenu => { + log::info!("FocusMenu"); let mut state = self.state.lock().unwrap(); state.focus = Focus::Menu; }, Action::FocusIDE => { + log::info!("FocusIDE"); let mut state = self.state.lock().unwrap(); state.focus = Focus::IDE; }, Action::FocusData => { + log::info!("FocusData"); let mut state = self.state.lock().unwrap(); state.focus = Focus::Data; }, diff --git a/src/components/ide.rs b/src/components/ide.rs index 92dea4e..d0ff3c9 100644 --- a/src/components/ide.rs +++ b/src/components/ide.rs @@ -86,15 +86,14 @@ impl Component for IDE { fn draw(&mut self, f: &mut Frame<'_>, area: Rect) -> Result<()> { let state = self.state.lock().unwrap(); let focused = state.focus == Focus::IDE; + let block = Block::default().title("top").borders(Borders::ALL).border_style(if focused { + Style::new().green() + } else { + Style::new().dim() + }); + let text = Paragraph::new(self.lines[0].iter().collect::()).block(block); - f.render_widget( - Block::default().title("top").borders(Borders::ALL).border_style(if focused { - Style::new().green() - } else { - Style::new().dim() - }), - area, - ); + f.render_widget(text, area); Ok(()) } } diff --git a/src/config.rs b/src/config.rs index c41e4a3..63942d4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -75,6 +75,7 @@ impl Config { } } + log::info!("{cfg:?}"); Ok(cfg) } }