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 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 crate::lua::{ use crate::lua::{
stdio::{ stdio::{
@ -27,10 +28,12 @@ pub fn create(lua: &'static Lua) -> LuaResult<LuaTable> {
})? })?
.with_function("write", |_, s: String| { .with_function("write", |_, s: String| {
print!("{s}"); print!("{s}");
std::io::stdout().flush().expect("Could not flush stdout");
Ok(()) Ok(())
})? })?
.with_function("ewrite", |_, s: String| { .with_function("ewrite", |_, s: String| {
eprint!("{s}"); eprint!("{s}");
std::io::stderr().flush().expect("Could not flush stderr");
Ok(()) Ok(())
})? })?
.with_async_function("prompt", |_, options: PromptOptions| { .with_async_function("prompt", |_, options: PromptOptions| {