From 57b01f0dbb8a524eb173f36330d5a2b8de1571b0 Mon Sep 17 00:00:00 2001 From: Soispha Date: Wed, 26 Jul 2023 21:08:56 +0200 Subject: [PATCH] Fix(app::command_interface): Add a (workaround) print function The default print function prints to stdout, which obviously doesn't work with a tui application. This wrapper however is a rather poor workaround, as it only works with strings (lua `print` calls `tostring` to turn non string values in something printable). --- src/tui_app/app/command_interface/mod.rs | 6 ++++++ .../app/events/event_types/event/handlers/command.rs | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/tui_app/app/command_interface/mod.rs b/src/tui_app/app/command_interface/mod.rs index 25efa4a..bb66168 100644 --- a/src/tui_app/app/command_interface/mod.rs +++ b/src/tui_app/app/command_interface/mod.rs @@ -13,6 +13,12 @@ use crate::app::Event; #[ci_command_enum] struct Commands { + /// Returns the string given to it + // FIXME(@Soispha): This is a workaround because the default print prints to stdout, + // which is obviously not ideal + print: fn(String) -> String, + + // Begin debug functions /// Greets the user greet: fn(String) -> String, diff --git a/src/tui_app/app/events/event_types/event/handlers/command.rs b/src/tui_app/app/events/event_types/event/handlers/command.rs index 3757b8f..251a488 100644 --- a/src/tui_app/app/events/event_types/event/handlers/command.rs +++ b/src/tui_app/app/events/event_types/event/handlers/command.rs @@ -104,10 +104,16 @@ pub async fn handle( send_main_output!("Hi, {}!", name); EventStatus::Ok } + Command::Print(output) => { + // FIXME(@Soispha): This only works with strings, which is a clear downside to the + // original print function. Find a way to just use the original one + send_main_output!("{}", output); + EventStatus::Ok + } Command::Help(_) => todo!(), Command::RaiseError(err) => { send_error_output!(err); EventStatus::Ok - }, + } }) }