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
@@ -1,328 +1,290 @@
1
- module PryTheme
2
- Commands = Pry::CommandSet.new do
3
-
4
- create_command "pry-theme", "Manage your Pry themes." do
5
- include PryTheme::Helper
6
-
7
- banner <<-BANNER
8
- Usage: pry-theme [OPTIONS] [--help]
9
-
10
- Change your theme on the fly (for one session).
11
-
12
- pry-theme pry-modern
13
-
14
- Show all themes from Pry Theme Collection.
15
-
16
- pry-theme -r
17
-
18
- Install a theme from Pry Theme Collection.
19
-
20
- pry-theme -i pry-classic
1
+ # coding: utf-8
21
2
 
22
- Test your current color theme.
23
-
24
- pry-theme -t
25
-
26
- Wiki: https://github.com/kyrylo/pry-theme/wiki/Pry-Theme-CLI
27
- Cheatsheet: https://github.com/kyrylo/pry-theme/wiki/Pry-Theme-Cheatsheet
28
- BANNER
29
-
30
- def options(opt)
31
- opt.on :a, "all-colors", "Show all available 8/256 colors."
32
- opt.on :c, "color", "Show information about a specific color (256)."
33
- opt.on :t, "test", "Test your current theme", :argument => false
34
- opt.on :e, "edit", "Edit or create a theme"
35
- opt.on :l, "list", "Show a list of installed themes", :argument => false
36
- opt.on :r, "remote-list", "Show a list of themes from Pry Theme Collection", :argument => false
37
- opt.on :i, "install", "Install a theme from Pry Theme Collection"
38
- end
39
-
40
- def process
41
- if opts.a?
42
- show_palette_colors
43
- elsif opts.c?
44
- show_specific_color
45
- elsif opts.t?
46
- test_theme
47
- elsif opts.e?
48
- edit_theme
49
- elsif opts.l?
50
- show_list
51
- elsif opts.r?
52
- show_remote_list
53
- elsif opts.i?
54
- install_theme
55
- elsif args[0] =~ /\A\w+-?\w+\z/
56
- switch_to_theme
57
- elsif args.empty?
58
- output.puts "Current theme: #{PryTheme.current_theme}"
3
+ module PryTheme
4
+ Command = Class.new
5
+
6
+ class Command::PryTheme < Pry::ClassCommand
7
+ include Pry::Helpers::BaseHelpers
8
+ include Pry::Helpers::CommandHelpers
9
+
10
+ match 'pry-theme'
11
+ description 'Manage your Pry themes.'
12
+
13
+ banner <<-'BANNER'
14
+ Usage: pry-theme [OPTIONS] [--help]
15
+
16
+ The command comes from `pry-theme` plugin. It enbales color theme support for your
17
+ Pry. Set up your favorite theme in `~/.pryrc` config file. For example, if you
18
+ enjoy Zenburn theme, add the following line: `Pry.config.theme = 'zenburn'`.
19
+
20
+ You can create your own themes with help of `edit` subcommand. More information
21
+ can be found in the appropriate arcticle: http://is.gd/YPuTjM
22
+ Tokens cheatsheet might come in handy, too: http://is.gd/D7GoVe
23
+
24
+ pry-theme try pry-modern-256 # changes theme (lasts for current session only)
25
+ pry-theme current # shows currently active theme name
26
+ pry-theme current --colors # tests colors from the current theme
27
+ pry-theme list # shows all installed themes as colorful snippets
28
+ pry-theme list --remote # shows all themes from Pry Theme Collection
29
+ pry-theme colors # shows the list of all color names
30
+ pry-theme colors --model 8 # shows the list of colors according to 8 color model
31
+ pry-theme install autumn # installs a theme from Pry Theme Collection
32
+ pry-theme uninstall monokai # uninstalls a theme
33
+ pry-theme convert -m 16 -t 3 # converts a single color to a term color
34
+ pry-theme edit zenburn # opens Zenburn theme in `Pry.editor`
35
+ BANNER
36
+
37
+ def def_list(cmd)
38
+ cmd.command :list do |opt|
39
+ opt.description 'Show a list of all installed themes'
40
+
41
+ opt.on :r, :remote, 'Show a list of all themes from Pry Theme Collection'
42
+
43
+ opt.run do |opts, args|
44
+ opts.present?(:r) ? show_remote_list : show_local_list
59
45
  end
