cli (version 1.0.1)

rule: Make a rule with one or two text labels

Description

The rule can include either a centered text label, or labels on the left and right side.

Usage

rule(left = "", center = "", right = "", line = 1, col = NULL,
  line_col = col, background_col = NULL, width = console_width())

Arguments

left

Label to show on the left. It interferes with the center label, only at most one of them can be present.

center

Label to show at the center. It interferes with the left and right labels.

right

Label to show on the right. It interferes with the center label, only at most one of them can be present.

line

The character or string that is used to draw the line. It can also 1 or 2, to request a single line (Unicode, if available), or a double line. Some strings are interpreted specially, see Line styles below.

col

Color of text, and default line color. Either a crayon style function or a color name that is passed to crayon::make_style().

line_col, background_col

Either a color name (used in crayon::make_style()), or a style function from crayon, to color the line and background.

width

Width of the rule. Defaults to the width option, see base::options().

Value

Character scalar, the rule.

Line styles

Some strings for the line argument are interpreted specially:

  • "single": (same as 1), a single line,

  • "double": (same as 2), a double line,

  • "bar1", "bar2", "bar3", etc., "bar8" uses varying height bars.

Details

To color the labels, use the functions from the crayon package directly, see examples below. To color the line, either use the crayon colors directly, or the line_col option.

Examples

Run this code
# NOT RUN {
## Simple rule
rule()

## Double rule
rule(line = 2)

## Bars
rule(line = "bar2")
rule(line = "bar5")

## Left label
rule(left = "Results")

## Centered label
rule(center = " * RESULTS * ")

## Colored labels
rule(center = crayon::red(" * RESULTS * "))

## Colored line
rule(center = crayon::red(" * RESULTS * "), line_col = "red")

## Custom line
rule(center = "TITLE", line = "~")

## More custom line
rule(center = "TITLE", line = crayon::blue("~-"))

## Even more custom line
rule(center = crayon::bgRed(" ", symbol$star, "TITLE",
  symbol$star, " "),
  line = "\u2582",
  line_col = "orange")
# }

Run the code above in your browser using DataLab