pry-theme 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +1 -0
  3. data/.travis.yml +8 -1
  4. data/CHANGELOG.md +40 -0
  5. data/Gemfile +1 -1
  6. data/README.md +26 -48
  7. data/Rakefile +10 -1
  8. data/VERSION +1 -0
  9. data/lib/pry-theme/basic_editor.rb +116 -0
  10. data/lib/pry-theme/color.rb +431 -0
  11. data/lib/pry-theme/color_table.rb +39 -0
  12. data/lib/pry-theme/colors/color16.rb +35 -0
  13. data/lib/pry-theme/colors/color256.rb +30 -0
  14. data/lib/pry-theme/colors/color8.rb +31 -0
  15. data/lib/pry-theme/commands.rb +237 -275
  16. data/lib/pry-theme/declaration.rb +120 -0
  17. data/lib/pry-theme/definition.rb +111 -0
  18. data/lib/pry-theme/formattable.rb +26 -0
  19. data/lib/pry-theme/hex.rb +76 -0
  20. data/lib/pry-theme/preview.rb +74 -0
  21. data/lib/pry-theme/rgb.rb +238 -13
  22. data/lib/pry-theme/term.rb +66 -0
  23. data/lib/pry-theme/theme.rb +116 -26
  24. data/lib/pry-theme/theme_list.rb +52 -0
  25. data/lib/pry-theme/when_started_hook.rb +25 -27
  26. data/lib/pry-theme.rb +84 -158
  27. data/pry-theme.gemspec +14 -18
  28. data/spec/color_table.rb +53 -0
  29. data/spec/colors/color16_spec.rb +255 -0
  30. data/spec/colors/color256_spec.rb +323 -0
  31. data/spec/colors/color8_spec.rb +254 -0
  32. data/spec/commands_spec.rb +203 -0
  33. data/spec/helper.rb +16 -0
  34. data/spec/hex_spec.rb +52 -0
  35. data/spec/rgb_spec.rb +81 -0
  36. data/spec/term_spec.rb +23 -0
  37. data/spec/theme_spec.rb +486 -0
  38. data/themes/github.prytheme.rb +49 -0
  39. data/themes/monokai.prytheme.rb +48 -0
  40. data/themes/pry-classic-16.prytheme.rb +48 -0
  41. data/themes/pry-classic-256.prytheme.rb +48 -0
  42. data/themes/pry-classic-8.prytheme.rb +48 -0
  43. data/themes/pry-cold.prytheme.rb +49 -0
  44. data/themes/pry-love-16.prytheme.rb +48 -0
  45. data/themes/pry-love-8.prytheme.rb +48 -0
  46. data/themes/pry-modern-16.prytheme.rb +48 -0
  47. data/themes/pry-modern-256.prytheme.rb +48 -0
  48. data/themes/pry-modern-8.prytheme.rb +48 -0
  49. data/themes/pry-monochrome.prytheme.rb +32 -0
  50. data/themes/pry-siberia-16.prytheme.rb +48 -0
  51. data/themes/pry-siberia-8.prytheme.rb +48 -0
  52. data/themes/pry-tepid-16.prytheme.rb +48 -0
  53. data/themes/pry-tepid-8.prytheme.rb +48 -0
  54. data/themes/pry-zealand-16.prytheme.rb +48 -0
  55. data/themes/pry-zealand-8.prytheme.rb +49 -0
  56. data/themes/railscasts.prytheme.rb +50 -0
  57. data/themes/solarized.prytheme.rb +48 -0
  58. data/themes/tomorrow.prytheme.rb +48 -0
  59. data/themes/twilight.prytheme.rb +48 -0
  60. data/themes/vim-default.prytheme.rb +50 -0
  61. data/themes/vim-detailed.prytheme.rb +50 -0
  62. data/themes/zenburn.prytheme.rb +48 -0
  63. metadata +56 -41
  64. data/lib/pry-theme/color_converter.rb +0 -55
  65. data/lib/pry-theme/helper.rb +0 -87
  66. data/lib/pry-theme/palette.rb +0 -85
  67. data/lib/pry-theme/term_notation.rb +0 -17
  68. data/lib/pry-theme/version.rb +0 -3
  69. data/test/fixtures/pry-classic.prytheme +0 -38
  70. data/test/helper.rb +0 -56
  71. data/test/test_color_converter.rb +0 -38
  72. data/test/test_commands.rb +0 -55
  73. data/test/test_helper.rb +0 -45
  74. data/test/test_palette.rb +0 -11
  75. data/themes/github.prytheme +0 -43
  76. data/themes/monokai.prytheme +0 -42
  77. data/themes/pry-classic.prytheme +0 -43
  78. data/themes/pry-cold.prytheme +0 -43
  79. data/themes/pry-modern.prytheme +0 -42
  80. data/themes/railscasts.prytheme +0 -44
  81. data/themes/saturday.prytheme +0 -42
  82. data/themes/solarized.prytheme +0 -43
  83. data/themes/tomorrow.prytheme +0 -43
  84. data/themes/twilight.prytheme +0 -42
  85. data/themes/vim-default.prytheme +0 -42
  86. data/themes/vim-detailed.prytheme +0 -42
  87. data/themes/zenburn.prytheme +0 -43
