Created
January 21, 2012 14:06
-
-
Save no6v/1652872 to your computer and use it in GitHub Desktop.
Customized colors for names and hashtags
This file contains hidden or 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
# encoding: UTF-8 | |
# ### Customized colors for names and hashtags | |
# | |
# # See Earthquake.config[:color] for available color names. | |
# # Only which looks like a color name is the name of the color :). | |
# | |
# ⚡ :eval config[:color] | |
# | |
# # Colors also can be specified by a single number. | |
# # Using colors for background (ex. 44) will not work well on search results. | |
# | |
# # ~/.earthquake/config | |
# Earthquake.config[:name_colors] = { | |
# earthquakegem: :darkpurple, | |
# jugyo: 31, | |
# no6v: 44, # it's ok for me to mark my tweet | |
# } | |
module Earthquake::Output | |
def color_of_with_name_colors(screen_name) | |
name = screen_name.delete("^0-9A-Za-z_") | |
if color = config[:name_colors][name.to_sym] | |
config[:color][color] || color | |
else | |
color_of_without_name_colors(screen_name) | |
end | |
end | |
alias_method_chain :color_of, :name_colors | |
end | |
Earthquake.init do | |
config[:color].reverse_update({ | |
darkred: 31, | |
darkgreen: 32, | |
darkyellow: 33, | |
darkblue: 34, | |
darkpurple: 35, | |
darkcyan: 36, | |
red: 91, | |
green: 92, | |
yellow: 93, | |
blue: 94, | |
purple: 95, | |
cyan: 96, | |
}) | |
config[:name_colors] ||= {} | |
@name_colors ||= {} | |
config[:name_colors].update(@name_colors) | |
command %r!^:name_color (\w+) (\w+)$!, as: :name_color do |m| | |
name, color = m.captures | |
name = name.to_sym | |
color = config[:color].fetch(color.to_sym, color.to_i) | |
@name_colors.update(name => color) | |
end | |
help(:name_color, "change the color for name (volatile)", | |
["⚡ :name_color no6v darkblue", "⚡ :name_color no6v 40"].join("\n")) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment