Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A tty? function to use in scripts #911

Merged
merged 7 commits into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions planck-c/engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,8 @@ void *do_engine_init(void *data) {

register_global_function(ctx, "PLANCK_GETENV", function_getenv);

register_global_function(ctx, "PLANCK_ISATTY", function_isatty);

display_launch_timing("register fns");

// Monkey patch cljs.core/system-time to use Planck's high-res timer
Expand Down
10 changes: 10 additions & 0 deletions planck-c/functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1522,3 +1522,13 @@ JSValueRef function_getenv(JSContextRef ctx, JSObjectRef function, JSObjectRef t
}
return JSValueMakeNull(ctx);
}

JSValueRef function_isatty(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject,
size_t argc, const JSValueRef args[], JSValueRef *exception) {
if (argc == 1 && JSValueGetType(ctx, args[0]) == kJSTypeNumber) {
int fd = (int) JSValueToNumber(ctx, args[0], NULL);
int result = isatty(fd);
return JSValueMakeBoolean(ctx, (result != 0));
}
return JSValueMakeNull(ctx);
}
3 changes: 3 additions & 0 deletions planck-c/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,6 @@ JSValueRef function_signal_task_complete(JSContextRef ctx, JSObjectRef function,

JSValueRef function_getenv(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject,
size_t argc, const JSValueRef args[], JSValueRef *exception);

JSValueRef function_isatty(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject,
size_t argc, const JSValueRef args[], JSValueRef *exception);
8 changes: 8 additions & 0 deletions planck-cljs/src/planck/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,14 @@
:args (s/cat :s string?)
:ret any?)

(defn tty?
mfikes marked this conversation as resolved.
Show resolved Hide resolved
"Return true if the file descriptor numbered with fd-num is a tty"
[fd-num]
(js/PLANCK_ISATTY fd-num))

(s/fdef tty?
:args (s/cat :fd-num (s/and integer? pos?)))
radhikalism marked this conversation as resolved.
Show resolved Hide resolved

;; Ensure planck.io and planck.http are loaded so that their
;; facilities are available
(#'repl/side-load-ns 'planck.http)
Expand Down