lib/pry-theme.rb in pry-theme-0.0.5 vs lib/pry-theme.rb in pry-theme-0.0.6
- old
+ new
@@ -101,11 +101,17 @@
m = color.match(color_pattern)
color_fg = if $2
palette.colors.find do |color|
color.human == $2.to_sym
- end.term
+ end
+
+ if c
+ c.term
+ else
+ raise NoColorError unless c
+ end
end
formatting = if $5
formatting = $5.each_char.map do |ch|
Formatting::ATTRIBUTES[ch]
@@ -114,12 +120,27 @@
color_bg = if $7
Formatting::BACKGROUNDS[$7]
end
- notation = palette.notation ? palette.notation[0..-2] : ""
+ # Uh oh :(
+ notation = if !color_fg
+ "38;0;"
+ elsif palette.notation
+ palette.notation[0..-2]
+ else
+ ""
+ end
+
[notation, color_fg, formatting, color_bg].flatten.compact.join(";")
+ else
+ # In cases when a user decided not to provide an argument value in theme,
+ # use default color. Not handling this situation results in CodeRay's
+ # error ("can't convert nil into String" stuff).
+ "38;0;0"
end
+ rescue NoColorError => e
+ Pry.output.puts "#{e}: wrong color value: `#{$2}`. Typo?"
end
def self.install_gem_hooks
Gem.post_uninstall do |u|
Uninstaller.run(u)