Crate flower_pot

Crate flower_pot 

Source
Expand description

Constants and simple functions for invoking ANSI control codes used for text-styling in terminals (including color codes). Does not support cursor movement or any other control codes.

Provides constant bindings for text-styling control codes like BOLD (= "\x1b[1m") and GREEN (= "\x1b[32m"):

use flower_pot::*;

println!("{GREEN}ok{RESET}");           // prints a green "ok"
println!("{BOLD}{RED}error!{RESET}");   // prints a bold, red "error!"
println!("{BLUE_BG}cloud{RESET}");      // prints white text on a blue background

// Note that you must print the RESET code after the end of
// the text you want styled, or else all text printed to the
// terminal after that point will also be styled that way,
// including text outputted by other programs.

…functions to succinctly invoke the 8-bit color palette:

use flower_pot::*;

// prints text in "palette-color #237" (often a shade of grey)
// with a background color of "palette-color #214" (often a
// shade of orange)

println!("{}{}example text{RESET}", color_256(237), color_256_bg(214));

…and ones that invoke truecolor functionality:

use flower_pot::*;

// prints text in RGB color [127, 45, 68] with a background
// color of RGB color [0, 255, 255]

println!("{}{}truecolor text{RESET}", truecolor(127, 45, 68), truecolor_bg(0, 255, 255));

The color_256, color_256_bg, truecolor, and truecolor_bg functions all return Strings.

Note that not all terminals support all of the codes defined in this library. The basic workflow of ANSI control codes is that a program outputs sequences of special characters defining what it wants (such as “make the following text bold” or “make the following text green” or “make the following text be the RGB color [127, 45, 68]”) to stdout, and then the terminal that the program is running in decides what to do with those characters. The codes themselves are reasonably well-standardized, but not every terminal understands all of them. Some terminals might ignore some codes, or might do weird things when you use them (such as displaying the text following the code incorrectly). This is a feature of the ANSI control code ecosystem, and not something a library can fix.

Once you’ve outputted a control code the terminal understands, all text that follows it is styled in the manner requested. If you want to go back to unstyled text, output the RESET code (\x1b[0m) or one of the more specific style-resetting codes such as NOT_UNDERLINED (\x1b[24m).

Poorly-supported codes (as reported by Wikipedia) are marked as such below.

Constants§

ALT_FONT_1
ALT_FONT_2
ALT_FONT_3
ALT_FONT_4
ALT_FONT_5
ALT_FONT_6
ALT_FONT_7
ALT_FONT_8
ALT_FONT_9
BLACK
BLACK_BG
BLUE
BLUE_BG
BOLD
BRIGHT_BLACK
BRIGHT_BLACK_BG
BRIGHT_BLUE
BRIGHT_BLUE_BG
BRIGHT_CYAN
BRIGHT_CYAN_BG
BRIGHT_GREEN
BRIGHT_GREEN_BG
BRIGHT_PURPLE
BRIGHT_PURPLE_BG
BRIGHT_RED
BRIGHT_RED_BG
BRIGHT_WHITE
BRIGHT_WHITE_BG
BRIGHT_YELLOW
BRIGHT_YELLOW_BG
CYAN
CYAN_BG
DEFAULT
DEFAULT_BG
DIM
DOUBLE_UNDERLINE
ENCIRCLED
FRAKTUR_FONT
FRAMED
GREEN
GREEN_BG
HIDDEN
INVERTED
ITALIC
NORMAL_INTENSITY
NOT_BLINKING
NOT_BOLD
NOT_FRAMED_NOT_ENCIRCLED
NOT_HIDDEN
NOT_INVERTED
NOT_ITALIC_NOT_BOLD
NOT_OVERLINED
NOT_STRIKETHROUGH
NOT_UNDERLINED
NO_PROPORTIONAL_SPACING
OVERLINE
PRIMARY_FONT
PROPORTIONAL_SPACING
PURPLE
PURPLE_BG
RAPID_BLINK
RED
RED_BG
RESET
SLOW_BLINK
STRIKETHROUGH
UNDERLINE
WHITE
WHITE_BG
YELLOW
YELLOW_BG

Functions§

color_256
color_256_bg
truecolor
truecolor_bg