Skip to content

Instantly share code, notes, and snippets.

@warmwaffles
Last active March 23, 2017 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warmwaffles/5164482 to your computer and use it in GitHub Desktop.
Save warmwaffles/5164482 to your computer and use it in GitHub Desktop.
A set of useful snippets that I find
# 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