colorb 0.0.6.1 → 0.0.7
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/lib/colorb.rb +58 -50
 - metadata +3 -4
 
    
        data/lib/colorb.rb
    CHANGED
    
    | 
         @@ -40,72 +40,80 @@ class String 
     | 
|
| 
       40 
40 
     | 
    
         
             
                :standout  => 7
         
     | 
| 
       41 
41 
     | 
    
         
             
              }
         
     | 
| 
       42 
42 
     | 
    
         | 
| 
       43 
     | 
    
         
            -
              (Colors.keys + Extra.keys).each {|name|
         
     | 
| 
       44 
     | 
    
         
            -
                remove_method name rescue nil
         
     | 
| 
       45 
     | 
    
         
            -
              }
         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
43 
     | 
    
         
             
              attr_accessor :foreground, :background, :flags
         
     | 
| 
       48 
44 
     | 
    
         | 
| 
       49 
     | 
    
         
            -
               
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
                 
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
                result = (self.frozen? || !id.to_s.end_with?('!')) ? self.dup : self
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
                return __old_method_missing(id, *args, &block) unless Colors[name] || Extra[name]
         
     | 
| 
      
 45 
     | 
    
         
            +
              Colors.keys.each {|name|
         
     | 
| 
      
 46 
     | 
    
         
            +
                define_method name do
         
     | 
| 
      
 47 
     | 
    
         
            +
                  color(name)
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
       57 
49 
     | 
    
         | 
| 
       58 
     | 
    
         
            -
                 
     | 
| 
       59 
     | 
    
         
            -
                   
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
                    if !result.foreground
         
     | 
| 
       63 
     | 
    
         
            -
                      result.foreground = name
         
     | 
| 
       64 
     | 
    
         
            -
                    else
         
     | 
| 
       65 
     | 
    
         
            -
                      result.background = name
         
     | 
| 
       66 
     | 
    
         
            -
                    end
         
     | 
| 
       67 
     | 
    
         
            -
                  end
         
     | 
| 
       68 
     | 
    
         
            -
                elsif Extra[name]
         
     | 
| 
       69 
     | 
    
         
            -
                  result.flags ||= []
         
     | 
| 
      
 50 
     | 
    
         
            +
                define_method "#{name}!" do
         
     | 
| 
      
 51 
     | 
    
         
            +
                  color!(name)
         
     | 
| 
      
 52 
     | 
    
         
            +
                end
         
     | 
| 
      
 53 
     | 
    
         
            +
              }
         
     | 
| 
       70 
54 
     | 
    
         | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
                   
     | 
| 
       74 
     | 
    
         
            -
                    result.flags << name
         
     | 
| 
       75 
     | 
    
         
            -
                  end
         
     | 
| 
      
 55 
     | 
    
         
            +
              Extra.keys.each {|name|
         
     | 
| 
      
 56 
     | 
    
         
            +
                define_method name do
         
     | 
| 
      
 57 
     | 
    
         
            +
                  extra(name)
         
     | 
| 
       76 
58 
     | 
    
         
             
                end
         
     | 
| 
       77 
59 
     | 
    
         | 
| 
       78 
     | 
    
         
            -
                 
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
      
 60 
     | 
    
         
            +
                define_method "#{name}!" do
         
     | 
| 
      
 61 
     | 
    
         
            +
                  extra!(name)
         
     | 
| 
      
 62 
     | 
    
         
            +
                end
         
     | 
| 
      
 63 
     | 
    
         
            +
              }
         
     | 
| 
       80 
64 
     | 
    
         | 
| 
       81 
65 
     | 
    
         
             
              def color (code, second=nil)
         
     | 
| 
       82 
     | 
    
         
            -
                 
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
                self.dup.color!(code, seond)
         
     | 
| 
      
 66 
     | 
    
         
            +
                self.dup.color!(code, second)
         
     | 
| 
       85 
67 
     | 
    
         
             
              end
         
     | 
| 
       86 
68 
     | 
    
         | 
| 
       87 
69 
     | 
    
         
             
              def color! (code, second=nil)
         
     | 
| 
       88 
     | 
    
         
            -
                 
     | 
| 
       89 
     | 
    
         
            -
                  if code > 7
         
     | 
| 
       90 
     | 
    
         
            -
                    (self.flags ||= []) << (!self.foreground ? :bold : :blink)
         
     | 
| 
       91 
     | 
    
         
            -
                  end
         
     | 
| 
      
 70 
     | 
    
         
            +
                string = (self.frozen?) ? self.dup : self
         
     | 
| 
       92 
71 
     | 
    
         | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
      
 72 
     | 
    
         
            +
                if code.is_a?(Symbol) || code.is_a?(String)
         
     | 
| 
      
 73 
     | 
    
         
            +
                  name = code.to_sym
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                  if !string.foreground
         
     | 
| 
      
 76 
     | 
    
         
            +
                    string.foreground = name
         
     | 
| 
       95 
77 
     | 
    
         
             
                  else
         
     | 
| 
       96 
     | 
    
         
            -
                     
     | 
| 
      
 78 
     | 
    
         
            +
                    string.background = name
         
     | 
| 
       97 
79 
     | 
    
         
             
                  end
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
                  string.lazy? ? string : string.colorify!
         
     | 
| 
       98 
82 
     | 
    
         
             
                else
         
     | 
| 
       99 
     | 
    
         
            -
                  if  
     | 
| 
       100 
     | 
    
         
            -
                     
     | 
| 
      
 83 
     | 
    
         
            +
                  if code < 16
         
     | 
| 
      
 84 
     | 
    
         
            +
                    if code > 7
         
     | 
