Skip to content

Commit f7985c2

Browse files
committed
Runtime: refactor isatty
1 parent b78067f commit f7985c2

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
@@ -419,6 +419,11 @@ class MlNodeFd extends MlFile {
419419
}
420420
}
421421

422+
isatty() {
423+
var tty = require("node:tty");
424+
return tty.isatty(this.fd) ? 1 : 0;
425+
}
426+
422427
length() {
423428
try {
424429
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)