summaryrefslogtreecommitdiff
path: root/src/app.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/app.rs')
-rw-r--r--src/app.rs41
1 files changed, 30 insertions, 11 deletions
diff --git a/src/app.rs b/src/app.rs
index 89b19dc..e93748f 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -5,11 +5,15 @@ use crate::{
sheet::register::Register,
state::{window::Window, GlobalState},
tui,
+ tuicursor::TuiCursor,
widgets::{logview::LogView, luaeditor::LuaEditor, sheetview::SheetView},
};
use ratatui::{
- crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers},
+ crossterm::{
+ event::{self, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers},
+ ExecutableCommand,
+ },
prelude::*,
};
@@ -19,6 +23,7 @@ pub struct App {
view: SheetView,
editor: LuaEditor,
logview: LogView,
+ cursor: Option<TuiCursor>,
}
impl App {
@@ -33,10 +38,11 @@ impl App {
view: SheetView::new(),
editor: LuaEditor::new(),
logview: LogView::new(),
+ cursor: None,
}
}
- pub fn run(&mut self, terminal: &mut tui::Tui) -> io::Result<()> {
+ 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()?;
@@ -44,7 +50,18 @@ impl App {
}
while !self.exit {
- terminal.draw(|frame| self.render_frame(frame))?;
+ terminal.draw(|frame| {
+ self.render_frame(frame);
+
+ if let Some(cursor) = &self.cursor {
+ frame.set_cursor(cursor.position.1, cursor.position.0);
+ }
+ })?;
+
+ if let Some(cursor) = &self.cursor {
+ terminal.backend_mut().execute(cursor.style)?;
+ }
+
self.handle_events()?;
}
@@ -75,13 +92,11 @@ impl App {
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),
- Window::Error => {},
- }
+ _ => 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),
+ Window::Error => {}
},
}
}
@@ -103,7 +118,8 @@ impl App {
}
if state.editor.visible {
- let layout = Layout::horizontal([Constraint::Min(1), Constraint::Length(80)]).split(view);
+ let layout =
+ Layout::horizontal([Constraint::Min(1), Constraint::Length(80)]).split(view);
view = layout[0];
editor = Some(layout[1]);
}
@@ -121,8 +137,11 @@ impl Widget for &mut App {
self.view.render(view, buf);
+ self.cursor = None;
+
if let Some(editor) = editor {
self.editor.render(editor, buf);
+ self.cursor = self.editor.render_cursor().map(|c| c.relative_to(editor));
}
if let Some(log) = log {