@@ -0,0 +1,66 @@
1
+ module PryTheme
2
+ # @since 0.2.0
3
+ # @api private
4
+ #
5
+ # Represents a terminal colour (not ANSI). Checks whether a number fits in its
6
+ # colour model.
7
+ class TERM
8
+
9
+ # @return [Integer] the values are 8, 16 or 256
10
+ attr_reader :color_model
11
+
12
+ # @param [Integer] value
13
+ # @param [Integer] color_model
14
+ def initialize(value, color_model = 256)
15
+ validate_attrs(value, color_model)
16
+ @value = value
17
+ @color_model = color_model
18
+ end
19
+
20
+ # @return [String]
21
+ def inspect
22
+ "(TERM-#{ @color_model }: #{ @value })"
23
+ end
24
+
25
+ # @return [Integer]
26
+ def to_i
27
+ @value
28
+ end
29
+
30
+ private
31
+
32
+ # @param [Integer] value
33
+ # @param [Integer] color_model
34
+ # @raise [ArgumentError] if the +value+ isn't a valid Integer (not in
35
+ # +color_model+ range) or provided incorrect +color_model+
36
+ # @raise [TypeError] if the +value+ or the +color_model+ isn't an Integer
37
+ # at all
38
+ # @return [void]
39
+ def validate_attrs(value, color_model)
40
+ fixnums = value.is_a?(Fixnum) && color_model.is_a?(Fixnum)
41
+ correct_term =
42
+ if fixnums
43
+ case color_model
44
+ when 256 then value.between?(0, 255)
45
+ when 16 then value.between?(0, 15)
46
+ when 8 then value.between?(0, 7)
47
+ else raise ArgumentError,
48
+ 'invalid color model for PryTheme::TERM#new(): ' \
49
+ "\"#{ color_model }\""
50
+ end
51
+ end
52
+
53
+ return true if fixnums && correct_term
54
+
55
+ unless fixnums
56
+ raise TypeError, "can't convert #{ value.class } into PryTheme::TERM"
57
+ end
58
+
59
+ unless correct_term
60
+ raise ArgumentError,
61
+ %|invalid TERM number for PryTheme::TERM#new(): "#{ value }"|
62
+ end
63
+ end
64
+
65
+ end
66
+ end
@@ -1,44 +1,134 @@
1
1
  module PryTheme
2
+
3
+ # Raised when something goes wrong with Pry Theme themes. It's a general
4
+ # exception for everything that comes into collision in theme files.
5
+ ThemeError = Class.new(StandardError)
6
+
7
+ # @since 0.2.0
8
+ # @api private
9
+ # @see PryTheme::create
10
+ #
11
+ # Creates a new Pry Theme theme. This class is not meant for the direct
12
+ # instantiation. Use {PryTheme::create} instead.
2
13
  class Theme
3
14
 
