combine_styles: Combine two or more ANSI styles

Description Usage Arguments Details Value Examples

View source: R/combine.r

Description

Combine two or more styles or style functions into a new style function that can be called on strings to style them.

Usage

1
2
3
4
combine_styles(...)

## S3 method for class 'crayon'
crayon$style

Arguments

...

The styles to combine. They will be applied from right to left.

crayon

A style function.

style

A style name that is included in names(styles()).

Details

It does not usually make sense to combine two foreground colors (or two background colors), because only the first one applied will be used.

It does make sense to combine different kind of styles, e.g. background color, foreground color, bold font.

The $ operator can also be used to combine styles. Not that the left hand side of $ is a style function, and the right hand side is the name of a style in styles().

Value

The combined style function.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## Use style names
alert <- combine_styles("bold", "red4", "bgCyan")
cat(alert("Warning!"), "\n")

## Or style functions
alert <- combine_styles(bold, red, bgCyan)
cat(alert("Warning!"), "\n")

## Combine a composite style
alert <- combine_styles(bold, combine_styles(red, bgCyan))
cat(alert("Warning!"), "\n")

## Shorter notation
alert <- bold $ red $ bgCyan
cat(alert("Warning!"), "\n")

Example output

Warning! 
Warning! 
Warning! 
Warning! 

crayon documentation built on May 2, 2019, 8:16 a.m.