60
- rescue NoPaletteError => no_palette_error
61
- warn no_palette_error
62
- rescue NoColorError => no_color_error
63
- warn no_color_error
64
- end
65
-
66
- private
67
-
68
- def switch_to_theme
69
- PryTheme.set_theme(args[0].strip) and
70
- output.puts "Using #{ args[0] } theme"
71
46
  end
47
+ end
72
48
 
73
- def show_palette_colors
74
- lputs in_columns(Palette.new(args[0]).to_a), output
75
- end
49
+ def def_colors(cmd)
50
+ cmd.command :colors do |opt|
51
+ opt.description 'Show all available colors'
76
52
 
77
- def in_columns(list, cols=3)
78
- color_table = []
53
+ opt.on :m, :model=, 'Display colors according to the given color model'
79
54
 
80
- list.each_slice(cols) do |slice|
81
- slice.each do |c|
82
- color = c.scan(/(\e\[[\d;]+m)(\w+)(\e\[0m)(:)(\e\[[\d;]+m)(\w+)(\e\[0m)/).flatten
83
- color[1] = color[1].ljust(3)
84
- color[-2] = color[-2].ljust(22)
85
- color_table << color
55
+ opt.run do |opts, args|
56
+ if opts.present?(:m)
57
+ display_colors(opts[:m].to_i)
58
+ else
59
+ display_colors(PryTheme.tput_colors)
86
60
  end
87
- color_table << "\n"
88
61
  end
89
- color_table.join
90
62
  end
63
+ end
91
64
 
92
- def show_specific_color
93
- c = args[0]
65
+ def def_try(cmd)
66
+ cmd.command :try do |opt|
67
+ opt.description 'Change theme on the fly (for the current session only)'
94
68
 
95
- unless c
96
- output.puts "This option requires an argument. Specify a color. Examples:"
97
- output.puts "Pry Theme: black; RGB: 0,0,0; HEX: #000000, ANSI: 0."
98
- return
69
+ opt.run do |opts, args|
70
+ if PryTheme::ThemeList.activate_theme(args.first)
71
+ output.puts %|Using "#{ args.first }" theme|
72
+ elsif args.first
73
+ output.puts %|Cannot find "#{args.first}" amongst themes in #{USER_THEMES_DIR}|
74
+ end
99
75
  end
76
+ end
77
+ end
100
78
 
101
- color = if ansi?(c)
102
- find_color(c)
103
- elsif hex?(c)
104
- find_color(ColorConverter.hex_to_ansi(c))
105
- elsif rgb?(c)
106
- find_color(ColorConverter.rgb_to_ansi(c))
107
- else
108
- h = ColorConverter::COLORS.select do |color|
109
- (color.human).to_s[c]
110
- end
111
-
112
- # Return human-readable colors if the
113
- # select selected any. If not, return nil.
114
- h if h.any?
115
- end
116
-
117
- case color
118
- when Array
119
- lputs color.map { |c| c.to_term(TermNotation::COLOR256) }.join("\n"), output
120
- when nil
121
- output.puts "Invalid color: #{ c }"
122
- else
123
- output.puts color.to_term(TermNotation::COLOR256)
79
+ def def_convert(cmd)
80
+ cmd.command :convert do |opt|
81
+ opt.description 'Convert the given color to proper terminal equivalent'
82
+
83
+ opt.on :t, :term=, 'Show a terminal color'
84
+ opt.on :h, :hex=, 'Convert from HEX'
85
+ opt.on :r, :rgb=, 'Convert from RGB'
86
+ opt.on :m, :model=, 'Convert accordingly to the given color model'
87
+
88
+ opt.run do |opts, args|
89
+ if color_model_option_only?(opts)
90
+ output.puts 'Provide a color value to be converted'
91
+ elsif color_model_option_and_other_one?(opts) || without_color_model?(opts)
92
+ convert_color(opts, args)
93
+ else
94
+ output.puts 'You must provide the `-m` and one of the rest switches.'
95
+ examples = [
96
+ 'pry-theme convert --model 8 --term 2',
97
+ 'pry-theme convert --model 8 --rgb 103,104,0',
98
+ 'pry-theme convert --model 16 --hex #EEAA00',
99
+ 'pry-theme convert --model 16 --term 0',
100
+ 'pry-theme convert --model 256 --term 255',
101
+ 'pry-theme convert --model 256 --hex #EEAA00',
102
+ ]
103
+ output.puts "Example: #{ examples[rand(examples.size)] }"
104
+ end
124
105
  end
125
106
  end
107
+ end
126
108
 
127
- def find_color(color)
128
- ColorConverter::COLORS.find { |c| c.term == color.to_i }
109
+ def def_uninstall(cmd)
110
+ cmd.command :uninstall do |opt|
111
+ opt.description 'Uninstall a theme'
112
+
113
+ opt.run do |opts, args|
114
+ args.each { |theme|
115
+ begin
116
+ FileUtils.rm(File.join(USER_THEMES_DIR, "#{ theme }.prytheme.rb"))
117
+ output.puts %|Successfully uninstalled "#{ theme }"!|
118
+ rescue
119
+ output.puts %|Cannot find theme "#{ theme }"|
120
+ end
121
+ }
122
+ end
129
123
  end
124
+ end
130
125
 
131
- def test_theme
132
- example = <<-TEST
133
- # "#{ PryTheme.current_theme }" theme.
134
- class PryTheme::ThisIsAClass
135
- def this_is_a_method
136
- THIS_IS_A_CONSTANT = :this_is_a_symbol
137
- this_is_a_local_var = "\#{this} \#@is a string.\\n"
138
- this_is_a_float = 10_000.00
139
- this_is_an_integer = 10_000
140
-
141
- # TRUE and FALSE are predefined constants.
142
- $this_is_a_global_variable = TRUE or FALSE
126
+ def def_install(cmd)
127
+ cmd.command :install do |opt|
128
+ opt.description 'Install a theme from Pry Theme Collection'
143
129
 
144
- @this_is_an_instance_variable = `echo '\#@hi \#{system} call\\n'`
145
- @@this_is_a_class_variable = @@@\\\\$ # An error.
130
+ opt.run do |opts, args|
131
+ install_theme(args)
132
+ end
133
+ end
134
+ end
146
135
 
147
- /[0-9]{1,3}this \#{is} a regexp\\w+/xi
148
- end
149
- end
150
- TEST
136
+ def def_current(cmd)
137
+ cmd.command :current do |opt|
138
+ opt.description 'Show information about currently active theme'
151
139
 
152
- lputs colorize_code(example), output
153
- end
140
+ opt.on :c, :colors, 'Display a painted code snippet'
154
141
 
155
- def edit_theme
156
- theme = args.first || PryTheme.current_theme
157
- theme.tr!("+", "") if new_theme_flag = (theme[0] == "+")
158
-
159
- if not new_theme_flag and not installed?(theme)
160
- output.puts %(Can't find "#{ theme }" theme in `#{ THEME_DIR }`.)
161
- output.puts "To create a new theme, prepend a `+` sign to its name."
162
- output.puts "Example: `pry-theme -e +#{ theme }`."
163
- return
164
- elsif new_theme_flag and installed?(theme)
165
- output.puts "Can't create a theme with the given name."
166
- output.puts %(The "#{ theme }" theme is already exist in your system.)
167
- output.puts "You can edit it with `pry-theme -e #{ theme }` command."
168
- return
169
- end
142
+ opt.run do |opts, args|
170
143
 
171
- theme_path = pathify_theme(theme)
172
-
173
- if new_theme_flag
174
- template = <<-TEMPLATE
175
- ---
176
- meta:
177
- theme-name : #{ theme }
178
- version : 1
179
- color-depth : 256 # Supports 8 or 256 colors.
180
- description : # Should be less than 80 characters.
181
- author : # John Doe <johndoe@example.com>
182
-
183
- theme:
184
- class : # blue on yellow
185
- class_variable : # red
186
- comment : # on green
187
- constant : # (bu)
188
- error : # black (b) on white
189
- float : # (i)
190
- global_variable :
191
- inline_delimiter :
192
- instance_variable :
193
- integer :
194
- keyword :
195
- method :
196
- predefined_constant :
197
- regexp:
198
- self :
199
- char :
200
- content :
201
- delimiter :
202
- modifier :
203
- escape :
204
- shell:
205
- self :
206
- char :
207
- content :
208
- delimiter :
209
- escape :
210
- string:
211
- self :
212
- char :
213
- content :
214
- delimiter :
215
- escape :
216
- symbol :
217
- TEMPLATE
218
-
219
- # Create a template in themes directory.
220
- File.open(theme_path, "w") { |f| f.puts template }
221
-
222
- output.puts %(Created "#{ theme }" theme in `#{ THEME_DIR }`.)
223
- output.puts "Opened it in #{ Pry.config.editor } for editing."
224
- else
225
- output.puts "Opened #{ theme } theme in #{ Pry.config.editor } for editing."
226
- output.puts "Don't forget to increment a version number of theme!"
144
+ if opts.present?(:c)
145
+ stagger_output Preview.new(ThemeList.current_theme).long
146
+ elsif args.empty?
147
+ output.puts ThemeList.current_theme.name
148
+ end
227
149
  end
150
+ end
151
+ end
228
152
 
229
- begin
230
- old_theme = PryTheme.current_theme
153
+ def def_edit(cmd)
154
+ cmd.command :edit do |opt|
155
+ opt.description 'Edit a theme definition'
231
156
 
232
- display_preview!(theme, %<Current "#{ theme }">)
233
- invoke_editor(theme_path, line=1, reloading=true)
234
- display_preview!(theme, %<Edited "#{ theme }">)
235
- ensure
236
- PryTheme.set_theme(old_theme)
157
+ opt.run do |opts, args|
158
+ BasicEditor.edit(args.first || ThemeList.current_theme.name)
237
159
  end
238
160
  end
161
+ end
239
162
 
240
- # Please, pay attention to the fact that this method changes current
241
- # theme to the given theme.
242
- def display_preview!(theme, header_text)
243
- PryTheme.set_theme(theme)
244
- display_header(header_text, output)
245
- test_theme
246
- end
163
+ def subcommands(cmd)
164
+ [:def_list, :def_colors, :def_try, :def_edit,
165
+ :def_uninstall, :def_install, :def_current, :def_convert,
166
+ ].each { |m| __send__(m, cmd) }
247
167
 
248
- def show_list
249
- old_theme = PryTheme.current_theme.dup
168
+ cmd.add_callback(:empty) do
169
+ stagger_output opts.help
170
+ end
171
+ end
250
172
 
251
- all_themes = installed_themes.map do |theme|
252
- theme = File.basename(theme, ".prytheme")
253
- meta = Theme.new(theme)
254
- PryTheme.set_theme(theme)
173
+ def process
174
+ # "There's no emptiness in the life of a warrior. Everything is filled to
175
+ # the brim. Everything is filled to the brim, and everything is equal."
176
+ end
255
177
 
256
- chunk = <<-CHUNK
257
- class Theme
258
- def method
259
- @ivar, @@cvar, lvar = 10_000, 400.00, "string"
260
- end
261
- end
262
- CHUNK
178
+ def complete(so_far)
179
+ PryTheme::ThemeList.themes.map(&:name)
180
+ end
263
181
 
264
- mark_current = "* " if theme == old_theme
265
- header = make_bold("#{mark_current}[#{theme}]")
266
- snippet = colorize_code(chunk)
267
- [header, meta.description, "---", snippet].compact.join("\n")
268
- end
182
+ private
269
183
 
270
- lputs all_themes.join("\n"), output
271
- ensure
272
- PryTheme.set_theme(old_theme)
184
+ def display_colors(color_model)
185
+ case color_model
186
+ when 256 then (stagger_output ColorTable.t256)
187
+ when 16 then (stagger_output ColorTable.t16)
188
+ when 8 then (stagger_output ColorTable.t8)
273
189
  end
190
+ end
274
191
 
275
- def show_remote_list
276
- require 'net/https'
277
- require 'json'
192
+ def show_local_list
193
+ previews = ThemeList.themes.map { |theme| Preview.new(theme).short }
194
+ stagger_output previews.join("\n")
195
+ end
278
196
 
279
- body = {}
280
- fetch_collection("/") do |http, uri|
281
- output.puts "Fetching list of themes..."
282
- response = http.request(Net::HTTP::Get.new(uri.request_uri))
283
- body = JSON.parse(response.body)
197
+ def show_remote_list
198
+ output.puts 'Fetching the list of themes from Pry Theme Collection...'
199
+ output.puts "#{windows?? '->':'→'} https://github.com/kyrylo/pry-theme-collection/"
200
+ body = json_body(PryTheme::PTC)
201
+
202
+ themes = body.map { |theme|
203
+ unless installed?(theme)
204
+ [theme['name'], theme['html_url']]
284
205
  end
206
+ }.compact
285
207
 
286
- i = 0
287
- remote_themes = body.map do |theme|
288
- if (name = theme["name"]) =~ /\A(?:[a-z]|[0-9]|-)+\z/
289
- "#{i+=1}. #{installed?(name) ? make_bold(name) : name}"
290
- end
291
- end.compact
208
+ out = "--\n"
209
+ themes.each.with_index(1) { |theme, i|
210
+ out += "#{ i }. "
211
+ out += theme.first + "\n"
292
212
 
293
- lputs remote_themes.join("\n"), output
294
- end
213
+ uri = URI.parse(PryTheme::SHORTENER + theme.last)
214
+ http = Net::HTTP.new(uri.host, uri.port)
215
+ response = http.request(Net::HTTP::Get.new(uri.request_uri))
295
216
 
296
- def install_theme
297
- return unless args[0]
217
+ out += response.body + "\n\n"
218
+ }
219
+ stagger_output out.chomp
220
+ end
298
221
 
299
- require 'net/https'
300
- require 'json'
301
- require 'base64'
222
+ def json_body(address)
223
+ require 'net/https'
224
+ require 'json'
225
+ require 'base64'
226
+
227
+ uri = URI.parse(address)
228
+ http = Net::HTTP.new(uri.host, uri.port)
229
+ http.use_ssl = true
230
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE if windows?
231
+ response = http.request(Net::HTTP::Get.new(uri.request_uri))
232
+ JSON.parse(response.body)
233
+ end
302
234
 
303
- body = {}
304
- fetch_collection("/#{args[0]}/#{args[0]}.prytheme") do |http, uri|
305
- output.puts "Fetching theme from the collection..."
306
- response = http.request(Net::HTTP::Get.new(uri.request_uri))
307
- body = JSON.parse(response.body)
308
- end
235
+ def install_theme(args)
236
+ args.each { |theme|
237
+ output.puts %|Installing "#{ theme }" from Pry Theme Collection...|
238
+ body = json_body(PTC + "%s/%s#{ PT_EXT }" % [theme, theme])
309
239
 
310
- if body["message"]
311
- output.puts "Cannot find theme: #{args[0]}"
312
- return
240
+ if body['message']
241
+ output.puts %|Cannot find theme "#{ theme }"...|
242
+ next
313
243
  end
314
244
 
315
- theme = Base64.decode64(body["content"])
316
-
317
- File.open(local_theme("#{args[0]}.prytheme"), "w") do |f|
318
- f.puts theme
245
+ File.open(File.join(USER_THEMES_DIR, "#{theme}.prytheme.rb"), 'w') do |f|
246
+ f.puts Base64.decode64(body['content'])
319
247
  end
248
+ require File.join(USER_THEMES_DIR, "#{theme}.prytheme.rb")
249
+ output.puts %|Successfully installed "#{ theme }"!|
250
+ }
251
+ end
320
252
 
321
- output.puts "Successfully installed #{args[0]}!"
322
- rescue
323
- output.puts "An error occurred!"
253
+ def convert_color(opts, args)
254
+ color_model = (opts.present?(:m) ? opts[:m] : PryTheme.tput_colors)
255
+
256
+ if opts.present?(:t)
257
+ color = PryTheme.color_const(color_model).new(
258
+ :from => :term, :foreground => opts[:t].to_i)
259
+ elsif opts.present?(:h)
260
+ color = PryTheme.color_const(color_model).new(
261
+ :from => :hex, :foreground => opts[:h])
262
+ elsif opts.present?(:r)
263
+ color = PryTheme.color_const(color_model).new(
264
+ :from => :rgb, :foreground => opts[:r])
324
265
  end
266
+ output.puts ColorTable.build_color_string(color)
267
+ rescue NameError
268
+ output.puts %|Unknown color model "#{ opts[:m] }". Try 8, 16 or 256|
325
269
  end
326
270
 
271
+ def color_model_option_only?(opts)
272
+ opts[:m] && !(opts[:h] || opts[:r] || opts[:t])
273
+ end
274
+
275
+ def color_model_option_and_other_one?(opts)
276
+ opts[:m] && (opts[:h] || opts[:r] || opts[:t])
277
+ end
278
+
279
+ def without_color_model?(opts)
280
+ !opts[:m] && (opts[:h] || opts[:r] || opts[:t])
281
+ end
282
+
283
+ def installed?(theme)
284
+ theme['name'] == 'README.md' ||
285
+ ThemeList.themes.map(&:name).include?(theme['name'])
286
+ end
327
287
  end
288
+
289
+ Pry::Commands.add_command(PryTheme::Command::PryTheme)
328
290
  end