summaryrefslogtreecommitdiff
path: root/src/app.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/app.rs')
-rw-r--r--src/app.rs35
1 files changed, 13 insertions, 22 deletions
diff --git a/src/app.rs b/src/app.rs
index 2e956eb..476d4c0 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -1,7 +1,8 @@
use std::{io, time::Duration};
use crate::{
- config, lua,
+ config::{self, keymap::GlobalKeyMap},
+ lua,
sheet::register::Register,
state::{window::Window, GlobalState},
tui,
@@ -11,7 +12,7 @@ use crate::{
use ratatui::{
crossterm::{
- event::{self, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers},
+ event::{self, Event, KeyEvent, KeyEventKind},
ExecutableCommand,
},
prelude::*,
@@ -19,7 +20,6 @@ use ratatui::{
#[derive(Default)]
pub struct App {
- exit: bool,
view: SheetView,
editor: LuaEditor,
logview: LogView,
@@ -34,7 +34,6 @@ impl App {
.set_active_sheet(Some(sheet_id));
Self {
- exit: false,
view: SheetView::new(),
editor: LuaEditor::new(),
logview: LogView::new(),
@@ -44,12 +43,12 @@ impl App {
pub fn run(mut self, terminal: &mut tui::Tui) -> io::Result<()> {
if let Err(e) = lua::source(&config::constants::USER_RC_PATH) {
- self.exit = true;
tui::restore()?;
println!("{}", e);
+ return Ok(());
}
- while !self.exit {
+ while !{ GlobalState::instance().exit } {
terminal.draw(|frame| {
self.render_frame(frame);
@@ -84,27 +83,19 @@ impl App {
Ok(())
}
- fn handle_key_event(&mut self, key_event: KeyEvent) {
+ fn handle_key_event(&mut self, event: KeyEvent) {
let focus = { GlobalState::instance().active_window };
- match key_event.code {
- KeyCode::Char('q') if key_event.modifiers == KeyModifiers::CONTROL => self.exit(),
- KeyCode::Char('l') if key_event.modifiers == KeyModifiers::CONTROL => {
- let mut state = GlobalState::instance_mut();
- state.log.visible = !state.log.visible;
- }
- _ => match focus {
- Window::View => self.view.handle_key_event(key_event),
- Window::Editor => self.editor.handle_key_event(key_event),
- Window::Log => self.logview.handle_key_event(key_event),
+
+ if !GlobalKeyMap::handle(event) {
+ match focus {
+ Window::View => self.view.handle_key_event(event),
+ Window::Editor => self.editor.handle_key_event(event),
+ Window::Log => self.logview.handle_key_event(event),
Window::Error => {}
- },
+ }
}
}
- fn exit(&mut self) {
- self.exit = true;
- }
-
fn area(&self, area: Rect) -> (Rect, Option<Rect>, Option<Rect>) {
let state = GlobalState::instance();
let mut view = area;