Last active
March 23, 2017 17:40
-
-
Save warmwaffles/5164482 to your computer and use it in GitHub Desktop.
A set of useful snippets that I find
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Outputs text with the specified format | |
# | |
# @param [String] text what you want to say | |
# @param [Hash] options | |
# | |
# @return [void] | |
def say text, options={} | |
color = options[:color] || :white | |
weight = options[:weight] || :normal | |
background = options[:background] || :none | |
c = { black: 30, red: 31, green: 32, yellow: 33, blue: 34, purple: 34, cyan: 36, white: 37 }.fetch(color, 37) | |
w = { normal: 0, bold: 1, underline: 4 }.fetch(weight, 0) | |
bg = { black: 40, red: 41, green: 42, yellow: 43, blue: 44, purple: 45, cyan: 46, white: 47 }.fetch(background, nil) | |
if bg | |
puts "\e[%d;%dm\e[%dm%s\e[0m\e[0m" % [w, c, bg, text] | |
else | |
puts "\e[%d;%dm%s\e[0m" % [w, c, text] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment