Romain Francois, Professional R Enthusiast

To content | To menu | To search

Thursday, May 28 2009

xterm256 support in biocep

On this post, I presented the xterm256 package for R, allowing to have text in background and foreground color in the R console

The drawback of relying on xterm escape sequences is that the package needs to be used within a terminal that supports this escape sequence protocol (basically some linux consoles)

Here, I am proposing a patch to the biocep workbench that emulates support for these colors directly in the biocep R console, see the screenshot below:


Combined with the syntax highlighter I am working on, this allows syntax highlighting of R code (pretty close to the way R sees the code) directly in the code and is in my view both visually pleasing and very useful

The functionality requires minor modifications of the source code of biocep that I have written and I can send a patch to interested users, but I unfortunately cannot commit the modifications to the biocep project because it is read-only at the moment

Saturday, April 18 2009

Colorful terminal: the R package "xterm256"

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: lef-2.png

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" )