wirb 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,35 @@
1
+ begin # only test if paint is available
2
+ require 'paint'
3
+
4
+ describe Wirb::Colorizer::Wirb0_Paint do
5
+ before :each do
6
+ Wirb.colorizer = Wirb::Colorizer::Wirb0_Paint
7
+ end
8
+
9
+ it "creates good color codes based on Paint color symbols" do
10
+ Wirb.get_color(:red).should match_colors(31)
11
+ Wirb.get_color(:red, :bright).should match_colors(1,31)
12
+ Wirb.get_color(:bright, :red).should match_colors(1,31)
13
+ Wirb.get_color(:red, :bright, :underline).should match_colors(1,4,31)
14
+ Wirb.get_color(:red, :blue).should match_colors(31,44)
15
+ Wirb.get_color(nil, :blue).should match_colors(44)
16
+ Wirb.get_color([43,86,129]).should match_colors('38;5;'+(16 + 1*36 + 2*6 + 3*1).to_s)
17
+ Wirb.get_color("medium sea green").should match_colors('38;5;78')
18
+ Wirb.get_color("#81562b").should match_colors('38;5;' + (16 + 3*36 + 2*6 + 1*1).to_s)
19
+ Wirb.get_color("#863").should match_colors('38;5;' + (16 + 3*36 + 2*6 + 1*1).to_s)
20
+ Wirb.get_color(:red, :encircle).should match_colors(52,31)
21
+ end
22
+
23
+ it "colorizes strings based on Paint color symbols" do
24
+ Wirb.colorize_string('Dantooine', :red, :bright, :underline).should match_colored_string('Dantooine', 1,4,31)
25
+ end
26
+
27
+ it_behaves_like "a Wirb0 colorizer"
28
+
29
+ after :each do
30
+ Wirb.colorizer = nil
31
+ end
32
+ end
33
+
34
+ rescue LoadError
35
+ end
@@ -0,0 +1,11 @@
1
+ describe Wirb::Colorizer::Wirb0 do
2
+ before :each do
3
+ Wirb.colorizer = Wirb::Colorizer::Wirb0
4
+ end
5
+
6
+ it_behaves_like "a Wirb0 colorizer"
7
+
8
+ after :each do
9
+ Wirb.colorizer = nil
10
+ end
11
+ end
@@ -0,0 +1,24 @@
1
+ describe Wirb::Colorizer::Wirble do
2
+ before :each do
3
+ Wirb.colorizer = Wirb::Colorizer::Wirble
4
+ end
5
+
6
+ it "creates good color codes based on Wirble color symbols" do
7
+ Wirb.get_color(:nothing).should match_colors(0)
8
+ Wirb.get_color(:purple).should match_colors(35)
9
+ Wirb.get_color(:light_gray).should match_colors(37)
10
+ Wirb.get_color(:dark_gray).should match_colors(1,30)
11
+ Wirb.get_color(:yellow).should match_colors(1,33)
12
+ Wirb.get_color(:light_green).should match_colors(1,32)
13
+ Wirb.get_color(:white).should match_colors(1,37)
14
+ end
15
+
16
+ it "colorizes strings based on Wirble color symbols" do
17
+ Wirb.colorize_string('Dantooine', :cyan).should match_colored_string('Dantooine', 36)
18
+ Wirb.colorize_string('Dantooine', :light_red).should match_colored_string('Dantooine', 1,31)
19
+ end
20
+
21
+ after :each do
22
+ Wirb.colorizer = nil
23
+ end
24
+ end
@@ -1,5 +1,3 @@
1
- #require File.dirname(__FILE__) + '/../lib/wirb' unless defined? Wirb
2
- #require File.dirname(__FILE__) + '/../lib/wirb/wp'
3
1
  require 'wirb'
4
2
  require 'wirb/wp'
5
3
  require 'zucker/engine'
@@ -7,6 +5,8 @@ require 'zucker/version'
7
5
 
8
6
  Wirb.start
9
7
 
8
+ # TOKENIZER
9
+
10
10
  def tokenizer(filename)
11
11
  filename =~ /tokenizer_(.*)_spec\.rb/
12
12
  "Wirb.tokenize" + ($1 ? "(#{$1})" : "")
@@ -34,14 +34,62 @@ def tokens
34
34
  Wirb.tokenize(@a).to_a
35
35
  end
36
36
 
