pry-theme 0.0.3.pre → 0.0.4.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/README.md +44 -20
- data/lib/pry-theme.rb +12 -6
- data/lib/pry-theme/commands.rb +32 -4
- data/lib/pry-theme/palette.rb +26 -3
- data/lib/pry-theme/theme.rb +10 -1
- data/lib/pry-theme/version.rb +1 -1
- data/lib/pry-theme/when_started_hook.rb +2 -2
- metadata +2 -2
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
Pry Theme changelog
|
2
2
|
===================
|
3
3
|
|
4
|
+
### v0.0.4.pre (June 28, 2012)
|
5
|
+
|
6
|
+
* Added `--all-colors` and `--color` options for `pry-theme` command;
|
7
|
+
* Improved used experience when working with `pry-theme`.
|
8
|
+
|
4
9
|
### v0.0.3.pre (June 26, 2012)
|
5
10
|
|
6
11
|
* Added support for Mac OS and Windows (I believe so, at least).
|
data/README.md
CHANGED
@@ -2,11 +2,6 @@
|
|
2
2
|
|
3
3
|
* [https://github.com/kyrylo/pry-theme/][pt]
|
4
4
|
|
5
|
-
Warning
|
6
|
-
=======
|
7
|
-
|
8
|
-
The project is in its infancy, so do expect bugs.
|
9
|
-
|
10
5
|
Description
|
11
6
|
-----------
|
12
7
|
|
@@ -19,21 +14,23 @@ Installation
|
|
19
14
|
All you need is to install the gem. The `pry-theme` plugin will be detected and
|
20
15
|
used automatically.
|
21
16
|
|
22
|
-
gem install pry-theme
|
17
|
+
gem install pry-theme --pre
|
23
18
|
|
24
19
|
Synopsis
|
25
20
|
--------
|
26
21
|
|
27
|
-
###
|
22
|
+
### Theme files
|
28
23
|
|
29
|
-
|
30
|
-
|
24
|
+
Theme file is a valid YAML file, which has `.prytheme` extension (for example,
|
25
|
+
`beautiful.prytheme`). Pry Theme ships only with two themes: `pry-classic` and
|
26
|
+
`pry-modern`. In order to set up the desired theme, add the following line into
|
27
|
+
your `.pryrc`:
|
31
28
|
|
32
29
|
Pry.config.theme = "theme-name"
|
33
30
|
|
34
31
|
The default theme is `pry-classic` (basically, you won't notice it, because
|
35
|
-
it copies the default outlook of Pry,
|
36
|
-
something more neoteric:
|
32
|
+
it copies the default outlook of Pry, just as you didn't install anything).
|
33
|
+
Let's change it to something more neoteric:
|
37
34
|
|
38
35
|
Pry.config.theme = "pry-modern"
|
39
36
|
|
@@ -41,14 +38,13 @@ That's all! Launch your Pry and you will see the changes.
|
|
41
38
|
|
42
39
|
### CLI
|
43
40
|
|
44
|
-
Pry Theme has a command-line interface via Pry.
|
45
|
-
|
46
|
-
|
41
|
+
Pry Theme has a command-line interface available via Pry. Just launch Pry and
|
42
|
+
start working with it. For example, you can _temporary_ change themes on the
|
43
|
+
fly:
|
47
44
|
|
48
|
-
|
49
|
-
>> pry-theme pry-classic
|
45
|
+
[1] pry(main)> pry-theme pry-classic
|
50
46
|
|
51
|
-
|
47
|
+
This will switch your current theme to `pry-classic`.
|
52
48
|
|
53
49
|
### Creating themes
|
54
50
|
|
@@ -56,15 +52,43 @@ It's not easy now, so let's just skip this paragraph :P
|
|
56
52
|
|
57
53
|
### Adding new themes
|
58
54
|
|
59
|
-
Theme files
|
60
|
-
|
55
|
+
Theme files must have `.prytheme` extension.
|
56
|
+
|
57
|
+
* On GNU/Linux
|
58
|
+
|
59
|
+
Put your theme file in `$XDG_CONFIG_HOME/pry-theme` directory.
|
60
|
+
|
61
|
+
* On Mac OS
|
62
|
+
|
63
|
+
Put your theme file in `$HOME/Library/Application Support/pry-theme` directory.
|
64
|
+
|
65
|
+
And don't forget to adjust your `.pryrc`!
|
61
66
|
|
62
67
|
Limitations
|
63
68
|
-----------
|
64
69
|
|
65
|
-
|
70
|
+
Basically, it will run on any terminal that is capable of displaying 256 colors,
|
71
|
+
but with a couple of admonishments.
|
72
|
+
|
73
|
+
### OS support
|
74
|
+
|
75
|
+
* GNU/Linux;
|
76
|
+
* Mac OS (I hope so, leastwise);
|
77
|
+
|
78
|
+
I don't plan to support Windows, because I can't even find a sane terminal for
|
79
|
+
it. Sorry, Windows guys. If want me to change my mind, you have to file an
|
80
|
+
issue.
|
81
|
+
|
82
|
+
### Ruby versions
|
83
|
+
|
66
84
|
* CRuby 1.9.3 (in future will support other implementations).
|
67
85
|
|
86
|
+
Under the hood
|
87
|
+
--------------
|
88
|
+
|
89
|
+
Basically, Pry Theme is nothing but a CodeRay color scheme with a human-readable
|
90
|
+
syntax.
|
91
|
+
|
68
92
|
License
|
69
93
|
-------
|
70
94
|
|
data/lib/pry-theme.rb
CHANGED
@@ -27,12 +27,20 @@ module PryTheme
|
|
27
27
|
# Pry themes' directory.
|
28
28
|
THEME_DIR = File.join(CONFIG_DIR, "pry-theme")
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
def self.set_theme(theme_name)
|
31
|
+
if theme = PryTheme.convert(theme_name)
|
32
|
+
::CodeRay::Encoders::Terminal::TOKEN_COLORS.merge!(theme)
|
33
|
+
end
|
32
34
|
end
|
33
35
|
|
34
36
|
def self.convert(theme_name)
|
35
|
-
|
37
|
+
begin
|
38
|
+
theme = Theme.new(theme_name)
|
39
|
+
rescue NoThemeError => no_theme_error
|
40
|
+
warn no_theme_error
|
41
|
+
return
|
42
|
+
end
|
43
|
+
|
36
44
|
palette = Palette.new(theme.color_depth)
|
37
45
|
scheme = {}
|
38
46
|
|
@@ -104,9 +112,7 @@ module PryTheme
|
|
104
112
|
Formatting::BACKGROUNDS[m[:bg]]
|
105
113
|
end
|
106
114
|
|
107
|
-
notation
|
108
|
-
|
109
|
-
[notation, color_fg, formatting, color_bg].flatten.compact.join(";")
|
115
|
+
[palette.notation[0..-2], color_fg, formatting, color_bg].flatten.compact.join(";")
|
110
116
|
end
|
111
117
|
|
112
118
|
end
|
data/lib/pry-theme/commands.rb
CHANGED
@@ -2,16 +2,44 @@ module PryTheme
|
|
2
2
|
Commands = Pry::CommandSet.new do
|
3
3
|
|
4
4
|
create_command "pry-theme", "Manage your Pry themes." do
|
5
|
+
|
5
6
|
banner <<-BANNER
|
6
7
|
Usage: pry-theme [OPTIONS]
|
7
|
-
|
8
|
-
|
8
|
+
|
9
|
+
Change your theme on the fly.
|
10
|
+
e.g.: pry-theme pry-modern
|
11
|
+
e.g.: pry-theme pry-classic
|
12
|
+
e.g.: pry-theme --all-colors 8
|
9
13
|
BANNER
|
10
14
|
|
15
|
+
def options(opt)
|
16
|
+
opt.on :a, "all-colors", "Show all available 8/256 colors."
|
17
|
+
opt.on :c, "color", "Show information about a specific color (256)."
|
18
|
+
end
|
19
|
+
|
11
20
|
def process
|
12
|
-
|
13
|
-
|
21
|
+
return if args.empty?
|
22
|
+
|
23
|
+
if opts.a?
|
24
|
+
output.puts Palette.new(args[0]).to_s
|
25
|
+
elsif opts.c?
|
26
|
+
unless args[0] =~ /\A(\d{1,3})\z/ && (0...256).include?($1.to_i)
|
27
|
+
raise NoColorError, "Invalid color number: #{ args[0] }"
|
28
|
+
end
|
29
|
+
|
30
|
+
pal = Palette.new(256)
|
31
|
+
color = pal.colors.detect { |c| c.term == args[0].to_i }
|
32
|
+
|
33
|
+
if color
|
34
|
+
output.puts color.to_term(pal.notation)
|
35
|
+
end
|
36
|
+
else
|
37
|
+
PryTheme.set_theme(args[0].strip) and output.puts "Using #{ args[0] } theme"
|
14
38
|
end
|
39
|
+
rescue NoPaletteError => no_palette_error
|
40
|
+
warn no_palette_error
|
41
|
+
rescue NoColorError => no_color_error
|
42
|
+
warn no_color_error
|
15
43
|
end
|
16
44
|
end
|
17
45
|
|
data/lib/pry-theme/palette.rb
CHANGED
@@ -21,7 +21,11 @@ module PryTheme
|
|
21
21
|
end
|
22
22
|
|
23
23
|
# Creates a new color.
|
24
|
-
Color = Struct.new(:term, :human)
|
24
|
+
Color = Struct.new(:term, :human) do
|
25
|
+
def to_term(notation)
|
26
|
+
"\e[#{ notation }#{ term };7m#{ term }\e[0m:\e[#{ notation }#{ term }m#{ human }\e[0m"
|
27
|
+
end
|
28
|
+
end
|
25
29
|
|
26
30
|
# Color palettes aka set of colors. Use 8 colors for limited terminals (like
|
27
31
|
# `linux` or other pithecanthropic crap. Real men's choice is 256 colors).
|
@@ -33,13 +37,29 @@ module PryTheme
|
|
33
37
|
# @return [Integer] The number representing max number of colors in theme.
|
34
38
|
attr_reader :color_depth
|
35
39
|
|
40
|
+
# @return [String] The notation to be used in conversions to terminal.
|
41
|
+
attr_reader :notation
|
42
|
+
|
36
43
|
# @param [Integer] colors The number of colors to be used in the palette.
|
37
44
|
def initialize(colors=8)
|
38
|
-
|
45
|
+
@color_depth = colors.to_i
|
46
|
+
@notation = "38;5;" if color_depth == 256
|
47
|
+
|
48
|
+
init_palette = "init_#{@color_depth}_colors"
|
49
|
+
|
50
|
+
if self.class.private_method_defined?(init_palette)
|
51
|
+
palette = send(init_palette)
|
52
|
+
else
|
53
|
+
raise NoPaletteError, "There is no palette with #{colors} colors (try 8 or 256)"
|
54
|
+
end
|
55
|
+
|
39
56
|
@colors = palette[:term].zip(palette[:human]).map do |color|
|
40
57
|
Color.new(*color)
|
41
58
|
end
|
42
|
-
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_s
|
62
|
+
@colors.map { |c| c.to_term(@notation) }
|
43
63
|
end
|
44
64
|
|
45
65
|
private
|
@@ -59,4 +79,7 @@ module PryTheme
|
|
59
79
|
end
|
60
80
|
|
61
81
|
end
|
82
|
+
|
83
|
+
class NoPaletteError < StandardError; end
|
84
|
+
class NoColorError < StandardError; end
|
62
85
|
end
|
data/lib/pry-theme/theme.rb
CHANGED
@@ -4,7 +4,14 @@ module PryTheme
|
|
4
4
|
attr_reader :scheme, :author, :description, :color_depth, :version, :name
|
5
5
|
|
6
6
|
def initialize(theme_filename)
|
7
|
-
|
7
|
+
theme_file = File.join(THEME_DIR, "#{theme_filename}.prytheme")
|
8
|
+
|
9
|
+
if File.exists?(theme_file)
|
10
|
+
theme = Psych.load_file(theme_file)
|
11
|
+
else
|
12
|
+
raise NoThemeError, "#{theme_filename}.prytheme doesn't exist"
|
13
|
+
end
|
14
|
+
|
8
15
|
meta = theme["meta"]
|
9
16
|
|
10
17
|
@name = meta["theme-name"]
|
@@ -24,4 +31,6 @@ module PryTheme
|
|
24
31
|
end
|
25
32
|
|
26
33
|
end
|
34
|
+
|
35
|
+
class NoThemeError < StandardError; end
|
27
36
|
end
|
data/lib/pry-theme/version.rb
CHANGED
@@ -8,12 +8,12 @@ module PryTheme
|
|
8
8
|
|
9
9
|
(Dir.entries(EXAMPLES_ROOT) - %w{ . .. }).each do |f|
|
10
10
|
unless File.exists?(File.join(THEME_DIR, f))
|
11
|
-
FileUtils.cp(File.join(
|
11
|
+
FileUtils.cp(File.join(EXAMPLES_ROOT, f), THEME_DIR)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
theme_name = Pry.config.theme || "pry-classic"
|
16
|
-
PryTheme
|
16
|
+
PryTheme.set_theme(theme_name)
|
17
17
|
end
|
18
18
|
|
19
19
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry-theme
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4.pre
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pry
|