4
- attr_reader :scheme, :author, :description, :color_depth, :version, :name
15
+ DEFAULT_CONFIG = {
16
+ :name => "prytheme-#{ rand(1_000_000_000) }",
17
+ :color_model => 256,
18
+ :author => 'Unknown Author',
19
+ :description => '',
20
+ }
5
21
 
6
- def initialize(theme_filename)
7
- theme_file = Helper.pathify_theme(theme_filename)
22
+ # Matches against valid theme name. It must start with a letter. The letter
23
+ # case is not important.
24
+ VALID_NAME = /\A[A-z][A-z0-9-]*\z/i
8
25
 
9
- if File.exists?(theme_file)
10
- theme = YAML.load_file(theme_file)
11
- else
12
- raise NoThemeError, "#{theme_filename}.prytheme doesn't exist"
13
- end
26
+ # @return [Theme::Definition] the heart of every theme: the colour
27
+ # definitions
28
+ attr_reader :definition
29
+
30
+ # @return [Boolean] whether this theme is a current theme
31
+ attr_reader :active
32
+ alias_method :active?, :active
33
+
34
+ # @see PryTheme::create
35
+ def initialize(config = {}, &block)
36
+ @config = DEFAULT_CONFIG.merge(config)
37
+ @authors = [{ :name => @config[:author] }]
38
+ @default_author = true
39
+ @active = false
40
+
41
+ validate_config
42
+
43
+ instance_eval(&block)
44
+ end
14
45
 
15
- meta = theme["meta"]
46
+ def author(options = nil)
47
+ if options
48
+ if options[:name].length > 32
49
+ raise PryTheme::ThemeError,
50
+ "author's name must be no longer than 32 characters"
51
+ end
16
52
 
17
- @name = meta["theme-name"]
18
- @version = meta["version"]
19
- @color_depth = meta["color-depth"].to_i
53
+ if @default_author
54
+ @default_author = false
55
+ @authors[0] = options
56
+ else
57
+ @authors << options
58
+ end
59
+ end
60
+ @authors
61
+ end
20
62
 
21
- # Forbid too long descriptions.
22
- if @description = meta["description"]
23
- if (size = @description.size) > 80
24
- raise ThemeDescriptionError, "Description of #{name} theme is too long (#{size}). Max size is 80 characters."
63
+ def description(text = nil)
64
+ if text
65
+ if text.length > 280
66
+ raise PryTheme::ThemeError,
67
+ "description must be no longer than 280 characters"
25
68
  end
69
+ @config[:description] = text
26
70
  end
71
+ @config[:description]
72
+ end
73
+
74
+ def define_theme(&block)
75
+ @definition = Definition.new(color_model, &block)
76
+ end
27
77
 
28
- @author = meta["author"]
29
- @scheme = theme["theme"]
78
+ def name
79
+ @config[:name]
30
80
  end
31
81
 
32
- def method_missing(method_name, *args, &block)
33
- if @scheme.has_key?(method_name.to_s)
34
- @scheme[method_name.to_s]
35
- else
36
- super
82
+ def color_model
83
+ @config[:color_model]
84
+ end
85
+
86
+ def disable
87
+ @active = false
88
+ end
89
+
90
+ def activate
91
+ ::CodeRay::Encoders::Terminal::TOKEN_COLORS.merge!(to_coderay)
92
+ @active = true
93
+ end
94
+
95
+ def to_coderay
96
+ {}.tap do |coderay|
97
+ @definition.class.instance_methods(false).each { |attr|
98
+ attr = attr.to_sym
99
+ val = @definition.__send__(attr) if @definition
100
+
101
+ unless val.kind_of?(Color)
102
+ coderay[attr] = {}
103
+ ivars = val.instance_variables.delete_if { |v| v =~ /color_model/}
104
+ ivars.each do |ivar|
105
+ coderay[attr][ivar.to_s.chomp('_')[1..-1].to_sym] =
106
+ val.instance_variable_get(ivar).to_ansi
107
+ end
108
+ else
109
+ coderay[attr.to_s.chomp('_').to_sym] = val.to_ansi
110
+ end
111
+ }
37
112
  end
38
113
  end
39
114
 
