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).
This commit is contained in:
Benedikt Peetz 2023-07-26 21:08:56 +02:00
parent 1a35bb152c
commit c0a1fc0a02
Signed by: bpeetz
GPG Key ID: A5E94010C3A642AD
2 changed files with 13 additions and 1 deletions

View File

@ -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,

View File

@ -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
},
}
})
}