colorit 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,9 @@
1
1
 
2
+ ## 0.3.2
3
+
4
+ * added support for ~/.coloritrc (thanks to [winks](https://github.com/winks))
5
+ * print all used patterns on --debug
6
+
2
7
  ## 0.3.1
3
8
 
4
9
  * add colors only if STDOUT is a TTY
@@ -15,4 +20,4 @@
15
20
  ## 0.1.0
16
21
 
17
22
  * refactored to be able to pipe to colorit
18
- * removed hard dependency to Perl and `tail` (d'oh!)
23
+ * removed hard dependency to Perl and `tail` (d'oh!)
data/README.md CHANGED
@@ -22,6 +22,16 @@ tail -f /var/log/*.log | colorit --blue "==> (.*) <=="
22
22
 
23
23
  * `[sudo] gem install colorit`
24
24
 
25
+ ## ~/.coloritrc
26
+
27
+ You can put color:match pairs into a ~/.coloritrc file.
28
+
29
+ ```
30
+ red:2012
31
+ blue:whatever:the:key:is:still:only:blue
32
+ ```
33
+
34
+
25
35
  ## Author
26
36
 
27
37
  Original author: Dominik Liebler <liebler.dominik@googlemail.com>
@@ -3,6 +3,6 @@
3
3
  lib = ::File.expand_path('../../lib', __FILE__)
4
4
  require "#{lib}/colorit"
5
5
 
6
- colorit_command = Colorit::Command.new(Colorit::Config.new)
6
+ colorit_command = Colorit::Command.new(Colorit::Coloritrc.new)
7
7
  colorit_command.parse_options
8
8
  colorit_command.run(ARGF, $stdout)
@@ -8,7 +8,8 @@ module Colorit
8
8
  require 'colorit/version'
9
9
  require 'colorit/command'
10
10
  require 'colorit/config'
11
+ require 'colorit/coloritrc'
11
12
  end
12
13
  end
13
14
 
14
- Colorit.load_modules
15
+ Colorit.load_modules
@@ -0,0 +1,19 @@
1
+ module Colorit
2
+ class Coloritrc < Colorit::Config
3
+
4
+ def initialize(rcpath = '~/.coloritrc')
5
+ super()
6
+
7
+ rcpath = File.expand_path(rcpath)
8
+ if File.readable?(rcpath)
9
+ File.readlines(rcpath).each do |line|
10
+ key,val = line.strip.split(':', 2)
11
+
12
+ unless key.nil?
13
+ send(key, val) if respond_to?(key.to_sym)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -36,6 +36,12 @@ module Colorit
36
36
  def run(input, output)
37
37
  colors = prepare_patterns if output.tty?
38
38
 
39
+ if @config.debug?
40
+ output.puts "DEBUG: using patterns:"
41
+ output.puts(pretty_patterns)
42
+ end
43
+
44
+
39
45
  begin
40
46
  input.each do |line|
41
47
  if output.tty?
@@ -72,5 +78,18 @@ module Colorit
72
78
 
73
79
  colors
74
80
  end
81
+
82
+ # prepare patterns to be printed on the console in a pretty fashion
83
+ #
84
+ def pretty_patterns
85
+ colors = prepare_patterns
86
+
87
+ patterns = []
88
+ colors.each do |color,pattern|
89
+ patterns << "DEBUG: #{pattern.to_s.colorize(/.*/, color)}"
90
+ end
91
+
92
+ patterns.join("\n")
93
+ end
75
94
  end
76
95
  end
@@ -1,6 +1,6 @@
1
1
  module Colorit
2
2
  class Config
3
- attr_reader :colors, :debug
3
+ attr_reader :colors
4
4
 
5
5
  # add setters for every color
6
6
  #
@@ -19,8 +19,11 @@ module Colorit
19
19
  end
20
20
 
21
21
  def debug=(debug)
22
- # todo: ensure boolean here!
23
- @debug = debug
22
+ @debug = (debug == true)
23
+ end
24
+
25
+ def debug?
26
+ @debug
24
27
  end
25
28
  end
26
- end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module Colorit
2
- VERSION = %w(0 3 1)
2
+ VERSION = %w(0 3 2)
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colorit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
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-12-13 00:00:00.000000000 Z
12
+ date: 2012-12-14 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: colorit colors your console outputs using regular expressions to emphasize
15
15
  special words in e.g. logfiles
@@ -23,6 +23,7 @@ files:
23
23
  - bin/colorit
24
24
  - lib/colorit.rb
25
25
  - lib/colorit/config.rb
26
+ - lib/colorit/coloritrc.rb
26
27
  - lib/colorit/command.rb
27
28
  - lib/colorit/colors.rb
28
29
  - lib/colorit/version.rb