You can capture stdin using system(), but you should be cautious as this whole
mechanism is highly OS-and-configuration-specific. R is not always running
connected to a terminal, and not all terminals respond to the same escape
commands.
On February 21, 2022 1:25:05 AM PST, Jan van der Laan <rhelp at
eoos.dds.nl> wrote:>
>
>I am trying to get the background colour of the terminal R is running
>in. There is a xterm control sequence for that: running the following in
>a suitable terminal returns the background colour:
>
>cat("\033]11;?\033\\")
>
>Except that the result is written to stdin and I can't seem to figure
>out how to get that into a variable in R.
>
>Following a shell script example from stackoverflow [1], I had a little
>bit of success using
>
>cat("\033]11;?\033\\")
>Sys.sleep(1)
>bg <- readLines(n=1)
>
>where one has to press an enter manually, but this is not something that
>can be put into a function.
>
>Wrapping that shell script into a system call works. That does introduce
>some dependencies, but on systems where this is relevant sh and sed are
>probably present anyway. But I still would prefers an R-solution.
>
>Does anyone know how one can get the background colour of the terminal R
>is running in?
>
>Suggestions other than using the xterm control sequence are, of course,
>also welcome. Perhaps a c-routine that can be wrapped into a Rcpp-call?
>
>Thanks for the help.
>
>Best,
>Jan
>
>
>
>[1]
>https://stackoverflow.com/questions/2507337/how-to-determine-a-terminals-background-color
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
--
Sent from my phone. Please excuse my brevity.