#![deny(warnings)]
mod console;
mod extension;
mod geometry;
mod global;
mod local;
mod term;
mod util;
use dolang::runtime::{Args, Input, Output, Result, Slot, Strand, Type, Value, vm::Builder};
pub use crate::{console::Console, extension::TermExt, geometry::Geometry};
use crate::global::Global;
pub fn install_console<'v>(
builder: &mut Builder<'v>,
console: impl Input<'v>,
can_style: bool,
line_ending: &str,
) {
let global = builder.state::<Global<'v>>();
Output::set(builder, &mut *global.host.console.borrow_mut(), console);
Output::set(
builder,
&mut *global.host.line_ending.borrow_mut(),
line_ending,
);
global.host.can_style.set(can_style);
}
pub fn console_type<'v>(builder: &Builder<'v>) -> Type<'v, Console> {
builder.state::<Global<'v>>().types.console
}
pub fn geometry_type<'v>(builder: &Builder<'v>) -> Type<'v, Geometry> {
builder.state::<Global<'v>>().types.geometry
}
pub fn write_data<'v, 's>(
strand: &mut Strand<'v, 's>,
args: Args<'v, '_>,
) -> Result<'v, 's, Vec<u8>> {
util::write_data(strand, args)
}
pub async fn write<'v, 's>(strand: &mut Strand<'v, 's>, bytes: &[u8]) -> Result<'v, 's, ()> {
console::write(strand, bytes).await
}
pub async fn writeln<'v, 's>(strand: &mut Strand<'v, 's>, bytes: &[u8]) -> Result<'v, 's, ()> {
console::writeln(strand, bytes).await
}
pub async fn flush<'v, 's>(strand: &mut Strand<'v, 's>) -> Result<'v, 's, ()> {
console::flush(strand).await
}
pub fn ansi_enabled<'v>(strand: &Strand<'v, '_>) -> bool {
console::ansi(strand)
}
pub fn is_captured<'v>(strand: &Strand<'v, '_>) -> bool {
console::is_captured(strand)
}
pub fn default_output<'v>(strand: &mut Strand<'v, '_>, out: impl Output<'v>) {
let global = strand.state::<Global<'v>>();
global
.types
.default
.create(strand, console::DefaultOutput, out)
}
pub fn is_default_output<'v>(strand: &Strand<'v, '_>, value: &Value<'v>) -> bool {
let global = strand.state::<Global<'v>>();
global.types.default.cast(value).is_some()
}
pub fn terminal_output<'v>(strand: &mut Strand<'v, '_>, out: impl Output<'v>) {
console::capture_root(strand, out)
}
pub fn terminal_line_ending<'v, 's>(strand: &mut Strand<'v, 's>) -> Result<'v, 's, Vec<u8>> {
console::ambient_line_ending(strand)
}
pub async fn write_terminal_line<'v, 's>(
strand: &mut Strand<'v, 's>,
output: &Value<'v>,
line_ending: &[u8],
line: &str,
) -> Result<'v, 's, ()> {
console::write_line_to(strand, output, line_ending, line.as_bytes()).await
}
pub fn filter_preformatted<'v, 's>(
strand: &mut Strand<'v, 's>,
value: &str,
ansi: bool,
) -> Result<'v, 's, String> {
term::filter_preformatted(strand, value, ansi)
}
pub fn preformatted_text<'v, 's>(
strand: &mut Strand<'v, 's>,
value: &str,
out: Slot<'v, '_>,
) -> Result<'v, 's, ()> {
let global = strand.state::<Global<'v>>();
term::create_preformatted_text(strand, global, value, out)
}