Skip to content

Commit e3b4b41

Browse files
oech3cakebaker
authored andcommitted
tty: Build tty.wasm
1 parent 282bcd8 commit e3b4b41

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

.github/workflows/wasi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
CARGO_TARGET_WASM32_WASIP1_RUNNER: wasmtime
3838
run: |
3939
# Get all utilities and exclude ones that don't compile for wasm32-wasip1
40-
EXCLUDE="dd|df|du|env|expr|mktemp|more|tac|test|tty"
40+
EXCLUDE="dd|df|du|env|expr|mktemp|more|tac|test"
4141
UTILS=$(./util/show-utils.sh | tr ' ' '\n' | grep -vE "^($EXCLUDE)$" | sed 's/^/-p uu_/' | tr '\n' ' ')
4242
cargo test --target wasm32-wasip1 --no-default-features $UTILS
4343
- name: Run integration tests via wasmtime

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ feat_wasm = [
235235
"true",
236236
"truncate",
237237
"tsort",
238+
"tty",
238239
"uname",
239240
"unexpand",
240241
"uniq",

src/uu/tty/src/tty.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
4949
set_exit_code(1);
5050
writeln!(stdout, "{}", translate!("tty-not-a-tty"))
5151
};
52-
52+
#[cfg(target_os = "wasi")]
53+
let write_result = if std::io::stdin().is_terminal() {
54+
// maximize compatibility
55+
writeln!(stdout, r"/dev/tty")
56+
} else {
57+
set_exit_code(1);
58+
writeln!(stdout, "{}", translate!("tty-not-a-tty"))
59+
};
5360
#[cfg(target_os = "windows")]
5461
let write_result = if std::io::stdin().is_terminal() {
5562
writeln!(stdout, r"\\.\CON")

0 commit comments

Comments
 (0)