style {xterm256}R Documentation

Applies foreground and background color to text

Description

The function wraps the text x in the appropriate xterm 256 escape sequences to add backgorund and foreground color

Usage

style(x, fg = NULL, bg = NULL)

Arguments

x text to style
fg foreground color. See details below
bg background color. See details below

Details

The colors used for the bg or fg argument can be integers between 0 and 255, which are mapped to the xterm colors (see http://frexx.de/xterm-256-notes/) or strings.

In the case of strings, a mapping is made uwing either the named colors colors or colors in hex representation, such as the output of the rgb function. The closest color from the requested is used. Distance is evaluated in the RGB space using an euclidean distance. See dist

Value

The text x possibly wrapped in escape sequences

Author(s)

Romain Francois <francoisromain@free.fr>

References

http://frexx.de/xterm-256-notes/

Examples

        ## Not run: 
                text <- c( "liberté", "égalité", "fraternité" )
                bg   <- c("blue", "white", "red" )
                line <- paste( 
                        rep( " ", length.out = sum( nchar( text ) ) + 2 ), collapse = "")
                {
                                cat( style( line, bg = "gray95" ), "\n" )
                                cat( style( text, bg = bg), "\n", sep = " " )
                                cat( style( line, bg = "gray95" ), "\n" )
                }
                
                cat( style( "hex", bg = "#cccccc", fg = "#0000ff" ), 
                        "and", 
                        style( "rgb", bg = rgb( 1, 0, 0), fg = rgb(1,1,1) ), 
                        "are also supported", 
                        "\n" ) 
                
                if( require( pixmap ) ){
                         rlogo <- read.pnm( system.file( "rlogo.pnm", package= "xterm256") )
                         rlogo.rgb <- data.frame( 
                                red = as.integer(rlogo@red * 255), 
                                green =  as.integer(rlogo@green * 255), 
                                blue =  as.integer(rlogo@blue * 255) )  
                         cl <- closest(rlogo.rgb)
                         rlogo.text <- style( rep( " ", length(cl)), bg = cl )
                         dim( rlogo.text ) <- c( 38, 50 )
                         cat( apply( rlogo, 1, paste, collapse = ""), sep ="\n" )
                         
                }
                
                
        
## End(Not run)

[Package xterm256 version 0.0 Index]