From a5462f79ad72739b7a9fde7560f82adc5b4e92dd Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Wed, 18 Oct 2023 09:16:57 -0500 Subject: [PATCH] added: TTY bindings to wasi platform --- core/runtime/platform/wasi/platform.onyx | 4 +-- core/runtime/platform/wasi/wasix_misc.onyx | 31 ++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/core/runtime/platform/wasi/platform.onyx b/core/runtime/platform/wasi/platform.onyx index 3b8ac9a9..86bad6dc 100644 --- a/core/runtime/platform/wasi/platform.onyx +++ b/core/runtime/platform/wasi/platform.onyx @@ -39,6 +39,7 @@ Supports_Env_Vars :: true #if #defined(runtime.vars.WASIX) { Supports_Networking :: true Supports_Futexes :: true + Supports_TTY :: true #load "./wasix_defs" #load "./wasix_net" @@ -47,10 +48,9 @@ Supports_Env_Vars :: true } else { Supports_Networking :: false Supports_Futexes :: false + Supports_TTY :: false } -Supports_TTY :: false - __output_string :: (s: str) -> u32 { STDOUT_FILENO :: 1 diff --git a/core/runtime/platform/wasi/wasix_misc.onyx b/core/runtime/platform/wasi/wasix_misc.onyx index e0d2d72f..43e835b8 100644 --- a/core/runtime/platform/wasi/wasix_misc.onyx +++ b/core/runtime/platform/wasi/wasix_misc.onyx @@ -1,6 +1,7 @@ package runtime.platform use wasi +use core.os __futex_wait :: (addr: rawptr, expected: i32, timeout: i32) -> i32 { tm: wasi.OptionTimestamp; @@ -24,4 +25,34 @@ __futex_wake :: (addr: rawptr, maximum: i32) -> i32 { } return 1 if out else 0; +} + +__tty_get :: (tty: &os.TTY_State) { + state: wasi.TTY; + if wasi.tty_get(&state) != .Success do return; + + tty.rows = state.rows; + tty.cols = state.cols; + tty.stdin_is_tty = state.stdin_tty; + tty.stdout_is_tty = state.stdout_tty; + tty.stderr_is_tty = state.stderr_tty; + tty.echo = state.echo; + tty.input_buffered = state.line_buffered; + tty.input_linefeeds = state.line_feeds; +} + +__tty_set :: (tty: &os.TTY_State) -> bool { + state := wasi.TTY.{ + rows = tty.rows, + cols = tty.cols, + stdin_tty = tty.stdin_is_tty, + stdout_tty = tty.stdout_is_tty, + stderr_tty = tty.stderr_is_tty, + echo = tty.echo, + line_buffered = tty.input_buffered, + line_feeds = tty.input_linefeeds + }; + + wasi.tty_set(&state); + return true; } \ No newline at end of file -- 2.25.1