| 
      
 85 
     | 
    
         
            +
                      (string.flags ||= []) << (!string.foreground ? :bold : :blink)
         
     | 
| 
      
 86 
     | 
    
         
            +
                    end
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
                    if !string.foreground
         
     | 
| 
      
 89 
     | 
    
         
            +
                      string.foreground = code - (code > 7 ? 7 : 0)
         
     | 
| 
      
 90 
     | 
    
         
            +
                    else
         
     | 
| 
      
 91 
     | 
    
         
            +
                      string.background = code - (code > 7 ? 7 : 0)
         
     | 
| 
      
 92 
     | 
    
         
            +
                    end
         
     | 
| 
       101 
93 
     | 
    
         
             
                  else
         
     | 
| 
       102 
     | 
    
         
            -
                     
     | 
| 
      
 94 
     | 
    
         
            +
                    if !string.foreground
         
     | 
| 
      
 95 
     | 
    
         
            +
                      string.foreground = code
         
     | 
| 
      
 96 
     | 
    
         
            +
                    else
         
     | 
| 
      
 97 
     | 
    
         
            +
                      string.background = code
         
     | 
| 
      
 98 
     | 
    
         
            +
                    end
         
     | 
| 
       103 
99 
     | 
    
         
             
                  end
         
     | 
| 
       104 
100 
     | 
    
         
             
                end
         
     | 
| 
       105 
101 
     | 
    
         | 
| 
       106 
     | 
    
         
            -
                 
     | 
| 
      
 102 
     | 
    
         
            +
                string.color!(second) if second
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                string.lazy? ? string : string.colorify!
         
     | 
| 
      
 105 
     | 
    
         
            +
              end
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
              def extra (name)
         
     | 
| 
      
 108 
     | 
    
         
            +
                self.dup.extra!(name)
         
     | 
| 
      
 109 
     | 
    
         
            +
              end
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
              def extra! (name)
         
     | 
| 
      
 112 
     | 
    
         
            +
                string = (self.frozen?) ? self.dup : self
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
                (string.flags ||= []) << name
         
     | 
| 
       107 
115 
     | 
    
         | 
| 
       108 
     | 
    
         
            -
                 
     | 
| 
      
 116 
     | 
    
         
            +
                string.lazy? ? string : string.colorify!
         
     | 
| 
       109 
117 
     | 
    
         
             
              end
         
     | 
| 
       110 
118 
     | 
    
         | 
| 
       111 
119 
     | 
    
         
             
              def lazy;  @lazy = true; self end
         
     | 
| 
         @@ -118,9 +126,9 @@ class String 
     | 
|
| 
       118 
126 
     | 
    
         
             
              def self.colorify (string, foreground, background, flags)
         
     | 
| 
       119 
127 
     | 
    
         
             
                return string if ENV['NO_COLORS'] && !ENV['NO_COLORS'].empty?
         
     | 
| 
       120 
128 
     | 
    
         | 
| 
       121 
     | 
    
         
            -
                 
     | 
| 
      
 129 
     | 
    
         
            +
                string = string.dup
         
     | 
| 
       122 
130 
     | 
    
         | 
| 
       123 
     | 
    
         
            -
                 
     | 
| 
      
 131 
     | 
    
         
            +
                string.sub!(/^/, [
         
     | 
| 
       124 
132 
     | 
    
         
             
                  String.color!(foreground),
         
     | 
| 
       125 
133 
     | 
    
         
             
                  String.color!(background, true),
         
     | 
| 
       126 
134 
     | 
    
         
             
                  [flags].flatten.compact.uniq.map {|f|
         
     | 
| 
         @@ -128,9 +136,9 @@ class String 
     | 
|
| 
       128 
136 
     | 
    
         
             
                  }
         
     | 
| 
       129 
137 
     | 
    
         
             
                ].flatten.compact.join(''))
         
     | 
| 
       130 
138 
     | 
    
         | 
| 
       131 
     | 
    
         
            -
                 
     | 
| 
      
 139 
     | 
    
         
            +
                string.sub!(/$/, String.extra!(:clean))
         
     | 
| 
       132 
140 
     | 
    
         | 
| 
       133 
     | 
    
         
            -
                 
     | 
| 
      
 141 
     | 
    
         
            +
                string
         
     | 
| 
       134 
142 
     | 
    
         
             
              end
         
     | 
| 
       135 
143 
     | 
    
         | 
| 
       136 
144 
     | 
    
         
             
              def self.color! (what, bg=false)
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -5,9 +5,8 @@ version: !ruby/object:Gem::Version 
     | 
|
| 
       5 
5 
     | 
    
         
             
              segments: 
         
     | 
| 
       6 
6 
     | 
    
         
             
              - 0
         
     | 
| 
       7 
7 
     | 
    
         
             
              - 0
         
     | 
| 
       8 
     | 
    
         
            -
              -  
     | 
| 
       9 
     | 
    
         
            -
               
     | 
| 
       10 
     | 
    
         
            -
              version: 0.0.6.1
         
     | 
| 
      
 8 
     | 
    
         
            +
              - 7
         
     | 
| 
      
 9 
     | 
    
         
            +
              version: 0.0.7
         
     | 
| 
       11 
10 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       12 
11 
     | 
    
         
             
            authors: 
         
     | 
| 
       13 
12 
     | 
    
         
             
            - meh.
         
     | 
| 
         @@ -15,7 +14,7 @@ autorequire: 
     | 
|
| 
       15 
14 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       16 
15 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       17 
16 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
            date: 2011-02- 
     | 
| 
      
 17 
     | 
    
         
            +
            date: 2011-02-10 00:00:00 +01:00
         
     | 
| 
       19 
18 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       20 
19 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       21 
20 
     | 
    
         |