diff --git a/src/app/events/event_types/event/handlers/ci_output.rs b/src/app/events/event_types/event/handlers/ci_output.rs new file mode 100644 index 0000000..9df9da4 --- /dev/null +++ b/src/app/events/event_types/event/handlers/ci_output.rs @@ -0,0 +1,11 @@ +use anyhow::Result; +use cli_log::info; + +use crate::app::{events::event_types::EventStatus, App}; + +pub async fn handle(app: &mut App<'_>, output: &String) -> Result { + info!("Recieved command output: `{}`", output); + app.ui.set_command_output(output); + + Ok(EventStatus::Ok) +} diff --git a/src/app/events/event_types/event/handlers/lua_command.rs b/src/app/events/event_types/event/handlers/lua_command.rs new file mode 100644 index 0000000..ac459e6 --- /dev/null +++ b/src/app/events/event_types/event/handlers/lua_command.rs @@ -0,0 +1,22 @@ +use anyhow::{Context, Result}; +use cli_log::info; + +use crate::app::{App, events::event_types::{EventStatus, Event}}; + +pub async fn handle(app: &mut App<'_>, command: &str) -> Result { + info!("Recieved ci command: `{command}`; executing.."); + + // TODO: Should the ci support more than strings? + let output = app.lua.context(|context| -> Result { + let output = context + .load(&command) + .eval::() + .with_context(|| format!("Failed to execute: `{command}`"))?; + info!("Function evaluated to: `{output}`"); + Ok(output) + })?; + + app.transmitter.send(Event::CiOutput(output)); + + Ok(EventStatus::Ok) +}