mirror of
https://github.com/lune-org/lune.git
synced 2024-12-12 13:00:37 +00:00
Add support for writing arbitrary bytes to stdout/stderr
This commit is contained in:
parent
2931aa690c
commit
2b94dbabe0
1 changed files with 9 additions and 7 deletions
|
@ -1,7 +1,7 @@
|
||||||
use blocking::unblock;
|
use blocking::unblock;
|
||||||
use dialoguer::{theme::ColorfulTheme, Confirm, Input, MultiSelect, Select};
|
use dialoguer::{theme::ColorfulTheme, Confirm, Input, MultiSelect, Select};
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
use std::io::Write;
|
use tokio::io::{self, AsyncWriteExt};
|
||||||
|
|
||||||
use crate::lua::{
|
use crate::lua::{
|
||||||
stdio::{
|
stdio::{
|
||||||
|
@ -26,14 +26,16 @@ pub fn create(lua: &'static Lua) -> LuaResult<LuaTable> {
|
||||||
.with_function("format", |_, args: LuaMultiValue| {
|
.with_function("format", |_, args: LuaMultiValue| {
|
||||||
pretty_format_multi_value(&args)
|
pretty_format_multi_value(&args)
|
||||||
})?
|
})?
|
||||||
.with_function("write", |_, s: String| {
|
.with_async_function("write", |_, s: LuaString| async move {
|
||||||
print!("{s}");
|
let mut stdout = io::stdout();
|
||||||
std::io::stdout().flush().expect("Could not flush stdout");
|
stdout.write_all(s.as_bytes()).await?;
|
||||||
|
stdout.flush().await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
})?
|
})?
|
||||||
.with_function("ewrite", |_, s: String| {
|
.with_async_function("ewrite", |_, s: LuaString| async move {
|
||||||
eprint!("{s}");
|
let mut stderr = io::stderr();
|
||||||
std::io::stderr().flush().expect("Could not flush stderr");
|
stderr.write_all(s.as_bytes()).await?;
|
||||||
|
stderr.flush().await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
})?
|
})?
|
||||||
.with_async_function("prompt", |_, options: PromptOptions| {
|
.with_async_function("prompt", |_, options: PromptOptions| {
|
||||||
|
|
Loading…
Reference in a new issue