pry-theme 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +1 -0
- data/.travis.yml +8 -1
- data/CHANGELOG.md +40 -0
- data/Gemfile +1 -1
- data/README.md +26 -48
- data/Rakefile +10 -1
- data/VERSION +1 -0
- data/lib/pry-theme/basic_editor.rb +116 -0
- data/lib/pry-theme/color.rb +431 -0
- data/lib/pry-theme/color_table.rb +39 -0
- data/lib/pry-theme/colors/color16.rb +35 -0
- data/lib/pry-theme/colors/color256.rb +30 -0
- data/lib/pry-theme/colors/color8.rb +31 -0
- data/lib/pry-theme/commands.rb +237 -275
- data/lib/pry-theme/declaration.rb +120 -0
- data/lib/pry-theme/definition.rb +111 -0
- data/lib/pry-theme/formattable.rb +26 -0
- data/lib/pry-theme/hex.rb +76 -0
- data/lib/pry-theme/preview.rb +74 -0
- data/lib/pry-theme/rgb.rb +238 -13
- data/lib/pry-theme/term.rb +66 -0
- data/lib/pry-theme/theme.rb +116 -26
- data/lib/pry-theme/theme_list.rb +52 -0
- data/lib/pry-theme/when_started_hook.rb +25 -27
- data/lib/pry-theme.rb +84 -158
- data/pry-theme.gemspec +14 -18
- data/spec/color_table.rb +53 -0
- data/spec/colors/color16_spec.rb +255 -0
- data/spec/colors/color256_spec.rb +323 -0
- data/spec/colors/color8_spec.rb +254 -0
- data/spec/commands_spec.rb +203 -0
- data/spec/helper.rb +16 -0
- data/spec/hex_spec.rb +52 -0
- data/spec/rgb_spec.rb +81 -0
- data/spec/term_spec.rb +23 -0
- data/spec/theme_spec.rb +486 -0
- data/themes/github.prytheme.rb +49 -0
- data/themes/monokai.prytheme.rb +48 -0
- data/themes/pry-classic-16.prytheme.rb +48 -0
- data/themes/pry-classic-256.prytheme.rb +48 -0
- data/themes/pry-classic-8.prytheme.rb +48 -0
- data/themes/pry-cold.prytheme.rb +49 -0
- data/themes/pry-love-16.prytheme.rb +48 -0
- data/themes/pry-love-8.prytheme.rb +48 -0
- data/themes/pry-modern-16.prytheme.rb +48 -0
- data/themes/pry-modern-256.prytheme.rb +48 -0
- data/themes/pry-modern-8.prytheme.rb +48 -0
- data/themes/pry-monochrome.prytheme.rb +32 -0
- data/themes/pry-siberia-16.prytheme.rb +48 -0
- data/themes/pry-siberia-8.prytheme.rb +48 -0
- data/themes/pry-tepid-16.prytheme.rb +48 -0
- data/themes/pry-tepid-8.prytheme.rb +48 -0
- data/themes/pry-zealand-16.prytheme.rb +48 -0
- data/themes/pry-zealand-8.prytheme.rb +49 -0
- data/themes/railscasts.prytheme.rb +50 -0
- data/themes/solarized.prytheme.rb +48 -0
- data/themes/tomorrow.prytheme.rb +48 -0
- data/themes/twilight.prytheme.rb +48 -0
- data/themes/vim-default.prytheme.rb +50 -0
- data/themes/vim-detailed.prytheme.rb +50 -0
- data/themes/zenburn.prytheme.rb +48 -0
- metadata +56 -41
- data/lib/pry-theme/color_converter.rb +0 -55
- data/lib/pry-theme/helper.rb +0 -87
- data/lib/pry-theme/palette.rb +0 -85
- data/lib/pry-theme/term_notation.rb +0 -17
- data/lib/pry-theme/version.rb +0 -3
- data/test/fixtures/pry-classic.prytheme +0 -38
- data/test/helper.rb +0 -56
- data/test/test_color_converter.rb +0 -38
- data/test/test_commands.rb +0 -55
- data/test/test_helper.rb +0 -45
- data/test/test_palette.rb +0 -11
- data/themes/github.prytheme +0 -43
- data/themes/monokai.prytheme +0 -42
- data/themes/pry-classic.prytheme +0 -43
- data/themes/pry-cold.prytheme +0 -43
- data/themes/pry-modern.prytheme +0 -42
- data/themes/railscasts.prytheme +0 -44
- data/themes/saturday.prytheme +0 -42
- data/themes/solarized.prytheme +0 -43
- data/themes/tomorrow.prytheme +0 -43
- data/themes/twilight.prytheme +0 -42
- data/themes/vim-default.prytheme +0 -42
- data/themes/vim-detailed.prytheme +0 -42
- data/themes/zenburn.prytheme +0 -43
data/lib/pry-theme/commands.rb
CHANGED
@@ -1,328 +1,290 @@
|
|
1
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
-
|
74
|
-
|
75
|
-
|
49
|
+
def def_colors(cmd)
|
50
|
+
cmd.command :colors do |opt|
|
51
|
+
opt.description 'Show all available colors'
|
76
52
|
|
77
|
-
|
78
|
-
color_table = []
|
53
|
+
opt.on :m, :model=, 'Display colors according to the given color model'
|
79
54
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
-
|
93
|
-
|
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
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
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
|
-
|
128
|
-
|
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
|
-
|
132
|
-
|
133
|
-
|
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
|
-
|
145
|
-
|
130
|
+
opt.run do |opts, args|
|
131
|
+
install_theme(args)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
146
135
|
|
147
|
-
|
148
|
-
|
149
|
-
|
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
|
-
|
153
|
-
end
|
140
|
+
opt.on :c, :colors, 'Display a painted code snippet'
|
154
141
|
|
155
|
-
|
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
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
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
|
-
|
230
|
-
|
153
|
+
def def_edit(cmd)
|
154
|
+
cmd.command :edit do |opt|
|
155
|
+
opt.description 'Edit a theme definition'
|
231
156
|
|
232
|
-
|
233
|
-
|
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
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
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
|
-
|
249
|
-
|
168
|
+
cmd.add_callback(:empty) do
|
169
|
+
stagger_output opts.help
|
170
|
+
end
|
171
|
+
end
|
250
172
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
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
|
-
|
257
|
-
|
258
|
-
|
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
|
-
|
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
|
-
|
271
|
-
|
272
|
-
|
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
|
-
|
276
|
-
|
277
|
-
|
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
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
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
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
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
|
-
|
294
|
-
|
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
|
-
|
297
|
-
|
217
|
+
out += response.body + "\n\n"
|
218
|
+
}
|
219
|
+
stagger_output out.chomp
|
220
|
+
end
|
298
221
|
|
299
|
-
|
300
|
-
|
301
|
-
|
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
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
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[
|
311
|
-
output.puts
|
312
|
-
|
240
|
+
if body['message']
|
241
|
+
output.puts %|Cannot find theme "#{ theme }"...|
|
242
|
+
next
|
313
243
|
end
|
314
244
|
|
315
|
-
|
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
|
-
|
322
|
-
|
323
|
-
|
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
|