lib/pry-theme.rb in pry-theme-0.0.4.pre vs lib/pry-theme.rb in pry-theme-0.0.5
- old
+ new
@@ -1,12 +1,14 @@
require 'pry-theme/version'
require 'pry-theme/commands'
require 'pry-theme/palette'
require 'pry-theme/theme'
require 'pry-theme/when_started_hook'
+require 'pry-theme/uninstaller'
+
require 'pry'
-require 'psych'
+require 'yaml'
module PryTheme
# The root path for PryTheme source codes.
ROOT = File.expand_path(File.dirname(__FILE__))
@@ -65,55 +67,65 @@
color_pattern = /
\A
# Matches "yellow".
(
- (?<fg>
+ (
\w+(0[1-9])?
)
\s?
)?
# Matches "yellow (bu)" or "(bu)".
(
\(
- (?<attrs>
+ (
d?b?u?i? # Order matters.
)
\)
)?
# Matches "yellow (bu) on red" or "on red".
(
\s?
on\s
- (?<bg>
+ (
[a-z]+(0[1-9])?
)
)?
\z
/x
- m = color.match(color_pattern)
- color_fg = if m[:fg]
- palette.colors.find do |color|
- color.human == m[:fg].to_sym
- end.term
- end
+ if color
+ m = color.match(color_pattern)
- formatting = if m[:attrs]
- formatting = m[:attrs].each_char.map do |ch|
- Formatting::ATTRIBUTES[ch]
+ color_fg = if $2
+ palette.colors.find do |color|
+ color.human == $2.to_sym
+ end.term
end
- end
- color_bg = if m[:bg]
- Formatting::BACKGROUNDS[m[:bg]]
- end
+ formatting = if $5
+ formatting = $5.each_char.map do |ch|
+ Formatting::ATTRIBUTES[ch]
+ end
+ end
- [palette.notation[0..-2], color_fg, formatting, color_bg].flatten.compact.join(";")
+ color_bg = if $7
+ Formatting::BACKGROUNDS[$7]
+ end
+
+ notation = palette.notation ? palette.notation[0..-2] : ""
+ [notation, color_fg, formatting, color_bg].flatten.compact.join(";")
+ end
+ end
+
+ def self.install_gem_hooks
+ Gem.post_uninstall do |u|
+ Uninstaller.run(u)
+ end
end
end
# Apply a theme of a user from their theme file.