Created
December 22, 2019 16:48
-
-
Save alandipert/93c05e22c63538f17a805349bb4fb82e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env Rscript | |
library(chromote) | |
library(jsonlite) | |
muffle <- function(expr) { | |
if (.Platform$OS.type == "unix") { | |
sink("/dev/null") | |
} else { | |
sink("NUL") | |
} | |
tryCatch({ | |
force(expr) | |
invisible() | |
}, finally = sink()) | |
} | |
# TODO figure out how to use Log instead of deprecate Console | |
muffle({ | |
b <- ChromoteSession$new() | |
b$Page$navigate("file:///home/alan/github/alandipert/jacl/index.html") | |
b$Console$messageAdded(function (msg) { | |
cat(msg$message$text) | |
cat('\n> ') | |
}) | |
b$Console$enable() | |
}) | |
cat('> ') | |
f <- file("stdin") | |
open(f, blocking = TRUE) | |
while(isOpen(f)) { | |
ch <- readChar(f, 1) | |
json_str <- toJSON(ch, auto_unbox = TRUE) | |
code <- paste0('replInputStream.write(', json_str, ')') | |
b$Runtime$evaluate(code) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment