lib/pry-theme.rb in pry-theme-0.0.3.pre vs lib/pry-theme.rb in pry-theme-0.0.4.pre

- old
+ new

@@ -25,16 +25,24 @@ end # Pry themes' directory. THEME_DIR = File.join(CONFIG_DIR, "pry-theme") - Setter = proc do |theme_name| - ::CodeRay::Encoders::Terminal::TOKEN_COLORS.merge!(PryTheme.convert(theme_name)) + def self.set_theme(theme_name) + if theme = PryTheme.convert(theme_name) + ::CodeRay::Encoders::Terminal::TOKEN_COLORS.merge!(theme) + end end def self.convert(theme_name) - theme = Theme.new(theme_name) + begin + theme = Theme.new(theme_name) + rescue NoThemeError => no_theme_error + warn no_theme_error + return + end + palette = Palette.new(theme.color_depth) scheme = {} theme.scheme.each_pair do |k, v| if v.is_a?(Hash) @@ -102,12 +110,10 @@ color_bg = if m[:bg] Formatting::BACKGROUNDS[m[:bg]] end - notation = "38;5" if palette.color_depth == 256 - - [notation, color_fg, formatting, color_bg].flatten.compact.join(";") + [palette.notation[0..-2], color_fg, formatting, color_bg].flatten.compact.join(";") end end # Apply a theme of a user from their theme file.