Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🖍️ R package for colored terminal output — now superseded by cli

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
NotificationsYou must be signed in to change notification settings

r-lib/crayon

Repository files navigation

Please usecli for new projects.

crayon is still supported and will receive important bug fixes,but no new features.



crayon


Stylish terminal output in R

Lifecycle: supersededCRAN RStudio mirror downloadsR-CMD-checkCodecov test coverage

With crayon it is easy to add color to terminal output, create styles for notes, warnings, errors; and combine styles.

ANSI color support is automatically detected and used. Crayon was largelyinspired bychalk.

Installation

Stable version:

install.packages("crayon")

Development version:

pak::pak("r-lib/crayon")

Styles

Crayon defines several styles that can be combined. Each style in the listhas a corresponding function with the same name.

General styles

  • reset
  • bold
  • blurred (usually calleddim, renamed to avoid name clash)
  • italic (not widely supported)
  • underline
  • inverse
  • hidden
  • strikethrough (not widely supported)

Text colors

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • silver (usually calledgray, renamed to avoid name clash)

Background colors

  • bgBlack
  • bgRed
  • bgGreen
  • bgYellow
  • bgBlue
  • bgMagenta
  • bgCyan
  • bgWhite

Screenshot on OSX

Usage

The styling functions take any number of character vectors as arguments,and they concatenate and style them:

library(crayon)cat(blue("Hello","world!\n"))

Crayon defines the%+% string concatenation operator to make it easyto assemble strings with different styles.

cat("... to highlight the" %+% red("search term") %+%" in a block of text\n")

Styles can be combined using the$ operator:

cat(yellow$bgMagenta$bold('Hello world!\n'))

Styles can also be nested, and then inner style takes precedence:

cat(green('I am a green line' %+%blue$underline$bold('with a blue substring') %+%' that becomes green again!\n'))

It is easy to define your own themes:

error<-red$boldwarn<-magenta$underlinenote<-cyancat(error("Error: subscript out of bounds!\n"))cat(warn("Warning: shorter argument was recycled.\n"))cat(note("Note: no such directory.\n"))

256 colors

Most modern terminals support the ANSI standard for 256 colors,and you can define new styles that make use of them. Themake_stylefunction defines a new style. It can handle R's built in color names(see the output ofcolors()) as well as RGB specifications via thergb() function. It automatically chooses the ANSI colors thatare closest to the specified R and RGB colors, and it also hasa fallback to terminals with 8 ANSI colors only.

ivory<- make_style("ivory")bgMaroon<- make_style("maroon",bg=TRUE)fancy<- combine_styles(ivory,bgMaroon)cat(fancy("This will have some fancy colors"),"\n")

License

MIT @ Gábor Csárdi

About

🖍️ R package for colored terminal output — now superseded by cli

Topics

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors18

Languages


[8]ページ先頭

©2009-2025 Movatter.jp