lib/pry-theme.rb in pry-theme-0.0.7 vs lib/pry-theme.rb in pry-theme-0.0.8
- old
+ new
@@ -1,6 +1,7 @@
require 'pry-theme/version'
+require 'pry-theme/helper'
require 'pry-theme/commands'
require 'pry-theme/palette'
require 'pry-theme/theme'
require 'pry-theme/when_started_hook'
require 'pry-theme/uninstaller'
@@ -16,27 +17,35 @@
# The root path for PryTheme examples.
EXAMPLES_ROOT = File.join(ROOT, "..", "examples")
# The root path for the directory with configuration files for OS you're using.
CONFIG_DIR = case RbConfig::CONFIG["host_os"]
- when /darwin/
- File.join(ENV["HOME"], "Library", "Application Support")
- when /linux/
- ENV["XDG_CONFIG_HOME"]
when /mingw|mswin/
- ENV["APPDATA"]
+ File.join(ENV["APPDATA"], "pry-theme")
+ else
+ # /darwin|linux/ and friends.
+ File.join(ENV["HOME"], ".pry")
end
# Pry themes' directory.
- THEME_DIR = File.join(CONFIG_DIR, "pry-theme")
+ THEME_DIR = File.join(CONFIG_DIR, "themes")
+ # The name of the default theme of Pry Theme.
+ DEFAULT_THEME_NAME = "pry-classic"
+
def self.set_theme(theme_name)
- if theme = PryTheme.convert(theme_name)
+ theme = PryTheme.convert(theme_name)
+ if theme ||= PryTheme.convert(theme_name = DEFAULT_THEME_NAME)
::CodeRay::Encoders::Terminal::TOKEN_COLORS.merge!(theme)
+ @current_theme = theme_name
end
end
+ def self.current_theme
+ @current_theme
+ end
+
def self.convert(theme_name)
begin
theme = Theme.new(theme_name)
rescue NoThemeError => no_theme_error
warn no_theme_error
@@ -122,15 +131,15 @@
Formatting::BACKGROUNDS[$7]
end
# Uh oh :(
notation = if !color_fg
- "38;0;"
+ "38;0"
elsif palette.notation
palette.notation[0..-2]
else
- ""
+ nil
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,
@@ -142,10 +151,10 @@
Pry.output.puts "#{e}: wrong color value: `#{$2}`. Typo?"
end
def self.install_gem_hooks
Gem.post_uninstall do |u|
- Uninstaller.run(u)
+ Uninstaller.run(u) if u.spec.name == "pry-theme"
end
end
end