matisse 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in matisse.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Patrick Oscity
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,58 @@
1
+ # Matisse
2
+
3
+ Matisse is a simple IRB output highlighter. It aims at resolving some issues that i personally had with Wirble. Because Wirble does a lot more than just colorizing the IRB output and i never used these features, i decided to bake my own. Matisse is the result of this effort and i hope you like it, too! This is how it looks like:
4
+
5
+ ![Screenshot](https://github.com/padde/matisse/raw/master/screenshot.png)
6
+
7
+ Feel free to send pull requests if you find an issue with Matisse (see section “Contributing“ below).
8
+
9
+ ## Installation
10
+
11
+ $ gem install matisse
12
+
13
+ ## Usage
14
+
15
+ To enable colorization, in your `~/.irbrc` (or during an IRB session) do:
16
+
17
+ require 'matisse/autoload'
18
+
19
+ or, if you prefer:
20
+
21
+ require 'matisse'
22
+
23
+ # maybe some other stuff
24
+
25
+ Matisse.enable
26
+
27
+ if you want to disable colorization later on, do:
28
+
29
+ Matisse.disable
30
+
31
+ ## To do
32
+
33
+ * Support the following classes:
34
+ * Time
35
+ * Date
36
+ * DateTime
37
+ * OpenStruct
38
+ * URI
39
+
40
+ * Find a system for managing (user defined) themes
41
+
42
+ * Support important Rails objects
43
+
44
+ * Better documentation (RDoc)
45
+
46
+ * Write tests
47
+
48
+ * Maybe
49
+ * Colorize output of `pp`
50
+ * Make spacing between Array/Hash elements customizable
51
+
52
+ ## Contributing
53
+
54
+ 1. Fork it
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
57
+ 4. Push to the branch (`git push origin my-new-feature`)
58
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ require 'matisse/version'
2
+ require 'matisse/colors'
3
+ require 'matisse/coreext/string'
4
+
5
+ colorizers_path = File.expand_path('../matisse/colorizers/*.rb', __FILE__)
6
+ Dir[colorizers_path].each{|file| require file }
7
+
8
+ module Matisse
9
+ def self.enable
10
+ ::IRB::Irb.class_eval do
11
+ alias :old_output_value :output_value
12
+
13
+ def output_value
14
+ printf @context.return_format, @context.last_value.inspect_colorized
15
+ end
16
+ end
17
+ end
18
+
19
+ def self.disable
20
+ ::IRB::Irb.class_eval do
21
+ alias :output_value :old_output_value
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ require 'matisse'
2
+
3
+ Matisse.enable
@@ -0,0 +1,7 @@
1
+ class Array
2
+ def inspect_colorized
3
+ res = '['.colorize(:array_delimiter)
4
+ res += map(&:inspect_colorized).join(','.colorize(:array_comma))
5
+ res += ']'.colorize(:array_delimiter)
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class Class
2
+ def inspect_colorized
3
+ inspect.colorize(:class)
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ class Enumerator
2
+ # TODO: eval is evil (hence the name), find a different approach!
3
+
4
+ def inspect_colorized
5
+ inspect =~ /^(#<)(Enumerator)(: )(.*)(:)([A-z_]+)((\()(.*)(\)))?(>)$/
6
+ res = $1.colorize(:object_delimiter ) # (#<)
7
+ res += $2.colorize(:class ) # (Enumerator)
8
+ res += $3.colorize(:object_separator ) # (: )
9
+ if $4.include?('Generator') # (.*)
10
+ res += ::Object.colorize_str($4)
11
+ else
12
+ res += eval($4).inspect_colorized
13
+ end
14
+ res += $5.colorize(:object_separator ) # (:)
15
+ res += $6.colorize(:enumerator ) # ([A-z_]+)
16
+ unless $7.nil? # ((\()(.*)(\)))?
17
+ res += $8.colorize(:enumerator ) # (\()
18
+ args = $9.split(',').map{|x|eval(x)} # (.*)
19
+ res += args.map(&:inspect_colorized).join(','.colorize(:enumerator_arg_separator))
20
+ res += $10.colorize(:enumerator ) # (\))
21
+ end
22
+ res += $11.colorize(:object_delimiter ) # (>)
23
+ end
24
+ end
@@ -0,0 +1,5 @@
1
+ class FalseClass
2
+ def inspect_colorized
3
+ inspect.colorize(:falseclass)
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ class Float
2
+ def inspect_colorized
3
+ if inspect =~ /^(\d+)(\.)(\d+)$/
4
+ res = $1.colorize(:float ) # (\d+)
5
+ res += $2.colorize(:float_separator ) # (\.)
6
+ res += $3.colorize(:float ) # (\d+)
7
+ return res
8
+ end
9
+
10
+ if inspect =~ /^(\d)(\.)(\d+)(e)([+-])(\d+)$/
11
+ res = $1.colorize(:float ) # (\d)
12
+ res += $2.colorize(:float_separator ) # (\.)
13
+ res += $3.colorize(:float ) # (\d+)
14
+ res += $4.colorize(:float_exp ) # (e)
15
+ res += $5.colorize(:float_plusminus ) # ([+-])
16
+ res += $6.colorize(:float ) # (\d+)
17
+ return res
18
+ end
19
+
20
+ inspect
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ class Hash
2
+ def inspect_colorized
3
+ res = '{'.colorize(:hash_delimiter)
4
+ res += map do |k,v|
5
+ k.inspect_colorized + '=>'.colorize(:hash_rocket) + v.inspect_colorized
6
+ end.join(','.colorize(:hash_comma))
7
+ res += '}'.colorize(:hash_delimiter)
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ class Matrix
2
+ def inspect_colorized
3
+ res = 'Matrix'.colorize(:matrix)
4
+ res += to_a.inspect_colorized
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ class NilClass
2
+ def inspect_colorized
3
+ inspect.colorize(:nilclass)
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class Numeric
2
+ def inspect_colorized
3
+ inspect.colorize(:numeric)
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ class Object
2
+ # Enumerator uses this method to colorize
3
+ # Enumerator::Generator (and other objects?)
4
+ def self.colorize_str str
5
+ if str =~ /^(#<)(.+)(:)(0x[0-9a-f]+)(>)$/
6
+ res = $1.colorize(:object_delimiter) # (#<)
7
+ classes = $2.split('::') # (*+)
8
+ classes.map!{|x| x.colorize(:class) }
9
+ res += classes.join('::'.colorize(:class_delimiter))
10
+ res += $3.colorize(:object_separator) # (:)
11
+ res += $4.colorize(:object_address ) # (0x[0-9a-f]+)
12
+ res += $5.colorize(:object_delimiter) # (>)
13
+ return res
14
+ end
15
+
16
+ str
17
+ end
18
+
19
+ def inspect_colorized
20
+ self.class.colorize_str self.inspect
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ class Proc
2
+ def inspect_colorized
3
+ inspect =~ /^(#<)([A-z]+)(:)(0x[0-9a-f]+)(@?)(\S*)( \(lambda\))?(>)$/
4
+ res = $1.colorize(:object_delimiter) # (#<)
5
+ res += $2.colorize(:class ) # ([A-z]+)
6
+ res += $3.colorize(:object_separator) # (:)
7
+ res += $4.colorize(:object_address ) # (0x[0-9a-f]+)
8
+ res += $5.colorize(:object_separator) # (@?)
9
+ res += $6.colorize(:object_from ) # (.*)
10
+ res += $7.colorize(:lambda ) unless $7.nil? # ( \(lambda\))
11
+ res += $8.colorize(:object_delimiter) # (>)
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ class Range
2
+ def inspect_colorized
3
+ dot_string = '..'
4
+ dot_string = '...' if exclude_end?
5
+ res = self.begin.inspect_colorized
6
+ res += dot_string.colorize(:range_dots)
7
+ res += self.end.inspect_colorized
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class Rational
2
+ def inspect_colorized
3
+ res = '('.colorize(:rational_delimiter)
4
+ res += numerator.inspect_colorized
5
+ res += '/'.colorize(:rational_slash)
6
+ res += denominator.inspect_colorized
7
+ res += ')'.colorize(:rational_delimiter)
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ class Regexp
2
+ def inspect_colorized
3
+ res = '/'.colorize(:regexp_delimiter)
4
+ res += self.inspect[1..-2].colorize(:regexp)
5
+ res += '/'.colorize(:regexp_delimiter)
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ class String
2
+ def inspect_colorized
3
+ res = '"'.colorize(:string_delimiter)
4
+ res += self.colorize(:string)
5
+ res += '"'.colorize(:string_delimiter)
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class Symbol
2
+ def inspect_colorized
3
+ self.inspect.colorize(:symbol)
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class TrueClass
2
+ def inspect_colorized
3
+ inspect.colorize(:trueclass)
4
+ end
5
+ end
@@ -0,0 +1,51 @@
1
+ module Matisse
2
+ COLORS = {
3
+ :array_delimiter => :light_green,
4
+ :array_comma => :blue,
5
+
6
+ :class => :yellow,
7
+ :class_delimiter => :light_yellow,
8
+
9
+ :enumerator => :red,
10
+ :enumerator_arg_separator => :blue,
11
+
12
+ :falseclass => :red,
13
+
14
+ :float => :cyan,
15
+ :float_exp => :green,
16
+ :float_plusminus => :cyan,
17
+ :float_separator => :green,
18
+
19
+ :hash_delimiter => :light_green,
20
+ :hash_comma => :blue,
21
+ :hash_rocket => :blue,
22
+
23
+ :lambda => :red,
24
+
25
+ :matrix => :blue,
26
+
27
+ :nilclass => :blue,
28
+
29
+ :numeric => :cyan,
30
+
31
+ :object_delimiter => :light_yellow,
32
+ :object_separator => :blue,
33
+ :object_address => :green,
34
+ :object_from => :light_blue,
35
+
36
+ :range_dots => :red,
37
+
38
+ :rational_delimiter => :light_yellow,
39
+ :rational_slash => :blue,
40
+
41
+ :regexp_delimiter => :light_red,
42
+ :regexp => :cyan,
43
+
44
+ :string_delimiter => :light_red,
45
+ :string => :cyan,
46
+
47
+ :symbol => :yellow,
48
+
49
+ :trueclass => :green
50
+ }
51
+ end
@@ -0,0 +1,13 @@
1
+ require 'colorize'
2
+
3
+ class String
4
+ alias :old_colorize :colorize
5
+
6
+ def colorize color
7
+ if ::Matisse::COLORS.include? color
8
+ return old_colorize ::Matisse::COLORS[color]
9
+ end
10
+
11
+ return old_colorize color
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Matisse
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'matisse/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ # development dependencies
8
+ gem.add_development_dependency "rake"
9
+
10
+ # dependencies
11
+ gem.add_dependency "colorize"
12
+
13
+ gem.name = "matisse"
14
+ gem.version = Matisse::VERSION
15
+ gem.authors = ["Patrick Oscity"]
16
+ gem.email = ["patrick.oscity@gmail.com"]
17
+ gem.description = "Matisse is a simple IRB output highlighter that just works."
18
+ gem.summary = "IRB output highlighter"
19
+ gem.homepage = "http://rubygems.org/gems/matisse"
20
+
21
+ gem.files = `git ls-files`.split($/)
22
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
23
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
24
+ gem.require_paths = ["lib"]
25
+ end
Binary file
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: matisse
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Patrick Oscity
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: colorize
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Matisse is a simple IRB output highlighter that just works.
47
+ email:
48
+ - patrick.oscity@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - lib/matisse.rb
59
+ - lib/matisse/autoload.rb
60
+ - lib/matisse/colorizers/array.rb
61
+ - lib/matisse/colorizers/class.rb
62
+ - lib/matisse/colorizers/enumerator.rb
63
+ - lib/matisse/colorizers/falseclass.rb
64
+ - lib/matisse/colorizers/float.rb
65
+ - lib/matisse/colorizers/hash.rb
66
+ - lib/matisse/colorizers/matrix.rb
67
+ - lib/matisse/colorizers/nilclass.rb
68
+ - lib/matisse/colorizers/numeric.rb
69
+ - lib/matisse/colorizers/object.rb
70
+ - lib/matisse/colorizers/proc.rb
71
+ - lib/matisse/colorizers/range.rb
72
+ - lib/matisse/colorizers/rational.rb
73
+ - lib/matisse/colorizers/regexp.rb
74
+ - lib/matisse/colorizers/string.rb
75
+ - lib/matisse/colorizers/symbol.rb
76
+ - lib/matisse/colorizers/trueclass.rb
77
+ - lib/matisse/colors.rb
78
+ - lib/matisse/coreext/string.rb
79
+ - lib/matisse/version.rb
80
+ - matisse.gemspec
81
+ - screenshot.png
82
+ homepage: http://rubygems.org/gems/matisse
83
+ licenses: []
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ segments:
95
+ - 0
96
+ hash: 3799194178502448459
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ segments:
104
+ - 0
105
+ hash: 3799194178502448459
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 1.8.24
109
+ signing_key:
110
+ specification_version: 3
111
+ summary: IRB output highlighter
112
+ test_files: []