Flush buffer on write and ewrite (#47)

This commit is contained in:
metrowaii 2023-05-18 11:28:33 -07:00 committed by GitHub
parent d2ed3bdd5d
commit 2931aa690c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,7 @@
use blocking::unblock;
use dialoguer::{theme::ColorfulTheme, Confirm, Input, MultiSelect, Select};
use mlua::prelude::*;
use std::io::Write;
use crate::lua::{
stdio::{
@ -27,10 +28,12 @@ pub fn create(lua: &'static Lua) -> LuaResult<LuaTable> {
})?
.with_function("write", |_, s: String| {
print!("{s}");
std::io::stdout().flush().expect("Could not flush stdout");
Ok(())
})?
.with_function("ewrite", |_, s: String| {
eprint!("{s}");
std::io::stderr().flush().expect("Could not flush stderr");
Ok(())
})?
.with_async_function("prompt", |_, options: PromptOptions| {