0
0
Fork 0

Add method for create shell color commands

Now we create the color commands for the shell in a seperate method.
This keeps the constructor a bit cleaner. And so we can easily add more
color scales (and keep the over view in one!).
This commit is contained in:
Stormwind 2015-12-08 12:14:27 +01:00
parent 1fdfb77d64
commit cbf14cfa34
1 changed files with 27 additions and 18 deletions

View File

@ -29,28 +29,37 @@ module Rubella
super data, field_size super data, field_size
@symbols = Hash.new @symbols = Hash.new
@symbols["colored_fields"] = Array.new(10) do |i| @symbols["colored_fields"] = self.create_colors [
color = case i 35+196,
when 0 then 35+196 24+196,
when 1 then 29+196 18+196,
when 2 then 23+196 12+196,
when 3 then 17+196 6+196,
when 4 then 11+196 196,
when 5 then 5+196 160,
when 6 then 196 124,
when 7 then 160 88,
when 8 then 124 52
when 9 then 88 ]
end
"\033[38;5;"+color.to_s+";48;5;"+color.to_s+"m█\033[m"
end
self.used_symbols = "colored_fields" self.used_symbols = "colored_fields"
end end
# Gets a string of 8-bit color codes and translates them into color
# commands for the shell.
#
# @param codes Array
# @return Array
#
def create_colors codes
colors = []
codes.each do |code|
colors << "\033[38;5;"+code.to_s+";48;5;"+code.to_s+"m█\033[m"
end
colors
end
end end
end end
end end