decorateString: Decorate a plain character string

Description Usage Arguments Value The DecoratedString S3 class Examples

View source: R/decorate-string.R

Description

Decorate a character string by adding a prefix and/or suffix to it, and by setting ANSI standardized SGR (Select Graphic Rendition) parameters for it. These parameters are always scoped to the decorated string.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
decorateString(
  string = character(1L),
  prefix = character(1L),
  suffix = character(1L),
  sgrSet = integer(),
  sgrReset = integer()
)

## S3 method for class 'DecoratedString'
print(x, ...)

Arguments

string

[character(1)]

A character string to be decorated. It cannot be empty.

prefix

[character(1)]

An optional character string to append to the beginning of string.

suffix

[character(1)]

An optional character string to append to the end of string.

sgrSet

[integer()]

An optional set of ANSI SGR parameters that adds one or more styles to string. Note that prefix and suffix also inherit these styles.

sgrReset

[integer()]

An optional set of ANSI SGR parameters that resets all styles previously set by SGR parameters passed to sgrSet.

The length of sgrSet and sgrReset must always match, even if this implies to duplicate certain parameters. Duplicates are handled internally.

x

[DecoratedString]

A DecoratedString object to print.

...

[any]

Currently ignored.

Value

A character(1) of S3 class DecoratedString.

The DecoratedString S3 class

This class does very little. It has a single print() method that conveys the object's internal value and its appearance when printed in a terminal.

Examples

1
2
3
4
5
6
7
8
## Create HTML tags.
decorateString("Here is some text.", "<p>", "</p>")

## Add ANSI styles, here bold text (SGR parameters 1 and 22).
decorateString("Here is some bold text.", sgrSet = 1L, sgrReset = 22L)

## All at once.
decorateString("Here is some bold text.", "<b>", "</b>", 1L, 22L)

jeanmathieupotvin/nanocli documentation built on Feb. 2, 2022, 11:30 p.m.