pry-theme 0.0.4.pre → 0.0.5

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.
data/CHANGELOG.md CHANGED
@@ -1,6 +1,22 @@
1
1
  Pry Theme changelog
2
2
  ===================
3
3
 
4
+ ### v0.0.5.pre (June 29, 2012)
5
+
6
+ * Added Ruby 1.8.7, JRuby and Ruby Enterprise Edition support.
7
+ * Fixed 8-color themes bug. We could not even use them in the previous version;
8
+ * Added `--test` command, which allows to "test" your theme visually.
9
+ * Added uninstaller, which basically just asks a user if he or she wants to
10
+ remove a directory with Pry themes (personally, I hate when software leave
11
+ their crap).
12
+ * Slightly improved `help` of `pry-theme` command
13
+ * Made theme attributes optional. Now, if you are not sure about some parameter
14
+ in a Pry Theme, you can leave it empty.
15
+
16
+ Last but not least:
17
+
18
+ * Check out new Wiki! (https://github.com/kyrylo/pry-theme/wiki)
19
+
4
20
  ### v0.0.4.pre (June 28, 2012)
5
21
 
6
22
  * Added `--all-colors` and `--color` options for `pry-theme` command;
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  ![Pry Theme][logo]
2
2
 
3
- * [https://github.com/kyrylo/pry-theme/][pt]
3
+ * Repository: [https://github.com/kyrylo/pry-theme/][pt]
4
+ * Wiki: [https://github.com/kyrylo/pry-theme/wiki][wiki]
4
5
 
5
6
  Description
6
7
  -----------
@@ -14,7 +15,7 @@ Installation
14
15
  All you need is to install the gem. The `pry-theme` plugin will be detected and
15
16
  used automatically.
16
17
 
17
- gem install pry-theme --pre
18
+ gem install pry-theme
18
19
 
19
20
  Synopsis
20
21
  --------
@@ -46,13 +47,16 @@ fly:
46
47
 
47
48
  This will switch your current theme to `pry-classic`.
48
49
 
50
+ You can find [more information about CLI in Pry Theme Wiki][cli].
51
+
49
52
  ### Creating themes
50
53
 
51
- It's not easy now, so let's just skip this paragraph :P
54
+ Creating new themes isn't hard. [Check out Pry Theme Wiki article on that][new_theme].
52
55
 
53
56
  ### Adding new themes
54
57
 
55
- Theme files must have `.prytheme` extension.
58
+ Theme files must have `.prytheme` extension. Check out [Pry Theme Collection][ptc],
59
+ if you want to find some themes other than default ones.
56
60
 
57
61
  * On GNU/Linux
58
62
 
@@ -68,20 +72,24 @@ Limitations
68
72
  -----------
69
73
 
70
74
  Basically, it will run on any terminal that is capable of displaying 256 colors,
71
- but with a couple of admonishments.
75
+ but with a couple of admonishments. They are listed below.
72
76
 
73
77
  ### OS support
74
78
 
75
79
  * GNU/Linux;
76
80
  * Mac OS (I hope so, leastwise);
77
81
 
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.
82
+ I hope it runs on Windows too, but I couldn't find any sane terminal, that
83
+ would support 256 colors. Sorry, Windows guys. Please, file an issue, if you
84
+ noticed bugs or something.
81
85
 
82
86
  ### Ruby versions
83
87
 
84
- * CRuby 1.9.3 (in future will support other implementations).
88
+ * MRI 1.9.3
89
+ * MRI 1.9.2
90
+ * MRI 1.8.7
91
+ * REE 1.8.7-2012.02
92
+ * JRuby 1.6.7
85
93
 
86
94
  Under the hood
87
95
  --------------
@@ -97,3 +105,7 @@ The project uses Zlib License. See LICENSE file for more information.
97
105
  [pt]: https://github.com/kyrylo/pry-theme/ "Home page"
98
106
  [logo]: http://img-fotki.yandex.ru/get/5107/98991937.a/0_7c6c8_871a1842_orig "Pry Theme"
99
107
  [pry]: https://github.com/pry/pry/ "Pry's home page"
108
+ [new_theme]: https://github.com/kyrylo/pry-theme/wiki/Creating-a-New-Theme
109
+ [cli]: https://github.com/kyrylo/pry-theme/wiki/Pry-Theme-CLI
110
+ [wiki]: https://github.com/kyrylo/pry-theme/wiki
111
+ [ptc]: https://github.com/kyrylo/pry-theme-collection
@@ -4,43 +4,111 @@ module PryTheme
4
4
  create_command "pry-theme", "Manage your Pry themes." do
5
5
 
6
6
  banner <<-BANNER
7
- Usage: pry-theme [OPTIONS]
7
+ Usage: pry-theme [OPTIONS] [--help]
8
8
 
9
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
10
+
11
+ pry-theme pry-modern
12
+
13
+ Display 8-color palette.
14
+
15
+ pry-theme --all-colors 8
16
+
17
+ Display Pry Theme code for terminal color 34.
18
+
19
+ pry-theme -c 34
20
+
21
+ Test your current color theme.
22
+
23
+ pry-theme -t
24
+
25
+ Wiki: https://github.com/kyrylo/pry-theme/wiki/Pry-Theme-CLI
13
26
  BANNER
14
27
 
15
28
  def options(opt)
16
29
  opt.on :a, "all-colors", "Show all available 8/256 colors."
17
30
  opt.on :c, "color", "Show information about a specific color (256)."
31
+ opt.on :t, "test", "Test your current theme", :argument => false
18
32
  end
19
33
 
20
34
  def process
21
- return if args.empty?
22
-
23
35
  if opts.a?
24
- output.puts Palette.new(args[0]).to_s
36
+ show_palette_colors
25
37
  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"
38
+ show_specific_color
39
+ elsif opts.t?
40
+ test_theme
41
+ elsif args[0] =~ /\A\w+-?\w+\z/
42
+ switch_to_theme
38
43
  end
39
44
  rescue NoPaletteError => no_palette_error
40
45
  warn no_palette_error
41
46
  rescue NoColorError => no_color_error
42
47
  warn no_color_error
43
48
  end
49
+
50
+ private
51
+
52
+ def switch_to_theme
53
+ PryTheme.set_theme(args[0].strip) and
54
+ output.puts "Using #{ args[0] } theme"
55
+ end
56
+
57
+ def show_palette_colors
58
+ output.puts Palette.new(args[0]).to_s
59
+ end
60
+
61
+ def show_specific_color
62
+ unless args[0] =~ /\A(\d{1,3})\z/ && (0...256).include?($1.to_i)
63
+ raise NoColorError, "Invalid color number: #{ args[0] }"
64
+ end
65
+
66
+ pal = Palette.new(256)
67
+ color = pal.colors.detect { |c| c.term == args[0].to_i }
68
+
69
+ if color
70
+ output.puts color.to_term(pal.notation)
71
+ end
72
+ end
73
+
74
+ def test_theme
75
+ example = <<-TEST
76
+ # Time for testing your colors!
77
+ module PryTheme
78
+ module JustTesting
79
+
80
+ THIS_IS_CONSTANT = :this_is_symbol
81
+
82
+ class ThisIsClass
83
+
84
+ def this_is_method
85
+ this_is_float = 10_000.00
86
+ this_is_integer = 10_000
87
+
88
+ "this_is_string"
89
+ 'this is another string'
90
+
91
+ @@this_is_class_variable
92
+
93
+ `echo 'Hello, hi, from "system" call!'`
94
+
95
+ $ # <-- The dollar is an error!
96
+
97
+ /[0-9]{1,3}this is regexp\\w+/xi
98
+ $1 or $2 or $3333
99
+
100
+ nil
101
+ self
102
+ end
103
+
104
+ end
105
+ end
106
+ end
107
+ # Testing complete.
108
+ TEST
109
+
110
+ output.puts colorize_code(example)
111
+ end
44
112
  end
45
113
 
46
114
  end
@@ -7,7 +7,7 @@ module PryTheme
7
7
  theme_file = File.join(THEME_DIR, "#{theme_filename}.prytheme")
8
8
 
9
9
  if File.exists?(theme_file)
10
- theme = Psych.load_file(theme_file)
10
+ theme = YAML.load_file(theme_file)
11
11
  else
12
12
  raise NoThemeError, "#{theme_filename}.prytheme doesn't exist"
13
13
  end
@@ -0,0 +1,20 @@
1
+ require 'fileutils'
2
+
3
+ module PryTheme
4
+ module Uninstaller
5
+
6
+ def self.run(u)
7
+ puts "Do you wish to delete #{THEME_DIR} directory with all Pry themes?"
8
+ print "(y/n): "
9
+
10
+ case $stdin.gets.chomp
11
+ when "y"
12
+ FileUtils.rm_rf(THEME_DIR)
13
+ puts "Successfully deleted #{THEME_DIR} and all Pry themes."
14
+ else
15
+ puts "Nothing deleted. You can manually delete the directory."
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module PryTheme
2
- VERSION = "0.0.4.pre"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -4,7 +4,7 @@ module PryTheme
4
4
  class WhenStartedHook
5
5
 
6
6
  def call(target, options, _pry_)
7
- Dir.mkdir(THEME_DIR) unless Dir.exists?(THEME_DIR)
7
+ Dir.mkdir(THEME_DIR) unless File.exists?(THEME_DIR)
8
8
 
9
9
  (Dir.entries(EXAMPLES_ROOT) - %w{ . .. }).each do |f|
10
10
  unless File.exists?(File.join(THEME_DIR, f))
data/lib/pry-theme.rb CHANGED
@@ -3,8 +3,10 @@ require 'pry-theme/commands'
3
3
  require 'pry-theme/palette'
4
4
  require 'pry-theme/theme'
5
5
  require 'pry-theme/when_started_hook'
6
+ require 'pry-theme/uninstaller'
7
+
6
8
  require 'pry'
7
- require 'psych'
9
+ require 'yaml'
8
10
 
9
11
  module PryTheme
10
12
 
@@ -67,7 +69,7 @@ module PryTheme
67
69
 
68
70
  # Matches "yellow".
69
71
  (
70
- (?<fg>
72
+ (
71
73
  \w+(0[1-9])?
72
74
  )
73
75
  \s?
@@ -76,7 +78,7 @@ module PryTheme
76
78
  # Matches "yellow (bu)" or "(bu)".
77
79
  (
78
80
  \(
79
- (?<attrs>
81
+ (
80
82
  d?b?u?i? # Order matters.
81
83
  )
82
84
  \)
@@ -87,32 +89,42 @@ module PryTheme
87
89
  (
88
90
  \s?
89
91
  on\s
90
- (?<bg>
92
+ (
91
93
  [a-z]+(0[1-9])?
92
94
  )
93
95
  )?
94
96
 
95
97
  \z
96
98
  /x
97
- m = color.match(color_pattern)
98
99
 
99
- color_fg = if m[:fg]
100
- palette.colors.find do |color|
101
- color.human == m[:fg].to_sym
102
- end.term
103
- end
100
+ if color
101
+ m = color.match(color_pattern)
102
+
103
+ color_fg = if $2
104
+ palette.colors.find do |color|
105
+ color.human == $2.to_sym
106
+ end.term
107
+ end
108
+
109
+ formatting = if $5
110
+ formatting = $5.each_char.map do |ch|
111
+ Formatting::ATTRIBUTES[ch]
112
+ end
113
+ end
104
114
 
105
- formatting = if m[:attrs]
106
- formatting = m[:attrs].each_char.map do |ch|
107
- Formatting::ATTRIBUTES[ch]
115
+ color_bg = if $7
116
+ Formatting::BACKGROUNDS[$7]
108
117
  end
109
- end
110
118
 
111
- color_bg = if m[:bg]
112
- Formatting::BACKGROUNDS[m[:bg]]
113
- end
119
+ notation = palette.notation ? palette.notation[0..-2] : ""
120
+ [notation, color_fg, formatting, color_bg].flatten.compact.join(";")
121
+ end
122
+ end
114
123
 
115
- [palette.notation[0..-2], color_fg, formatting, color_bg].flatten.compact.join(";")
124
+ def self.install_gem_hooks
125
+ Gem.post_uninstall do |u|
126
+ Uninstaller.run(u)
127
+ end
116
128
  end
117
129
 
118
130
  end
@@ -0,0 +1,4 @@
1
+ require 'pry'
2
+ require 'pry-theme'
3
+
4
+ PryTheme.install_gem_hooks
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-theme
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4.pre
5
- prerelease: 6
4
+ version: 0.0.5
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kyrylo Silin
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-28 00:00:00.000000000 Z
12
+ date: 2012-06-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pry
@@ -43,8 +43,10 @@ files:
43
43
  - lib/pry-theme/commands.rb
44
44
  - lib/pry-theme/palette.rb
45
45
  - lib/pry-theme/theme.rb
46
+ - lib/pry-theme/uninstaller.rb
46
47
  - lib/pry-theme/version.rb
47
48
  - lib/pry-theme/when_started_hook.rb
49
+ - lib/rubygems_plugin.rb
48
50
  - pry-theme.gemspec
49
51
  homepage: https://github.com/kyrylo/pry-theme
50
52
  licenses:
@@ -62,9 +64,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
62
64
  required_rubygems_version: !ruby/object:Gem::Requirement
63
65
  none: false
64
66
  requirements:
65
- - - ! '>'
67
+ - - ! '>='
66
68
  - !ruby/object:Gem::Version
67
- version: 1.3.1
69
+ version: '0'
68
70
  requirements: []
69
71
  rubyforge_project:
70
72
  rubygems_version: 1.8.23