Skip to content

Commit ae4457e

Browse files
committed
Runtime: refactor isatty
1 parent 66b72d6 commit ae4457e

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

runtime/js/fs_node.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,11 @@ class MlNodeFd extends MlFile {
421421
}
422422
}
423423

424+
isatty() {
425+
var tty = require("node:tty");
426+
return tty.isatty(this.fd) ? 1 : 0;
427+
}
428+
424429
length() {
425430
try {
426431
return this.fs.fstatSync(this.fd).size;

runtime/js/unix.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,12 @@ function caml_unix_filedescr_of_fd(x) {
9898
}
9999

100100
//Provides: caml_unix_isatty
101-
//Requires: fs_node_supported, caml_unix_lookup_file
101+
//Requires: caml_unix_lookup_file
102102
//Alias: unix_isatty
103103
function caml_unix_isatty(fd) {
104-
if (fs_node_supported()) {
105-
var tty = require("node:tty");
106-
return tty.isatty(caml_unix_lookup_file(fd).fd) ? 1 : 0;
107-
} else {
108-
return 0;
109-
}
104+
var file = caml_unix_lookup_file(fd);
105+
if (!file.isatty) return 0;
106+
return file.isatty();
110107
}
111108

112109
//Provides: caml_unix_isatty

0 commit comments

Comments
 (0)