40
- end
115
+ private
41
116
 
42
- class NoThemeError < StandardError; end
43
- class ThemeDescriptionError < StandardError; end
117
+ def validate_config
118
+ if name !~ VALID_NAME
119
+ raise PryTheme::ThemeError, 'theme name must start with a letter'
120
+ end
121
+
122
+ if name.length > 18
123
+ raise PryTheme::ThemeError,
124
+ 'theme name must be no longer than 18 characters'
125
+ end
126
+
127
+ unless [256, 8, 16].include?(color_model)
128
+ raise PryTheme::ThemeError,
129
+ 'incorrect color model. Available values: 8, 16 or 256'
130
+ end
131
+ end
132
+
133
+ end
44
134
  end
@@ -0,0 +1,52 @@
1
+ module PryTheme
2
+ module ThemeList
3
+
4
+ extend self
5
+
6
+ def themes
7
+ @themes ||= []
8
+ end
9
+
10
+ def add_theme(theme)
11
+ themes << theme
12
+ end
13
+
14
+ def each(&block)
15
+ themes.each(&block)
16
+ end
17
+
18
+ def current_theme
19
+ themes.find { |theme| theme.active? }
20
+ end
21
+
22
+ def activate_theme(name)
23
+ theme = themes.find { |theme| theme.name == name }
24
+
25
+ if theme
26
+ current_theme.disable if current_theme
27
+ theme.activate
28
+ true
29
+ end
30
+ end
31
+
32
+ def activate_theme_intelligently
33
+ if Pry::Helpers::BaseHelpers.windows?
34
+ activate_theme('pry-classic-16')
35
+ else
36
+ case PryTheme.tput_colors
37
+ when 256 then activate_theme('pry-classic-256')
38
+ when 16 then activate_theme('pry-classic-16')
39
+ else activate_theme('pry-classic-8')
40
+ end
41
+ end
42
+ end
43
+
44
+ def reload_theme(name, file)
45
+ @themes.delete_if { |theme| theme.name == name }
46
+ load file
47
+ activate_theme(name)
48
+ true
49
+ end
50
+
51
+ end
52
+ end
@@ -1,38 +1,36 @@
1
- require 'fileutils'
2
-
3
1
  module PryTheme
4
2
  class WhenStartedHook
5
- include PryTheme::Helper
6
-
7
3
  def call(target, options, _pry_)
8
- FileUtils.mkdir_p(THEME_DIR) unless File.exists?(THEME_DIR)
4
+ recreate_user_themes_from_default_ones
5
+ load_themes
6
+
7
+ if Pry.config.theme
8
+ ThemeList.activate_theme(Pry.config.theme)
9
+ else
10
+ ThemeList.activate_theme_intelligently
11
+ end
12
+ end
13
+
14
+ private
9
15
 
10
- example_themes.each do |theme|
11
- # Copy a default theme to theme directory if it isn't there yet. Update
12
- # an installed theme if a theme from the gem has a more recent version
13
- # (version determines by theme's meta information).
14
- if File.exists?(local_theme(theme))
15
- new_version = theme_file_version(default_theme(theme))
16
- old_version = theme_file_version(local_theme(theme))
16
+ # Copy a default theme to theme directory, but only if it isn't there yet.
17
+ def recreate_user_themes_from_default_ones
18
+ FileUtils.mkdir_p(USER_THEMES_DIR) unless File.exists?(USER_THEMES_DIR)
19
+ default_themes = Dir.entries(DEF_THEMES_DIR) - %w{. ..}
17
20
 
18
- if new_version > old_version
19
- FileUtils.cp(default_theme(theme), THEME_DIR)
20
- end
21
- else
22
- FileUtils.cp(default_theme(theme), THEME_DIR)
21
+ default_themes.each do |theme|
22
+ user_theme_path = File.join(USER_THEMES_DIR, theme)
23
+ unless File.exists?(user_theme_path)
24
+ def_theme_path = File.join(DEF_THEMES_DIR, theme)
25
+ FileUtils.cp(def_theme_path, USER_THEMES_DIR)
23
26
  end
24
27
  end
