Skip to content

Commit

Permalink
focusing, input
Browse files Browse the repository at this point in the history
  • Loading branch information
achristmascarl committed Jun 3, 2024
1 parent 3bc6d48 commit a307b0d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 21 deletions.
18 changes: 9 additions & 9 deletions .config/config.json5
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
"Menu": {
"<q>": "Quit", // Quit the application
"<Ctrl-c>": "Quit", // Yet another way to quit
"<Ctrl-1>": "FocusMenu",
"<Ctrl-2>": "FocusIDE",
"<Ctrl-3>": "FocusData"
"<Alt-1>": "FocusMenu",
"<Alt-2>": "FocusIDE",
"<Alt-3>": "FocusData"
},
"IDE": {
"<Ctrl-c>": "Quit",
"<Ctrl-1>": "FocusMenu",
"<Ctrl-2>": "FocusIDE",
"<Ctrl-3>": "FocusData"
"<Alt-1>": "FocusMenu",
"<Alt-2>": "FocusIDE",
"<Alt-3>": "FocusData"
},
"Data": {
"<q>": "Quit",
"<Ctrl-c>": "Quit",
"<Ctrl-1>": "FocusMenu",
"<Ctrl-2>": "FocusIDE",
"<Ctrl-3>": "FocusData"
"<Alt-1>": "FocusMenu",
"<Alt-2>": "FocusIDE",
"<Alt-3>": "FocusData"
}
}
}
20 changes: 16 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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)?,
Expand All @@ -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.
Expand All @@ -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)?;
}
}
}
}
Expand Down Expand Up @@ -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;
},
Expand Down
15 changes: 7 additions & 8 deletions src/components/ide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<String>()).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(())
}
}
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ impl Config {
}
}

log::info!("{cfg:?}");
Ok(cfg)
}
}
Expand Down

0 comments on commit a307b0d

Please sign in to comment.