A very simple DSL to generate colored strings to use in *nix-like OS's terminals
gem install geek_painter
Generate a valid string to be used as a prompt string (PS1)
Check this link to see the available variables: www.ibm.com/developerworks/linux/library/l-tip-prompt/
Put the following lines in a file (ie. ~/.my_scripts/my_prompt.rb or whatever you want) master_piece = GeekPainter.paint do label “[”.in(:brown).on :blue label “\u”.in :red label “:”.in :yellow label “\h”.in :red label “] ”.in(:magenta).on :red label “\W ”.in :default label “$(__git_ps1)”.in :yellow <= This might not work if you don't have git installed end puts master_piece.prompt Now open your ~/.bash_profile, ~/.bashrc or ~/.profile and put this on it
Open a console and you'll see your new shiny and colorful prompt.
If you just want to copy and paste the string run the same script like this in a Ruby terminal (irb):
Copy the resulting string and paste it in your PS1.
Generate a valid string to be used as colored text in the terminal
my_text = GeekPainter.paint do label “Hello, ”.in(:red).on(:blue) label “World.”.in(:yellow).on(:cyan) end puts my_text.raw_text
In this case “raw_text” will return the following string: e[1;31;44mHello, e[1;33;46mWorld.e[0m
Copy it and… $ printf “e[1;31;44mHello, e[1;33;46mWorld.e[0m” To print the colored text in the Interactive Ruby console (IRb) do the following
puts my_text.text # it will print the colored text itself not the escaped string
Foreground (These colors can be used as a parameter in the “in” method)
:black :dark_gray :light_gray :light_red :red :light_green :green :yellow :brown :light_blue :blue :light_magenta :magenta :light_cyan :cyan :white :default
Background (These colors can be used as a parameter in the “on” method)
:black :red :green :brown :blue :magenta :cyan :white :default
Note on Patches/Pull Requests
Fork the project.
Make your feature addition or bug fix.
Add tests for it. This is important so I don't break it in a future version unintentionally.
Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
Send me a pull request. Bonus points for topic branches.
Copyright © 2010 Rafael Magaña. See LICENSE for details.