28
+ end
25
29
 
26
- if Pry.config.theme
27
- if Helper.installed?(Pry.config.theme)
28
- PryTheme.set_theme(Pry.config.theme)
29
- else
30
- _pry_.output.puts %{Can't find "#{ Pry.config.theme }" theme. Using "#{ DEFAULT_THEME_NAME }"}
31
- PryTheme.set_theme(DEFAULT_THEME_NAME)
32
- end
33
- else
34
- _pry_.output.puts %{Can't find `Pry.config.theme` definition in your `~/.pryrc`.\nUsing "#{ DEFAULT_THEME_NAME }" theme now.}
35
- PryTheme.set_theme(DEFAULT_THEME_NAME)
30
+ def load_themes
31
+ user_themes = Dir[File.join(USER_THEMES_DIR, '*' + PT_EXT)]
32
+ user_themes.each do |theme|
33
+ require theme
36
34
  end
37
35
  end
38
36
 
data/lib/pry-theme.rb CHANGED
@@ -1,174 +1,100 @@
1
- require 'pry-theme/version'
2
- require 'pry-theme/helper'
3
- require 'pry-theme/palette'
4
- require 'pry-theme/term_notation'
5
- require 'pry-theme/theme'
1
+ require 'fileutils'
2
+
3
+ require 'pry-theme/theme_list'
4
+ require 'pry-theme/when_started_hook'
5
+ require 'pry-theme/hex'
6
6
  require 'pry-theme/rgb'
7
- require 'pry-theme/color_converter'
7
+ require 'pry-theme/term'
8
+ require 'pry-theme/formattable'
9
+ require 'pry-theme/declaration'
10
+ require 'pry-theme/definition'
11
+ require 'pry-theme/theme'
12
+ require 'pry-theme/preview'
13
+ require 'pry-theme/color'
14
+ require 'pry-theme/color_table'
15
+ require 'pry-theme/basic_editor'
8
16
  require 'pry-theme/commands'
9
- require 'pry-theme/when_started_hook'
10
-
11
- require 'yaml'
12
17
 
13
18
  module PryTheme
14
19
 
15
- # The root path for PryTheme source codes.
16
- ROOT = File.expand_path(File.dirname(__FILE__))
17
-
18
- # The root path for PryTheme examples.
19
- EXAMPLES_ROOT = File.join(ROOT, "..", "themes")
20
-
21
- # The root path for the directory with configuration files for OS you're using.
22
- CONFIG_DIR = case RbConfig::CONFIG["host_os"]
23
- when /mingw|mswin/
24
- File.join(ENV["APPDATA"], "pry-theme")
25
- else
26
- # /darwin|linux/ and friends.
27
- File.join(ENV["HOME"], ".pry")
28
- end
29
-
30
- # Pry themes' directory.
31
- THEME_DIR = File.join(CONFIG_DIR, "themes")
32
-
33
- # The name of the default theme of Pry Theme.
34
- DEFAULT_THEME_NAME = "pry-classic"
35
-
36
- # The URI for GitHub API link to Pry Theme Collection contents.
37
- COLLECTION = "https://api.github.com/repos/kyrylo/pry-theme-collection/contents"
38
-
39
- def self.set_theme(theme_name)
40
- return unless theme = PryTheme.convert(theme_name)
41
- ::CodeRay::Encoders::Terminal::TOKEN_COLORS.merge!(theme)
42
- @current_theme = theme_name
43
- end
44
-
45
- def self.current_theme
46
- @current_theme
47
- end
48
-
49
- def self.convert(theme_name)
50
- begin
51
- theme = Theme.new(theme_name)
52
- rescue NoThemeError => no_theme_error
53
- warn no_theme_error
54
- return
55
- rescue ThemeDescriptionError => long_descr
56
- Pry.output.puts long_descr
57
- Pry.output.puts "Using #{DEFAULT_THEME_NAME} theme."
58
- return
59
- end
60
-
61
- palette = Palette.new(theme.color_depth)
62
- scheme = {}
20
+ # The VERSION file must be in the root directory of the library.
21
+ VERSION_FILE = File.expand_path('../../VERSION', __FILE__)
63
22
 
64
- theme.scheme.each_pair do |k, v|
65
- if v.is_a?(Hash)
66
- nested_h = {}
23
+ VERSION = File.exist?(VERSION_FILE) ?
24
+ File.read(VERSION_FILE).chomp : '(could not find VERSION file)'
67
25
 
68
- v.each_pair do |nested_k, nested_v|
69
- nested_h[nested_k.to_sym] = color_to_term(nested_v, palette)
70
- end
26
+ # The root path of Pry Theme source code.
27
+ ROOT = File.expand_path(File.dirname(__FILE__))
71
28
 
72
- scheme[k.to_sym] = nested_h
73
- else
74
- scheme[k.to_sym] = color_to_term(v, palette)
75
- end
29
+ # The path of the directory with Pry configuration files.
30
+ CONFIG_DIR = File.join(ENV['HOME'], '.pry')
31
+
32
+ # The path of the default Pry Theme themes.
33
+ DEF_THEMES_DIR = File.join(ROOT, '..', 'themes')
34
+
35
+ # The path where the user should keep their themes.
36
+ USER_THEMES_DIR = File.join(CONFIG_DIR, 'themes')
37
+
38
+ # Every Pry Theme file must end with this extension.
39
+ PT_EXT = '.prytheme.rb'
40
+
41
+ # Pry Theme Collection.
42
+ PTC = 'https://api.github.com/repos/kyrylo/pry-theme-collection/contents/'
43
+
44
+ # The default URL shortener (used for listing themes from PTC).
45
+ SHORTENER = 'http://is.gd/create.php?format=simple&url='
46
+
47
+ # @since 0.2.0
48
+ # @api public
49
+ class << self
50
+ # @see https://github.com/kyrylo/pry-theme/wiki/Creating-a-New-Theme
51
+ #
52
+ # Creates a new Pry Theme theme.
53
+ #
54
+ # @example
55
+ # my_theme = PryTheme.create name: 'my-theme', color_model: 8 do
56
+ # author name: 'John Doe', email: 'johndoe@example.com'
57
+ # description 'My first theme'
58
+ #
59
+ # define_theme do
60
+ # class_variable 'red'
61
+ # integer 'black'
62
+ # method 'white', 'red'
63
+ # symbol bg: 'yellow'
64
+ #
65
+ # string do
66
+ # content 'blue', 'black'
67
+ # end
68
+ # end
69
+ # end
70
+ #
71
+ # my_theme.definition.class_variable.foreground(true) #=> "red"
72
+ # my_theme.definition.string.content.background(true) #=> "black"
73
+ #
74
+ # @param [Hash] config
75
+ # @option config [String] :name ('prytheme-\d+') The name of the theme. It
76
+ # must be no longer than 18 characters
77
+ # @option config [Integer] :color_model (256) The number of colours
78
+ # available in the theme that is being created. Besides 256, valid
79
+ # arguments are `8` and `16`
80
+ def create(config = {}, &block)
81
+ Theme.new(config, &block)
76
82
  end
77
83
 
78
- scheme
79
- end
80
-
81
- def self.color_to_term(color, palette)
82
- color_pattern = /
83
- \A
84
-
85
- # Matches "yellow".
86
- (
87
- (
88
- \w+(0[1-9])?
89
- )
90
- \s?
91
- )?
92
-
93
- # Matches "yellow (bu)" or "(bu)".
94
- (
95
- \(
96
- (
97
- d?b?u?i? # Order matters.
98
- )
99
- \)
100
- )?
101
-
102
-
103
- # Matches "yellow (bu) on red" or "on red".
104
- (
105
- \s?
106
- on\s
107
- (
108
- \w+(0[1-9])?
109
- )
110
- )?
111
-
112
- \z
113
- /x
114
-
115
- if color
116
- m = color.match(color_pattern)
117
-
118
- color_fg = find_color($2, palette) { |c| c.term }
119
-
120
- formatting = if $5
121
- formatting = $5.each_char.map do |ch|
122
- Formatting::ATTRIBUTES[ch]
123
- end
124
- end
125
-
126
- color_bg = find_color($7, palette) do |c|
127
- if palette.color_depth == 256
128
- "#{ TermNotation::BACKGROUND256 }#{c.term}"
129
- else
130
- Formatting::BACKGROUNDS[c.human.to_s]
131
- end
132
- end
133
-
134
- # Uh oh :(
135
- notation = if !color_fg
136
- TermNotation::NO_FOREGROUND
137
- elsif palette.notation
138
- palette.notation[0..-2]
139
- else
140
- nil
141
- end
142
-
143
- [notation, color_fg, formatting, color_bg].flatten.compact.join(";")
144
- else
145
- # In cases when a user decided not to provide an argument value in theme,
146
- # use default color. Not handling this situation results in CodeRay's
147
- # error ("can't convert nil into String" stuff).
148
- TermNotation::EMPTY
84
+ # @return [Integer] the number of supported terminal colours. Always equal
85
+ # to 16 on Windows.
86
+ def tput_colors
87
+ `tput colors`.to_i
88
+ rescue Errno::ENOENT
89
+ 16
149
90
  end
150
- rescue NoColorError => e
151
- Pry.output.puts "#{e}: wrong color value: `#{color}`. Typo?"
152
- end
153
-
154
- def self.find_color(color, palette, &block)
155
- if color
156
- c = palette.colors.find do |palette_color|
157
- palette_color.human == color.to_sym
158
- end
159
91
 
160
- if c
161
- block.call(c)
162
- else
163
- raise NoColorError
164
- end
92
+ # @param [Integer] color
93
+ # @return [Class] the class, which corresponds to the given +color+
94
+ def color_const(color)
95
+ const_get(:"Color#{ color }")
165
96
  end
166
97
  end
167
98
 
99
+ Pry.config.hooks.add_hook(:when_started, :pry_theme, WhenStartedHook.new)
168
100
  end
169
-
170
- # Apply a theme of a user from their theme file.
171
- Pry.config.hooks.add_hook(:when_started, :apply_user_theme, PryTheme::WhenStartedHook.new)
172
-
173
- # Import the PryTheme commands.
174
- Pry.config.commands.import PryTheme::Commands
data/pry-theme.gemspec CHANGED
@@ -1,24 +1,20 @@
1
- unless defined? PryTheme::VERSION
2
- require File.expand_path('../lib/pry-theme/version', __FILE__)
3
- end
4
-
5
1
  Gem::Specification.new do |s|
6
- s.name = "pry-theme"
7
- s.version = PryTheme::VERSION
2
+ s.name = 'pry-theme'
3
+ s.version = File.read('VERSION')
8
4
  s.date = Time.now.strftime('%Y-%m-%d')
9
- s.summary = "Easy way to customize your Pry colors"
10
- s.description = "The plugin enables color theme support for your Pry. No more .pryrc bustling."
11
- s.author = "Kyrylo Silin"
12
- s.email = "kyrylosilin@gmail.com"
13
- s.homepage = "https://github.com/kyrylo/pry-theme"
14
- s.licenses = "zlib"
5
+ s.summary = 'An easy way to customize Pry colors via theme files'
6
+ s.description = 'The plugin enables color theme support for Pry.'
7
+ s.author = 'Kyrylo Silin'
8
+ s.email = 'kyrylosilin@gmail.com'
9
+ s.homepage = 'https://github.com/kyrylo/pry-theme'
10
+ s.licenses = 'zlib'
15
11
 
16
- s.require_path = "lib"
17
- s.files = `git ls-files`.split "\n"
12
+ s.require_path = 'lib'
13
+ s.files = `git ls-files`.split("\n")
18
14
 
19
- s.add_runtime_dependency "json"
15
+ s.add_runtime_dependency 'json'
20
16
 
21
- s.add_development_dependency "bacon"
22
- s.add_development_dependency "rake"
23
- s.add_development_dependency "pry"
17
+ s.add_development_dependency 'bacon'
18
+ s.add_development_dependency 'rake'
19
+ s.add_development_dependency 'pry'
24
20
  end