ripl-color_result 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gemspec CHANGED
@@ -11,7 +11,8 @@ Gem::Specification.new do |s|
11
11
  s.summary = "A ripl plugin to colorize result."
12
12
  s.description = "This ripl plugin colorizes your result."
13
13
  s.required_rubygems_version = ">= 1.3.6"
14
- s.add_dependency 'ripl', '>= 0.2.8'
14
+ s.add_dependency 'ripl', '>= 0.3.1'
15
+ s.add_dependency 'wirb', '>= 0.2.0'
15
16
  s.files = Dir.glob(%w[{lib,test}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} **/deps.rip]) + %w{Rakefile .gemspec}
16
17
  s.extra_rdoc_files = ["README.rdoc", "COPYING"]
17
18
  s.license = 'MIT'
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,6 @@
1
+ == 0.3.0
2
+ * Now using Wirb as default colorizer
3
+
1
4
  == 0.2.0
2
5
  * Added ap_options to pass a options hash to awesome_inspect (thanks to DirtYiCE)
3
6
  * Renamed color_result_schema option to color_result_default_schema (better logical nesting)
data/COPYING CHANGED
@@ -1,6 +1,4 @@
1
- Copyright (C) 2006-2009 Paul Duncan <pabs@pablotron.org>
2
- Copyright (C) 2009 Jens Wille <jens.wille@gmail.com>
3
- Copyright (C) 2010 Jan Lelis <mail@janlelis.de>
1
+ Copyright (C) 2010-2011 Jan Lelis <mail@janlelis.de>
4
2
 
5
3
  Permission is hereby granted, free of charge, to any person obtaining a
6
4
  copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -1,5 +1,5 @@
1
1
  == Description
