Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/auser/colors
Add colors to your terminal output
https://github.com/auser/colors
Last synced: 15 days ago
JSON representation
Add colors to your terminal output
- Host: GitHub
- URL: https://github.com/auser/colors
- Owner: auser
- License: mit
- Created: 2009-06-16T01:54:39.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2009-07-23T21:14:27.000Z (over 15 years ago)
- Last Synced: 2024-11-11T12:06:17.661Z (2 months ago)
- Language: Ruby
- Homepage: http://poolpartyrb.com
- Size: 78.1 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
- License: LICENSE
Awesome Lists containing this project
README
= colors
Ever wondered how to get colors on your terminal? Now you can and ever so easily.
First, gotta thank the Passenger folks for the initial implementation of the brilliant idea.
== Usage
require "colors"
Colors.process("Text")
Any of these colors red, green, yellow, blue, purple, sea, white are available.You can add backgrounds to your color by passing bg= in a tag, for instance:
Colors.process("Blue text on yellow bg")
Finally, you can bold your text with , for instance:
Colors.process("BOLD")== Terminal color explanation
Non-printing escape sequences have to be enclosed in \[\033[ and \]. For colour escape sequences, they should also be followed by a lowercase m.
So for instance, if you wanted red text, for example, you would surround your text with:
\e[1m\e[31mRed text\e[0m\e[37m\e[40m
To see all the colors available on your terminal and as a quick and easy guide, run this in your shell:
#!/bin/bashT='text' # The test text
echo -e "\n 40m 41m 42m 43m\
44m 45m 46m 47m";for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \
'1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \
' 36m' '1;36m' ' 37m' '1;37m';
do FG=${FGs// /}
echo -en " $FGs \033[$FG $T "
for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
do echo -en "$EINS \033[$FG\033[$BG $T \033[0m";
done
echo;
done
echo== Copyright
Copyright (c) 2009 Ari Lerner. See LICENSE for details.