fmt: Text formatting

View source: R/fmt.R

fmtR Documentation

Text formatting

Description

Formats text with specified color, styles, and background using ANSI escape codes or HTML, with support for plain text output.

Usage

fmt(
  x,
  col = NULL,
  bold = FALSE,
  italic = FALSE,
  underline = FALSE,
  thin = FALSE,
  muted = FALSE,
  bg = NULL,
  pad = 0L,
  output_type = c("ansi", "html", "plain")
)

Arguments

x

Character: Text to format.

col

Character: Color (hex code, named color, or NULL for no color).

bold

Logical: If TRUE, make text bold.

italic

Logical: If TRUE, make text italic.

underline

Logical: If TRUE, underline text.

thin

Logical: If TRUE, make text thin/light.

muted

Logical: If TRUE, make text muted/dimmed.

bg

Character: Background color (hex code, named color, or NULL).

pad

Integer: Number of spaces to pad before text.

output_type

Character: Output type ("ansi", "html", "plain").

Details

This function combines multiple formatting options into a single call, making it more efficient than nested function calls. It generates optimized ANSI escape sequences and clean HTML output.

Value

Character: Formatted text with specified styling.

Author(s)

EDG

Examples

# Simple color
fmt("Hello", col = "red")

# Bold red text
fmt("Error", col = "red", bold = TRUE)

# Multiple styles
fmt("Warning", col = "yellow", bold = TRUE, italic = TRUE)

# With background
fmt("Highlight", col = "white", bg = "blue", bold = TRUE)

rtemis.core documentation built on April 22, 2026, 1:11 a.m.