From c0a1fc0a021029c804bc931818f746dcd02e65eb 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 264b2c0..c382f73 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 26deb6b..9e257c4 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 @@ -116,10 +116,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 - }, + } }) }