terminal_colors 0.0.0
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.
- checksums.yaml +7 -0
 - data/lib/terminal_colors/apply.rb +30 -0
 - data/lib/terminal_colors/invalid_label_error.rb +3 -0
 - data/lib/terminal_colors/palette.rb +24 -0
 - data/lib/terminal_colors.rb +3 -0
 - metadata +47 -0
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA1:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 9a4eb15311221d34c1db2c612d24a48c122d45aa
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 38d95ae8f22a5844121cc68d8154eb8e034bffb0
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: a18ed700d02e3c5c75b860f13562d00f76b23593e1db63e55a1c43234f7604edf83a9f61a3f7458f36ed1bd196b8e133e5541f765ad79150f30d42bc25104049
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: c742f755f924fd4631b8f95e1017baf36d8cda8e20be70f83cf0b6ef1cf949e948752b82af362118dd1ff96d9e5a31f179deae4f1901ed7d82573632c40a6e1e
         
     | 
| 
         @@ -0,0 +1,30 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module TerminalColors
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Apply
         
     | 
| 
      
 3 
     | 
    
         
            +
                def self.call string, fg: nil, bg: nil, bold: nil
         
     | 
| 
      
 4 
     | 
    
         
            +
                  output = String.new
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                  styled = fg || bg || bold
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                  if styled
         
     | 
| 
      
 9 
     | 
    
         
            +
                    fg = Palette.fetch fg if fg
         
     | 
| 
      
 10 
     | 
    
         
            +
                    bg = Palette.fetch bg if bg
         
     | 
| 
      
 11 
     | 
    
         
            +
                    bold_octet = bold ? '1' : '0'
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                    output << "\e[#{bold_octet}"
         
     | 
| 
      
 14 
     | 
    
         
            +
                    output << ";" if fg or bg
         
     | 
| 
      
 15 
     | 
    
         
            +
                    output << "3#{fg}" if fg
         
     | 
| 
      
 16 
     | 
    
         
            +
                    output << ";" if fg and bg
         
     | 
| 
      
 17 
     | 
    
         
            +
                    output << "4#{bg}" if bg
         
     | 
| 
      
 18 
     | 
    
         
            +
                    output << "m"
         
     | 
| 
      
 19 
     | 
    
         
            +
                  end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                  output << string
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                  if styled
         
     | 
| 
      
 24 
     | 
    
         
            +
                    output << "\e[0m"
         
     | 
| 
      
 25 
     | 
    
         
            +
                  end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                  output
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,24 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module TerminalColors
         
     | 
| 
      
 2 
     | 
    
         
            +
              module Palette
         
     | 
| 
      
 3 
     | 
    
         
            +
                def self.fetch label_or_index
         
     | 
| 
      
 4 
     | 
    
         
            +
                  index = get label_or_index
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                  if index.nil?
         
     | 
| 
      
 7 
     | 
    
         
            +
                    raise InvalidLabelError, "Invalid label #{label_or_index.inspect}"
         
     | 
| 
      
 8 
     | 
    
         
            +
                  end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                  index
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                def self.get label_or_index
         
     | 
| 
      
 14 
     | 
    
         
            +
                  case label_or_index
         
     | 
| 
      
 15 
     | 
    
         
            +
                  when Integer then label_or_index
         
     | 
| 
      
 16 
     | 
    
         
            +
                  else list.index label_or_index.to_sym
         
     | 
| 
      
 17 
     | 
    
         
            +
                  end
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                def self.list
         
     | 
| 
      
 21 
     | 
    
         
            +
                  @list ||= %i(black red green yellow blue magenta cyan white)
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,47 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: terminal_colors
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.0
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 7 
     | 
    
         
            +
            - Nathan Ladd
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2016-12-28 00:00:00.000000000 Z
         
     | 
| 
      
 12 
     | 
    
         
            +
            dependencies: []
         
     | 
| 
      
 13 
     | 
    
         
            +
            description: Apply ANSI terminal colors to strings
         
     | 
| 
      
 14 
     | 
    
         
            +
            email: nathanladd+github@gmail.com
         
     | 
| 
      
 15 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 16 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 17 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 18 
     | 
    
         
            +
            files:
         
     | 
| 
      
 19 
     | 
    
         
            +
            - lib/terminal_colors.rb
         
     | 
| 
      
 20 
     | 
    
         
            +
            - lib/terminal_colors/apply.rb
         
     | 
| 
      
 21 
     | 
    
         
            +
            - lib/terminal_colors/invalid_label_error.rb
         
     | 
| 
      
 22 
     | 
    
         
            +
            - lib/terminal_colors/palette.rb
         
     | 
| 
      
 23 
     | 
    
         
            +
            homepage: https://github.com/ntl/terminal-colors
         
     | 
| 
      
 24 
     | 
    
         
            +
            licenses:
         
     | 
| 
      
 25 
     | 
    
         
            +
            - MIT
         
     | 
| 
      
 26 
     | 
    
         
            +
            metadata: {}
         
     | 
| 
      
 27 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 28 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 29 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 30 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 31 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 32 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 33 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 34 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 35 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 36 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 37 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 38 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 39 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 40 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 41 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 42 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 43 
     | 
    
         
            +
            rubygems_version: 2.6.8
         
     | 
| 
      
 44 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 45 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
      
 46 
     | 
    
         
            +
            summary: Apply ANSI terminal colors to strings
         
     | 
| 
      
 47 
     | 
    
         
            +
            test_files: []
         
     |