diff --git a/quake_tui/src/app.rs b/quake_tui/src/app.rs index b8971aa2..9aa93b1d 100644 --- a/quake_tui/src/app.rs +++ b/quake_tui/src/app.rs @@ -1,4 +1,5 @@ use quake_core::entry::EntryDefines; +use quake_core::quake::QuakeActionNode; use quake_core::QuakeConfig; use serde_yaml; use std::error::Error; @@ -45,12 +46,14 @@ impl Default for App { pub enum Mode { Command, Normal, + Insert, } #[derive(Clone, Debug)] pub enum MainWidget { Home, EntryTypes, + Editor(QuakeActionNode), } impl Widget for MainWidget { @@ -89,6 +92,10 @@ impl Widget for MainWidget { entry_types_list.render(area, buf); } + MainWidget::Editor(_action) => { + let editor = Block::default().borders(Borders::ALL).title("Editor"); + editor.render(area, buf); + } } } } diff --git a/quake_tui/src/command.rs b/quake_tui/src/command.rs index 50249dd4..13712fa7 100644 --- a/quake_tui/src/command.rs +++ b/quake_tui/src/command.rs @@ -1,14 +1,25 @@ -use crate::app::{App, MainWidget}; +use crate::app::{App, MainWidget, Mode}; +use quake_core::parser::quake::QuakeActionNode; pub fn execute_command(command: &str, app: &mut App) -> Result<(), String> { match command { "quit" => app.shutdown(), "listAll" => app.main_widget = MainWidget::EntryTypes, - _ => return Err(format!("Unknown command: {}", command)), + other => execute_action_command(other, app)?, } Ok(()) } +pub fn execute_action_command(command: &str, app: &mut App) -> Result<(), String> { + if let Ok(action) = QuakeActionNode::action_from_text(command) { + app.mode = Mode::Insert; + app.main_widget = MainWidget::Editor(action); + Ok(()) + } else { + Err(format!("Unknown command: {}", command)) + } +} + #[cfg(test)] mod tests { use super::execute_command; diff --git a/quake_tui/src/lib.rs b/quake_tui/src/lib.rs index 655a2e5f..e5f22357 100644 --- a/quake_tui/src/lib.rs +++ b/quake_tui/src/lib.rs @@ -58,7 +58,6 @@ fn run_app(terminal: &mut Terminal, mut app: App) -> Result<(), B KeyCode::Enter => { let command: String = app.command.drain(..).collect(); execute_command(&command, &mut app)?; - app.mode = Mode::Normal; } KeyCode::Char(c) => { app.command.push(c); @@ -71,6 +70,12 @@ fn run_app(terminal: &mut Terminal, mut app: App) -> Result<(), B } _ => {} }, + Mode::Insert => match key.code { + KeyCode::Esc => { + app.mode = Mode::Normal; + } + _ => {} + }, } } } diff --git a/quake_tui/src/ui.rs b/quake_tui/src/ui.rs index 8ec940fd..1a91ece9 100644 --- a/quake_tui/src/ui.rs +++ b/quake_tui/src/ui.rs @@ -14,18 +14,21 @@ pub fn draw(f: &mut Frame, app: &mut App) { .split(f.size()); let command_bar = Paragraph::new(app.command.as_ref()) .style(match app.mode { - Mode::Normal => Style::default(), Mode::Command => Style::default().fg(Color::Yellow), + _ => Style::default(), }) .block(Block::default().borders(Borders::ALL).title("Action")); f.render_widget(command_bar, chunks[0]); + f.render_widget(app.main_widget.clone(), chunks[1]); + match app.mode { Mode::Normal => {} Mode::Command => f.set_cursor( chunks[0].x + app.command.width() as u16 + 1, chunks[0].y + 1, ), + Mode::Insert => { + f.set_cursor(chunks[1].x + 1, chunks[1].y + 1); + } } - - f.render_widget(app.main_widget.clone(), chunks[1]); }