Utility functions for colorful console applications.
$ gem install colsole
- Print colored messages
- Color parts of a message
- Print neatly aligned status messages
- Word wrap with indentation consideration
See the Examples file for more.
An alternative to puts.
Leave a trailing space to keep the cursor at the same line
say "appears in " say "one line"
Embed color markers in the string:
say "!txtred!I am RED !txtgrn!I am GREEN"
say_status :status, "message" [, :color]
Print a message with a colored status
say_status :create, "perpetual energy"
You can provide a color in the regulat 6 letter code:
say_status :error, "does not compute", :txtred
word_wrap " string" [, length]
Wrap long lines while keeping words intact, and keeping indentation based on the leading spaces in your string:
say word_wrap(" one two three four five", 15) # output: # one two # three four # five
length is not provided,
word_wrap will attempt to determine it
automatically based on the width of the terminal.
Use resay after a space terminated "said" string to rewrite the line
say "downloading... " # long process here... resay "downloaded."
say! "anything to stderr"
Use say! to output to stderr with color markers:
say! "!txtred!Error!txtrst!: This just did not work"
Utility / Support Functions
Parses and returns a color-flagged string.
Respects pipe and auto terminates colored strings.
Call without text to see a list/demo of all available colors.
Returns true if we are running in an interactive terminal
Checks if the provided string is a command in the path.
Returns an array
[width, height] of the terminal, or the supplied
fallback_value if it is unable to detect.
Returns only the terminal width. This is a shortcut to