One of the goal of my forthcoming highlight package for R is to provide syntax highlighting based on evidence gathered from the output of the R parser directly into the R console (more on this later)
While writing the renderer targetting the console, I realized that support for colored text in the console is something that might be useful outside of the highlighter, and then decided to make it an independent package : xterm256
The idea is to use the The 256 color mode of xterm to wrap some text between escape sequences so that when it is cat to the console, the text appears with a background and/or a foreground color. Here is a screenshot from my console:
The package exposes only one function with three arguments: the style
function with arguments :
-
x
: the text we want to style -
bg
: the background color we want to use -
fg
: the foreground color we want to use
so if you want to print hello world in yellow with a black background, you can do:
cat( style( "hello world", bg = "black", fg = "yellow"), "\n" )