2
- This {ripl}[http://github.com/cldwalker/ripl] plugin colorizes your results.
2
+ This {ripl}[https://github.com/cldwalker/ripl] plugin colorizes your results.
3
3
 
4
4
  == Install
5
5
  Install the gem with:
@@ -12,10 +12,10 @@ Add to your ~/.riplrc
12
12
 
13
13
  require 'ripl/color_result'
14
14
 
15
- You can choose a <tt>:color_result_engine</tt>. By default, the bundled +Wirble+-like colorization is used. Possible other values are:
15
+ You can choose a <tt>:color_result_engine</tt>. By default, Wirb[https://github.com/janlelis/wirb]] is used. Possible other values are:
16
16
 
17
- * <tt>:ap</tt> - using the _awesome_print_ gem
18
- * <tt>:coderay</tt> - using the _coderay_ gem
17
+ * <tt>:ap</tt> - use {awesome_print}[https://github.com/michaeldv/awesome_print]
18
+ * <tt>:coderay</tt> - use {coderay}[http://coderay.rubychan.de/]
19
19
 
20
20
  Example (in your ~/.riplrc)
21
21
 
@@ -24,18 +24,14 @@ Example (in your ~/.riplrc)
24
24
  Set it to +nil+ to deactivate result colorization.
25
25
 
26
26
  You can change the colors used by the default colorization by editing the <tt>:color_result_default_schema</tt> hash:
27
- Ripl.config[:color_result_default_schema][:comma] = :green
27
+ Ripl.config[:color_result_default_schema][:comma] = :blue
28
28
 
29
29
  If you use <tt>awesome_print</tt>, you can override default options using <tt>:color_result_ap_options</tt> hash:
30
30
  Ripl.config[:color_result_ap_options] = { :multiline => false }
31
31
 
32
32
  == Credits
33
33
 
34
- The default colorization uses code from Wirble
35
- * Copyright (C) 2006-2009 Paul Duncan <pabs@pablotron.org>
36
- * Copyright (C) 2009 Jens Wille <jens.wille@gmail.com>
37
-
38
- Copyright (c) 2010 Jan Lelis <http://code-needs-smileys.com>, see COPYING for details.
34
+ Copyright (c) 2010 Jan Lelis <http://rbjl.net>, see COPYING for details.
39
35
 
40
36
  Plus contributions by cldwalker and DirtYiCE.
41
37
 
data/deps.rip CHANGED
@@ -1 +1,2 @@
1
- ripl >=0.2.8
1
+ ripl >=0.3.1
2
+ wirb >=0.2.0
@@ -2,26 +2,7 @@ require 'ripl'
2
2
 
3
3
  module Ripl
4
4
  module ColorResult
5
- VERSION = '0.2.0'
6
- COLORS = {
7
- :nothing => '0;0',
8
- :black => '0;30',
9
- :red => '0;31',
10
- :green => '0;32',
11
- :brown => '0;33',
12
- :blue => '0;34',
13
- :purple => '0;35',
14
- :cyan => '0;36',
15
- :light_gray => '0;37',
16
- :dark_gray => '1;30',
17
- :light_red => '1;31',
18
- :light_green => '1;32',
19
- :yellow => '1;33',
20
- :light_blue => '1;34',
21
- :light_purple => '1;35',
22
- :light_cyan => '1;36',
23
- :white => '1;37',
24
- }
5
+ VERSION = '0.3.0'
25
6
 
26
7
  def format_result(result)
27
8
  return super if !config[:color_result_engine]
@@ -34,51 +15,78 @@ module Ripl
34
15
  require 'ap'
35
16
  result.awesome_inspect( config[:color_result_ap_options] || {} )
36
17
  else # :default
37
- require File.dirname(__FILE__) + "/color_result/default_colorizer"
38
- DefaultColorizer.colorize_code( result.inspect )
18
+ require 'wirb'
19
+ Wirb.colorize_result result.inspect, Ripl.config[:color_result_default_schema]
39
20
  end
40
-
41
21
  end
42
22
  end
43
23
  end
44
24
 
45
- Ripl::Shell.send :include, Ripl::ColorResult
46
-
25
+ Ripl::Shell.include Ripl::ColorResult
47
26
 
48
27
  Ripl.config[:color_result_engine] ||= :default
49
- # color scheme for default colorization, original from wirble
50
- Ripl.config[:color_result_default_schema] ||= {
51
- # delimiter colors
52
- :comma => :blue,
53
- :refers => :blue,
28
+ Ripl.config[:color_result_default_schema] ||= { # see Wirb::COLORS for a color list
29
+ # container
30
+ :open_hash => :light_green,
31
+ :close_hash => :light_green,
32
+ :open_array => :light_green,
33
+ :close_array => :light_green,
34
+
35
+ :open_set => :green,
36
+ :close_set => :green,
37
+ :open_enumerator => :green,
38
+ :close_enumerator => :green,
39
+
40
+ # delimiter colors
41
+ :comma => :green,
42
+ :refers => :green,
43
+
44
+ # class
45
+ :class => :light_green,
46
+ :class_separator => :green,
47
+ :object_class => :light_green,
48
+
49
+ # object
50
+ :open_object => :green,
51
+ :object_description_prefix => :green,
52
+ :object_description => :brown,
53
+ :object_addr_prefix => :brown_underline,
54
+ :object_addr => :brown_underline,
55
+ :object_line_prefix => :brown_underline,
56
+ :object_line => :brown_underline,
57
+ :object_line_number => :brown_underline,
58
+ :close_object => :green,
54
59
 
55
- # container colors (hash and array)
56
- :open_hash => :green,
57
- :close_hash => :green,
58
- :open_array => :green,
59
- :close_array => :green,
60
+ # symbol
61
+ :symbol_prefix => :yellow,
62
+ :symbol => :yellow,
63
+ :open_symbol_string => :brown,
64
+ :symbol_string => :yellow,
65
+ :close_symbol_string => :brown,
60
66
 
61
- # object colors
62
- :open_object => :light_red,
63
- :object_class => :white,
64
- :object_addr_prefix => :blue,
65
- :object_line_prefix => :blue,
66
- :close_object => :light_red,
67
+ # string
68
+ :open_string => :light_gray,
69
+ :string => :dark_gray,
70
+ :close_string => :light_gray,
67
71
 
68
- # symbol colors
69
- :symbol => :yellow,
70
- :symbol_prefix => :yellow,
72
+ # regexp
73
+ :open_regexp => :light_blue,
74
+ :regexp => :dark_gray,
75
+ :close_regexp => :light_blue,
76
+ :regexp_flags => :light_red,
71
77
 
72
- # string colors
73
- :open_string => :red,
74
- :string => :cyan,
75
- :close_string => :red,
78
+ # number
79
+ :number => :cyan,
80
+ :range => :red,
81
+ :open_rational => :light_cyan,
82
+ :rational_separator => :light_cyan,
83
+ :close_rational => :light_cyan,
76
84
 
77
- # misc colors
78
- :number => :cyan,
79
- :keyword => :green,
80
- :class => :light_green,
81
- :range => :red,
85
+ # misc
86
+ :keyword => nil,
87
+ :nil => :light_red,
88
+ :false => :red,
89
+ :true => :green,
82
90
  }
83
91
 
84
92
  # J-_-L
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 0.2.0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jan Lelis
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-13 00:00:00 +01:00
17
+ date: 2011-01-27 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -27,11 +27,26 @@ dependencies:
27
27
  - !ruby/object:Gem::Version
28
28
  segments:
29
29
  - 0
30
- - 2
31
- - 8
32
- version: 0.2.8
30
+ - 3
31
+ - 1
32
+ version: 0.3.1
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: wirb
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 0
45
+ - 2
46
+ - 0
47
+ version: 0.2.0
48
+ type: :runtime
49
+ version_requirements: *id002
35
50
  description: This ripl plugin colorizes your result.
36
51
  email: mail@janlelis.de
37
52
  executables: []
@@ -42,7 +57,6 @@ extra_rdoc_files:
42
57
  - README.rdoc
43
58
  - COPYING
44
59
  files:
45
- - lib/ripl/color_result/default_colorizer.rb
46
60
  - lib/ripl/color_result.rb
47
61
  - README.rdoc
48
62
  - CHANGELOG.rdoc
@@ -1,193 +0,0 @@
1
- # Default colorization module:
2
- # Code taken from the (blackwinter) wirble gem, adjusted api. See COPYING for credits.
3
-
4
- class << Ripl::ColorResult::DefaultColorizer = Module.new
5
- def tokenize(str)
6
- raise 'missing block' unless block_given?
7
- chars = str.split(//)
8
-
9
- # $stderr.puts "DEBUG: chars = #{chars.join(',')}"
10
-
11
- state, val, i, lc = [], '', 0, nil
12
- while i <= chars.size
13
- repeat = false
14
- c = chars[i]
15
-
16
- # $stderr.puts "DEBUG: state = #{state}"
17
-
18
- case state[-1]
19
- when nil
20
- case c
21
- when ':'
22
- state << :symbol
23
- when '"'
24
- state << :string
25
- when '#'
26
- state << :object
27
- when /[a-z]/i
28
- state << :keyword
29
- repeat = true
30
- when /[0-9-]/
31
- state << :number
32
- repeat = true
33
- when '{'
34
- yield :open_hash, '{'
35
- when '['
36
- yield :open_array, '['
37
- when ']'
38
- yield :close_array, ']'
39
- when '}'
40
- yield :close_hash, '}'
41
- when /\s/
42
- yield :whitespace, c
43
- when ','
44
- yield :comma, ','
45
- when '>'
46
- yield :refers, '=>' if lc == '='
47
- when '.'
48
- yield :range, '..' if lc == '.'
49
- when '='
50
- # ignore these, they're used elsewhere
51
- nil
52
- else
53
- # $stderr.puts "DEBUG: ignoring char #{c}"
54
- end
55
- when :symbol
56
- case c
57
- # XXX: should have =, but that messes up foo=>bar
58
- when /[a-z0-9_!?]/
59
- val << c
60
- else
61
- yield :symbol_prefix, ':'
62
- yield state[-1], val
63
- state.pop; val = ''
64
- repeat = true
65
- end
66
- when :string
67
- case c
68
- when '"'
69
- if lc == "\\"
70
- val[-1] = ?"
71
- else
72
- yield :open_string, '"'
73
- yield state[-1], val
74
- state.pop; val = ''
75
- yield :close_string, '"'
76
- end
77
- else
78
- val << c
79
- end
80
- when :keyword
81
- case c
82
- when /[a-z0-9_]/i
83
- val << c
84
- else
85
- # is this a class?
86
- st = val =~ /^[A-Z]/ ? :class : state[-1]
87
-
88
- yield st, val
89
- state.pop; val = ''
90
- repeat = true
91
- end
92
- when :number
93
- case c
94
- when /[0-9e-]/
95
- val << c
96
- when '.'
97
- if lc == '.'
98
- val[/\.$/] = ''
99
- yield state[-1], val
100
- state.pop; val = ''
101
- yield :range, '..'
102
- else
103
- val << c
104
- end
105
- else
106
- yield state[-1], val
107
- state.pop; val = ''
108
- repeat = true
109
- end
110
- when :object
111
- case c
112
- when '<'
113
- yield :open_object, '#<'
114
- state << :object_class
115
- when ':'
116
- state << :object_addr
117
- when '@'
118
- state << :object_line
119
- when '>'
120
- yield :close_object, '>'
121
- state.pop; val = ''
122
- end
123
- when :object_class
124
- case c
125
- when ':'
126
- yield state[-1], val
127
- state.pop; val = ''
128
- repeat = true
129
- else
130
- val << c
131
- end
132
- when :object_addr
133
- case c
134
- when '>'
135
- when '@'
136
- yield :object_addr_prefix, ':'
137
- yield state[-1], val
138
- state.pop; val = ''
139
- repeat = true
140
- else
141
- val << c
142
- end
143
- when :object_line
144
- case c
145
- when '>'
146
- yield :object_line_prefix, '@'
147
- yield state[-1], val
148
- state.pop; val = ''
149
- repeat = true
150
- else
151
- val << c
152
- end
153
- else
154
- raise "unknown state #{state}"
155
- end
156
-
157
- unless repeat
158
- i += 1
159
- lc = c
160
- end
161
- end
162
- end
163
-
164
- #
165
- # Return the escape code for a given color.
166
- #
167
- def get_color(key)
168
- Ripl::ColorResult::COLORS.key?(key) && "\033[#{Ripl::ColorResult::COLORS[key]}m"
169
- end
170
-
171
- #
172
- # Return a string with the given color.
173
- #
174
- def colorize_string(str, color)
175
- col, nocol = [color, :nothing].map { |key| get_color(key) }
176
- col ? "#{col}#{str}#{nocol}" : str
177
- end
178
-
179
- #
180
- # Colorize the results of inspect
181
- #
182
- def colorize_code(str)
183
- ret, nocol = '', get_color(:nothing)
184
- tokenize(str) do |tok, val|
185
- ret << colorize_string(val, Ripl.config[:color_result_default_schema][tok])
186
- end
187
- ret
188
- rescue # catch any errors from the tokenizer (just in case)
189
- str
190
- end
191
- end
192
-
193
- # J-_-L