37
- def only19
38
- yield if RubyVersion == 1.9
37
+ # COLORIZER
38
+
39
+ shared_examples_for "a Wirb0 colorizer" do
40
+ it "creates good color codes based on original Wirb color symbols" do
41
+ # Wirb.get_color(:black).should match_colors(30)
42
+ Wirb.get_color(:light_purple).should match_colors(1,35)
43
+ Wirb.get_color(:brown_underline).should match_colors(4,33)
44
+ Wirb.get_color(:green_background).should match_colors(42)
45
+ end
46
+
47
+ it "colorizes strings based on original Wirb color symbols" do
48
+ Wirb.colorize_string('Mos Eisley', :blue).should match_colored_string('Mos Eisley', 34)
49
+ Wirb.colorize_string('Tatooine', :light_red).should match_colored_string('Tatooine', 1, 31)
50
+ Wirb.colorize_string('Bespin', :white).should match_colored_string('Bespin', 1, 37)
51
+ Wirb.colorize_string('Coruscant', :cyan_underline).should match_colored_string('Coruscant', 4, 36)
52
+ end
39
53
  end
40
54
 
41
- def only18
42
- yield if RubyVersion == 1.8
55
+ def extract_color_codes(string)
56
+ res = string.scan(/\e\[(?:\d+(?:;\d+)*)?m/).map do |code_match|
57
+ codes = []
58
+ code_match.scan(/((?:38|48);5;\d+)|((\d+);(\d+))|(\d+)|^$/) do |code_parts|
59
+ rgb_code, color_with_style, style, color, color_with_no_style = code_parts
60
+ codes << if rgb_code
61
+ rgb_code
62
+ elsif color_with_style
63
+ case style
64
+ when '0'
65
+ color
66
+ when '7'
67
+ (color.to_i+10).to_s
68
+ else
69
+ [style,color]
70
+ end
71
+ elsif color_with_no_style
72
+ color_with_no_style
73
+ else
74
+ '0'
75
+ end
76
+ end
77
+ codes
78
+ end.flatten
79
+ standardize_color_codes(res)
43
80
  end
44
81
 
82
+ def standardize_color_codes(codes)
83
+ codes = codes.map{|code| code.to_s}
84
+ codes = codes.sort.uniq # Order of codes doesn't matter, nor does repetition
85
+ if codes != ['0']
86
+ codes -= ['0'] # Code '0' doesn't matter, unless it's the only one
87
+ end
88
+ codes
89
+ end
90
+
91
+ # MATCHER
92
+
45
93
  # match regex in arrays (e.g. for object ids)
46
94
  RSpec::Matchers.define :be_like do |should_array|
47
95
  match do |got_array|
@@ -80,6 +128,69 @@ RSpec::Matchers.define :be_sorted_like do |should_array|
80
128
  end
81
129
  end
82
130
 
131
+ # Match the color codes from a string with an array of codes, e.g.
132
+ # "\e\[1m\e\[34m".should match_colors(1,34)
133
+ # Order of the codes does not matter, and repeated codes are ignored
134
+ # Codes like "\e[0;32" are equivalent to "\e[0m\e[32m"
135
+ # Codes like 0,34 and 34 are equivalent
136
+ # Codes like 7,34 and 44 are equivalent
137
+ RSpec::Matchers.define :match_colors do |*should_codes|
138
+ match do |got_string|
139
+ got_codes = extract_color_codes(got_string)
140
+ should_codes = standardize_color_codes(should_codes.flatten)
141
+
142
+ should_codes == got_codes
143
+ end
144
+
145
+ failure_message_for_should do |actual|
146
+ "expected that #{actual.inspect} would match the color codes #{should_codes.inspect}"
147
+ end
148
+
149
+ failure_message_for_should_not do |actual|
150
+ "expected that #{actual.inspect} would match the color codes #{should_codes.inspect}"
151
+ end
152
+
153
+ end
154
+
155
+ # Match an encoded string:
156
+ # Usage "\e[4m\e[33mStuff\e[0m".should match_colored_string('Stuff', 4, 33)
157
+ RSpec::Matchers.define :match_colored_string do |*should_spec|
158
+ match do |got_string|
159
+ should_string = should_spec.first
160
+ should_codes = should_spec[1..-1]
161
+
162
+ if matches=(got_string=~/^((?:\e\[\d+(?:;\d+)*m)+)(.*)(\e\[\d+(;\d+)*m)$/)
163
+ got_codes = $1
164
+ got_string = $2
165
+ got_terminating_code = $3
166
+ end
167
+
168
+
169
+ matches &&
170
+ should_string == got_string &&
171
+ got_codes.should(match_colors(should_codes)) &&
172
+ got_terminating_code.should(match_colors(0))
173
+ end
174
+
175
+ failure_message_for_should do |actual|
176
+ "expected that #{actual.inspect} would match the string #{should_spec.first.inspect}, colored with color codes #{should_spec[1..-1].inspect}"
177
+ end
178
+
179
+ failure_message_for_should_not do |actual|
180
+ "expected that #{actual.inspect} would not match the string #{should_spec.first}, colored with color codes #{should_spec[1..-1].inspect}"
181
+ end
182
+ end
183
+
184
+ # GENERAL
185
+
186
+ def only19
187
+ yield if RubyVersion == 1.9
188
+ end
189
+
190
+ def only18
191
+ yield if RubyVersion == 1.8
192
+ end
193
+
83
194
  # common regex patterns
84
195
  OBJECT_ID = /0x[0-9a-f]+/
85
196
 
@@ -4,21 +4,23 @@ require File.dirname(__FILE__) + "/lib/wirb/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "wirb"
7
- s.version = Wirb::VERSION
7
+ s.version = Wirb::VERSION.dup
8
8
  s.authors = ["Jan Lelis"]
9
9
  s.email = "mail@janlelis.de"
10
10
  s.homepage = "https://github.com/janlelis/wirb"
11
- s.summary = "Colorizes your irb results."
12
- s.description = "Colorizes your irb results. It's based on Wirble but only provides result highlighting. Just call Wirb.start and enjoy the colors ;)."
11
+ s.summary = "Wavy IRB: Colorizes irb results."
12
+ s.description = "Wavy IRB: Colorizes irb results. It originated from Wirble, but only provides result highlighting. Just call Wirb.start and enjoy the colors in your IRB ;). You can use it with your favorite colorizer engine. See README.rdoc for more details."
13
13
  s.required_rubygems_version = '>= 1.3.6'
14
14
  s.required_ruby_version = '>= 1.8.7'
15
- s.files = Dir.glob(%w[{lib,test,spec}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c}]) + %w{Rakefile wirb.gemspec .gemtest}
15
+ s.files = Dir.glob(%w[{lib,test,spec}/**/*.rb bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c} data/**/*.yml]) + %w{Rakefile wirb.gemspec .gemtest}
16
16
  s.extra_rdoc_files = ["README.rdoc", "COPYING.txt"]
17
17
  s.license = 'MIT'
18
18
  s.add_development_dependency 'rspec'
19
19
  s.add_development_dependency 'rspec-core'
20
20
  s.add_development_dependency 'rake'
21
21
  s.add_development_dependency 'zucker', '>= 11'
22
+ #s.add_development_dependency 'highline'
23
+ s.add_development_dependency 'paint'
22
24
 
23
25
  len = s.homepage.size
24
26
  s.post_install_message = \
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: wirb
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.2
5
+ version: 0.4.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jan Lelis
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-15 00:00:00 Z
13
+ date: 2011-07-07 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -56,7 +56,18 @@ dependencies:
56
56
  version: "11"
57
57
  type: :development
58
58
  version_requirements: *id004
59
- description: Colorizes your irb results. It's based on Wirble but only provides result highlighting. Just call Wirb.start and enjoy the colors ;).
59
+ - !ruby/object:Gem::Dependency
60
+ name: paint
61
+ prerelease: false
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ type: :development
69
+ version_requirements: *id005
70
+ description: "Wavy IRB: Colorizes irb results. It originated from Wirble, but only provides result highlighting. Just call Wirb.start and enjoy the colors in your IRB ;). You can use it with your favorite colorizer engine. See README.rdoc for more details."
60
71
  email: mail@janlelis.de
61
72
  executables: []
62
73
 
@@ -67,32 +78,46 @@ extra_rdoc_files:
67
78
  - COPYING.txt
68
79
  files:
69
80
  - lib/wirb.rb
70
- - lib/wirb/schema.rb
81
+ - lib/wirb/colorizer.rb
71
82
  - lib/wirb/tokenizer.rb
72
83
  - lib/wirb/wp.rb
73
- - lib/wirb/colors.rb
84
+ - lib/wirb/colorizer/wirble.rb
85
+ - lib/wirb/colorizer/paint.rb
86
+ - lib/wirb/colorizer/wirb0.rb
87
+ - lib/wirb/colorizer/wirb0_highline.rb
88
+ - lib/wirb/colorizer/wirb0_paint.rb
89
+ - lib/wirb/colorizer/highline.rb
74
90
  - lib/wirb/version.rb
75
91
  - lib/wirb/irb.rb
76
92
  - spec/tokenizer_rails_spec.rb
93
+ - spec/colorizer_wirb0_highline_spec.rb
77
94
  - spec/tokenizer_hash_spec.rb
95
+ - spec/colorizer_wirb0_paint_spec.rb
78
96
  - spec/tokenizer_number_spec.rb
79
97
  - spec/tokenizer_regexp_spec.rb
80
98
  - spec/tokenizer_array_spec.rb
99
+ - spec/colorizer_wirble_spec.rb
81
100
  - spec/tokenizer_enumerator_spec.rb
82
101
  - spec/spec_helper.rb
83
102
  - spec/tokenizer_misc_spec.rb
84
103
  - spec/tokenizer_nil_false_true_spec.rb
104
+ - spec/colorizer_highline_spec.rb
85
105
  - spec/tokenizer_symbol_spec.rb
86
106
  - spec/tokenizer_set_spec.rb
87
107
  - spec/tokenizer_object_spec.rb
108
+ - spec/colorizer_wirb0_spec.rb
88
109
  - spec/tokenizer_nested_spec.rb
89
110
  - spec/tokenizer_time_spec.rb
111
+ - spec/colorizer_spec.rb
90
112
  - spec/tokenizer_rubyvm_spec.rb
91
113
  - spec/tokenizer_string_spec.rb
114
+ - spec/colorizer_paint_spec.rb
92
115
  - spec/tokenizer_rubygems_spec.rb
93
116
  - COPYING.txt
94
117
  - README.rdoc
95
118
  - CHANGELOG.rdoc
119
+ - data/wirb/classic_wirb0.yml
120
+ - data/wirb/classic_paint.yml
96
121
  - Rakefile
97
122
  - wirb.gemspec
98
123
  - .gemtest
@@ -122,6 +147,6 @@ rubyforge_project:
122
147
  rubygems_version: 1.8.1
123
148
  signing_key:
124
149
  specification_version: 3
125
- summary: Colorizes your irb results.
150
+ summary: "Wavy IRB: Colorizes irb results."
126
151
  test_files: []
127
152
 
@@ -1,72 +0,0 @@
1
- module Wirb
2
- @schema = { # you can also use escape codes directly, e.g. "4;31"
3
-
4
- # container
5
- :open_hash => :light_green,
6
- :close_hash => :light_green,
7
- :open_array => :light_green,
8
- :close_array => :light_green,
9
-
10
- :open_set => :green,
11
- :close_set => :green,
12
-
13
- # delimiter colors
14
- :comma => :green,
15
- :refers => :green,
16
-
17
- # class
18
- :class => :light_green,
19
- :class_separator => :green,
20
- :object_class => :light_green,
21
-
22
- # object
23
- :open_object => :green,
24
- :object_description_prefix => :green,
25
- :object_description => :brown,
26
- :object_address_prefi => :brown_underline,
27
- :object_address => :brown_underline,
28
- :object_line_prefix => :brown_underline,
29
- :object_line => :brown_underline,
30
- :object_line_number => :brown_underline,
31
- :object_variable_prefix => :light_purple,
32
- :object_variable => :light_purple,
33
- :close_object => :green,
34
-
35
- # symbol
36
- :symbol_prefix => :yellow,
37
- :symbol => :yellow,
38
- :open_symbol_string => :brown,
39
- :symbol_string => :yellow,
40
- :close_symbol_string => :brown,
41
-
42
- # string
43
- :open_string => :light_gray,
44
- :string => :dark_gray,
45
- :close_string => :light_gray,
46
-
47
- # regexp
48
- :open_regexp => :light_blue,
49
- :regexp => :dark_gray,
50
- :close_regexp => :light_blue,
51
- :regexp_flags => :light_red,
52
-
53
- # number
54
- :number => :cyan,
55
- :range => :red,
56
- :open_rational => :light_cyan,
57
- :rational_separator => :light_cyan,
58
- :close_rational => :light_cyan,
59
-
60
- # misc
61
- :default => nil,
62
- :keyword => nil, # some lowercased word
63
- :time => :purple,
64
- :nil => :light_red,
65
- :false => :red,
66
- :true => :green,
67
- :gem_requirement_condition => :cyan,
68
- :gem_requirement_version => :light_cyan,
69
- }
70
- end
71
-
72
- # J-_-L