9.0
top
← prev up next →

colorizeπŸ”— i

(require colorize ) package: colorize
Colorize the output text of your console as you wish, source code.
NOTE: this is a exported version of ruby gem colorize.

1Procedure ReferenceπŸ”— i

procedure

( colorize str
color1
#:backgroundcolor2
#:stylestyle)string?
str:string?
color1:symbol?
color2:symbol?
style:symbol?
Colorize str with color1 as it’s foreground color, color2 as it’s background color, and style as the it’s style.

procedure

( colorize/argv sym)list?

sym:symbol?
show a list of value for the colorize’s possible arguments.

procedure

( colorized? str)boolean?

str:string?
check if #code{str} is colorized or not.

2Usage ExampleπŸ”— i

Examples:
> (colorize/argv 'color)

'(black

light-black

red

light-red

green

light-green

yellow

light-yellow

blue

light-blue

magenta

light-magenta

cyan

light-cyan

white

light-white

default)

> (colorize/argv 'style)

'(default bold italic underline blink swap hide)

> (colorize/argv 'all)

'((color

black

light-black

red

light-red

green

light-green

yellow

light-yellow

blue

light-blue

magenta

light-magenta

cyan

light-cyan

white

light-white

default)

(style default bold italic underline blink swap hide))

> (colorize "this is a raw red string"'red)

"\e[0;31;49mthis is a raw red string\e[0m"

;below is an example about how to display the the red string to your terminal
> (displayln (colorize "this is a raw red string"'red))

this is a raw red string

> (colorize "this is a raw red string on blue with underline"'red
#:background'blue
#:style'underline)

"\e[4;31;44mthis is a raw red string on blue with underline\e[0m"

;a practical usage example shown below:
> (string-join `("\n"
,(colorize "Happy"'light-red)
,(colorize "Hacking"'blue)
,(colorize (string-titlecase (or (getenv "USER")"user"))'green)
"-"
,(colorize "Racket"'cyan)
,(colorize "♥"'magenta)
,(colorize "You"'light-magenta)
,(colorize "!!!"'red)
"\n\n")
" ")

"\n \e[0;91;49mHappy\e[0m \e[0;34;49mHacking\e[0m \e[0;32;49mUser\e[0m - \e[0;36;49mRacket\e[0m \e[0;35;49m♥\e[0m \e[0;95;49mYou\e[0m \e[0;31;49m!!!\e[0m \n\n"

3Optional ColorizationπŸ”— i

parameter

( colorize? )boolean?

(colorize? boolean)void?
boolean:boolean?
Parameter used by colorize-optional .

True if the environment variable "NO_COLOR" is set and not equal to 0.

parameter

( no-color? )boolean?

(no-color? boolean)void?
boolean:boolean?
Parameter used by colorize-optional . Initial value of this parameter is equal to the value of NO_COLOR? ,

syntax

( colorize-optional strarg...)

If colorize? is #true and no-color? is #false then the str will be colorized with colorize .

arg... are the arguments passed down to colorize .

Example:
> (parameterize ([colorize? #false]
[no-color? #true])
(colorize-optional "Happy"'light-red))

"Happy"

top
← prev up next →

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /