Skip to content

Instantly share code, notes, and snippets.

@alandipert
Created December 22, 2019 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alandipert/93c05e22c63538f17a805349bb4fb82e to your computer and use it in GitHub Desktop.
Save alandipert/93c05e22c63538f17a805349bb4fb82e to your computer and use it in GitHub Desktop.
#!/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