term-ansicolor 0.0.4 → 1.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.
- data/CHANGES +4 -0
- data/README.en +4 -1
- data/Rakefile +47 -38
- data/VERSION +1 -1
- data/examples/example.rb +9 -1
- data/lib/term/ansicolor.rb +80 -63
- metadata +8 -7
    
        data/CHANGES
    CHANGED
    
    | @@ -1,3 +1,7 @@ | |
| 1 | 
            +
            2004-12-23 * 1.0.0 * Added Term::ANSIColor.coloring[?=]? methods.
         | 
| 2 | 
            +
                                 Thanks Thomas Husterer for the contribution.
         | 
| 3 | 
            +
                               * Minor cleanup of code.
         | 
| 4 | 
            +
                               * Documented visible methods in the module.
         | 
| 1 5 | 
             
            2004-09-28 * 0.0.4 * First release on Rubyforge
         | 
| 2 6 | 
             
                               * Supports Rubygems now
         | 
| 3 7 | 
             
            2003-10-09 * 0.0.3 * Added uncolored method as suggested by
         | 
    
        data/README.en
    CHANGED
    
    | @@ -5,12 +5,15 @@ Just type into the command line as root: | |
| 5 5 |  | 
| 6 6 | 
             
            # ruby install.rb
         | 
| 7 7 |  | 
| 8 | 
            +
            Or if you prefer using Rake, try:
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            # rake install
         | 
| 11 | 
            +
             | 
| 8 12 | 
             
            Documentation
         | 
| 9 13 | 
             
            =============
         | 
| 10 14 |  | 
| 11 15 | 
             
            Look into examples/example.rb to get an idea how this library is used.
         | 
| 12 16 |  | 
| 13 | 
            -
             | 
| 14 17 | 
             
            Author
         | 
| 15 18 | 
             
            ======
         | 
| 16 19 |  | 
    
        data/Rakefile
    CHANGED
    
    | @@ -8,65 +8,74 @@ include Config | |
| 8 8 | 
             
            PKG_NAME = 'term-ansicolor'
         | 
| 9 9 | 
             
            PKG_VERSION = File.read('VERSION').chomp
         | 
| 10 10 | 
             
            PKG_FILES = Dir.glob("**/*").delete_if { |item|
         | 
| 11 | 
            -
             | 
| 11 | 
            +
              item.include?("CVS") or item.include?("pkg")
         | 
| 12 12 | 
             
            }
         | 
| 13 13 |  | 
| 14 14 | 
             
            desc "Installing library"
         | 
| 15 15 | 
             
            task :install  do
         | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 16 | 
            +
              libdir = CONFIG["sitelibdir"]
         | 
| 17 | 
            +
              dest = File.join(libdir, 'term')
         | 
| 18 | 
            +
              install('lib/term/ansicolor.rb', dest)
         | 
| 19 19 | 
             
            end
         | 
| 20 20 |  | 
| 21 | 
            -
             | 
| 21 | 
            +
            desc "Making rdoc documentation"
         | 
| 22 | 
            +
            task :doc do
         | 
| 23 | 
            +
              load "make_doc.rb"
         | 
| 24 | 
            +
            end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            task :clean do
         | 
| 27 | 
            +
            	rm_r 'doc'
         | 
| 28 | 
            +
            end
         | 
| 22 29 |  | 
| 23 | 
            -
             | 
| 30 | 
            +
            spec = Gem::Specification.new do |s|
         | 
| 31 | 
            +
            	#### Basic information.
         | 
| 24 32 |  | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 27 | 
            -
             | 
| 28 | 
            -
             | 
| 33 | 
            +
            	s.name = 'term-ansicolor'
         | 
| 34 | 
            +
            	s.version = PKG_VERSION
         | 
| 35 | 
            +
            	s.summary = "Ruby library that colors strings using ANSI escape sequences"
         | 
| 36 | 
            +
            	s.description = ""
         | 
| 29 37 |  | 
| 30 | 
            -
             | 
| 38 | 
            +
            	#### Dependencies and requirements.
         | 
| 31 39 |  | 
| 32 | 
            -
             | 
| 33 | 
            -
             | 
| 40 | 
            +
            	#s.add_dependency('log4r', '> 1.0.4')
         | 
| 41 | 
            +
            	#s.requirements << ""
         | 
| 34 42 |  | 
| 35 | 
            -
             | 
| 43 | 
            +
            	s.files = PKG_FILES
         | 
| 36 44 |  | 
| 37 | 
            -
             | 
| 45 | 
            +
            	#### C code extensions.
         | 
| 38 46 |  | 
| 39 | 
            -
             | 
| 47 | 
            +
            	#s.extensions << "ext/extconf.rb"
         | 
| 40 48 |  | 
| 41 | 
            -
             | 
| 49 | 
            +
            	#### Load-time details: library and application (you will need one or both).
         | 
| 42 50 |  | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 51 | 
            +
            	s.require_path = 'lib'                         # Use these for libraries.
         | 
| 52 | 
            +
            	s.autorequire = 'term/ansicolor'
         | 
| 45 53 |  | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 54 | 
            +
            	#s.bindir = "bin"                               # Use these for applications.
         | 
| 55 | 
            +
            	#s.executables = ["bla.rb"]
         | 
| 56 | 
            +
            	#s.default_executable = "bla.rb"
         | 
| 49 57 |  | 
| 50 | 
            -
             | 
| 58 | 
            +
            	#### Documentation and testing.
         | 
| 51 59 |  | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
                #  '--line-numbers'
         | 
| 60 | 
            +
            	#s.has_rdoc = true
         | 
| 61 | 
            +
            	#s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
         | 
| 62 | 
            +
            	#s.rdoc_options <<
         | 
| 63 | 
            +
            	#	'--title' <<  'Term::ANSIColor -- ANSI color escape sequences' <<
         | 
| 64 | 
            +
            	# '--main' << 'README' <<
         | 
| 65 | 
            +
            	#	'--line-numbers'
         | 
| 59 66 |  | 
| 60 | 
            -
             | 
| 67 | 
            +
            	#### Author and project details.
         | 
| 61 68 |  | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 64 | 
            -
             | 
| 65 | 
            -
             | 
| 69 | 
            +
            	s.author = "Florian Frank"
         | 
| 70 | 
            +
            	s.email = "flori@ping.de"
         | 
| 71 | 
            +
            	s.homepage = "http://term-ansicolor.rubyforge.org"
         | 
| 72 | 
            +
            	s.rubyforge_project = "term-ansicolor"
         | 
| 66 73 | 
             
            end
         | 
| 67 74 |  | 
| 68 75 | 
             
            Rake::GemPackageTask.new(spec) do |pkg|
         | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 76 | 
            +
              pkg.need_tar = true
         | 
| 77 | 
            +
              pkg.package_files += PKG_FILES
         | 
| 71 78 | 
             
            end
         | 
| 72 | 
            -
             | 
| 79 | 
            +
             | 
| 80 | 
            +
            task :release => :package
         | 
| 81 | 
            +
                # vim: set noet sw=2 ts=2:
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0.0 | 
| 1 | 
            +
            1.0.0
         | 
    
        data/examples/example.rb
    CHANGED
    
    | @@ -14,6 +14,14 @@ print Color.green + "green" + Color.clear, "\n" | |
| 14 14 | 
             
            print Color.on_red(Color.green("green")), "\n"
         | 
| 15 15 | 
             
            print Color.yellow { Color.on_black { "yellow on_black" } }, "\n\n"
         | 
| 16 16 |  | 
| 17 | 
            +
            # Or shortcut Term::ANSIColor by assignment:
         | 
| 18 | 
            +
            c = Term::ANSIColor
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            print c.red, c.bold, "No Namespace cluttering (alternative):", c.clear, "\n"
         | 
| 21 | 
            +
            print c.green + "green" + c.clear, "\n"
         | 
| 22 | 
            +
            print c.on_red(c.green("green")), "\n"
         | 
| 23 | 
            +
            print c.yellow { c.on_black { "yellow on_black" } }, "\n\n"
         | 
| 24 | 
            +
             | 
| 17 25 | 
             
            # Anyway, I don't define any of Term::ANSIColor's methods in this example
         | 
| 18 26 | 
             
            # and I want to keep it short:
         | 
| 19 27 | 
             
            include Term::ANSIColor
         | 
| @@ -31,7 +39,7 @@ print clear, "clear", reset, reset, "reset", reset, | |
| 31 39 | 
             
              on_blue, "on_blue", reset, on_magenta, "on_magenta", reset,
         | 
| 32 40 | 
             
              on_cyan, "on_cyan", reset, on_white, "on_white", reset, "|\n\n"
         | 
| 33 41 |  | 
| 34 | 
            -
            print red, bold, "Usage as unary  | 
| 42 | 
            +
            print red, bold, "Usage as unary argument methods:", reset, "\n"
         | 
| 35 43 | 
             
            print clear("clear"), reset("reset"), bold("bold"), dark("dark"),
         | 
| 36 44 | 
             
              underscore("underscore"), blink("blink"), negative("negative"),
         | 
| 37 45 | 
             
              concealed("concealed"), "|\n",
         | 
    
        data/lib/term/ansicolor.rb
    CHANGED
    
    | @@ -1,78 +1,95 @@ | |
| 1 1 | 
             
            module Term
         | 
| 2 | 
            +
              module ANSIColor
         | 
| 3 | 
            +
                @@attributes = [
         | 
| 4 | 
            +
                  [ :clear        ,   0 ], 
         | 
| 5 | 
            +
                  [ :reset        ,   0 ],     # synonym for :clear
         | 
| 6 | 
            +
                  [ :bold         ,   1 ], 
         | 
| 7 | 
            +
                  [ :dark         ,   2 ], 
         | 
| 8 | 
            +
                  [ :italic       ,   3 ],     # not widely implemented
         | 
| 9 | 
            +
                  [ :underline    ,   4 ], 
         | 
| 10 | 
            +
                  [ :underscore   ,   4 ],     # synonym for :underline
         | 
| 11 | 
            +
                  [ :blink        ,   5 ], 
         | 
| 12 | 
            +
                  [ :rapid_blink  ,   6 ],     # not widely implemented
         | 
| 13 | 
            +
                  [ :negative     ,   7 ],     # no reverse because of String#reverse
         | 
| 14 | 
            +
                  [ :concealed    ,   8 ], 
         | 
| 15 | 
            +
                  [ :strikethrough,   9 ],     # not widely implemented
         | 
| 16 | 
            +
                  [ :black        ,  30 ], 
         | 
| 17 | 
            +
                  [ :red          ,  31 ], 
         | 
| 18 | 
            +
                  [ :green        ,  32 ], 
         | 
| 19 | 
            +
                  [ :yellow       ,  33 ], 
         | 
| 20 | 
            +
                  [ :blue         ,  34 ], 
         | 
| 21 | 
            +
                  [ :magenta      ,  35 ], 
         | 
| 22 | 
            +
                  [ :cyan         ,  36 ], 
         | 
| 23 | 
            +
                  [ :white        ,  37 ], 
         | 
| 24 | 
            +
                  [ :on_black     ,  40 ], 
         | 
| 25 | 
            +
                  [ :on_red       ,  41 ], 
         | 
| 26 | 
            +
                  [ :on_green     ,  42 ], 
         | 
| 27 | 
            +
                  [ :on_yellow    ,  43 ], 
         | 
| 28 | 
            +
                  [ :on_blue      ,  44 ], 
         | 
| 29 | 
            +
                  [ :on_magenta   ,  45 ], 
         | 
| 30 | 
            +
                  [ :on_cyan      ,  46 ], 
         | 
| 31 | 
            +
                  [ :on_white     ,  47 ], 
         | 
| 32 | 
            +
                ]
         | 
| 2 33 |  | 
| 3 | 
            -
            module | 
| 34 | 
            +
                # Returns true, if the coloring function of this module
         | 
| 35 | 
            +
                # is switched on, false otherwise.
         | 
| 36 | 
            +
                def self.coloring?
         | 
| 37 | 
            +
                  @@coloring
         | 
| 38 | 
            +
                end
         | 
| 4 39 |  | 
| 5 | 
            -
             | 
| 6 | 
            -
                 | 
| 7 | 
            -
                 | 
| 8 | 
            -
                 | 
| 9 | 
            -
             | 
| 10 | 
            -
                 | 
| 11 | 
            -
                 | 
| 12 | 
            -
                [ :underscore   ,   4 ],     # synonym for :underline
         | 
| 13 | 
            -
                [ :blink        ,   5 ], 
         | 
| 14 | 
            -
                [ :rapid_blink  ,   6 ],     # not widely implemented
         | 
| 15 | 
            -
                [ :negative     ,   7 ],     # no reverse because of String#reverse
         | 
| 16 | 
            -
                [ :concealed    ,   8 ], 
         | 
| 17 | 
            -
                [ :strikethrough,   9 ],     # not widely implemented
         | 
| 18 | 
            -
                [ :black        ,  30 ], 
         | 
| 19 | 
            -
                [ :red          ,  31 ], 
         | 
| 20 | 
            -
                [ :green        ,  32 ], 
         | 
| 21 | 
            -
                [ :yellow       ,  33 ], 
         | 
| 22 | 
            -
                [ :blue         ,  34 ], 
         | 
| 23 | 
            -
                [ :magenta      ,  35 ], 
         | 
| 24 | 
            -
                [ :cyan         ,  36 ], 
         | 
| 25 | 
            -
                [ :white        ,  37 ], 
         | 
| 26 | 
            -
                [ :on_black     ,  40 ], 
         | 
| 27 | 
            -
                [ :on_red       ,  41 ], 
         | 
| 28 | 
            -
                [ :on_green     ,  42 ], 
         | 
| 29 | 
            -
                [ :on_yellow    ,  43 ], 
         | 
| 30 | 
            -
                [ :on_blue      ,  44 ], 
         | 
| 31 | 
            -
                [ :on_magenta   ,  45 ], 
         | 
| 32 | 
            -
                [ :on_cyan      ,  46 ], 
         | 
| 33 | 
            -
                [ :on_white     ,  47 ], 
         | 
| 34 | 
            -
              ]
         | 
| 40 | 
            +
                # Turns the coloring on or off globally, so you can easily do
         | 
| 41 | 
            +
                # this for example:
         | 
| 42 | 
            +
                #  Term::ANSIColor::coloring = STDOUT.isatty
         | 
| 43 | 
            +
                def self.coloring=(val)
         | 
| 44 | 
            +
                  @@coloring = val
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
                self.coloring = true
         | 
| 35 47 |  | 
| 36 | 
            -
             | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 | 
            -
                        result =  | 
| 48 | 
            +
                @@attributes.each do |c, v|
         | 
| 49 | 
            +
                  eval %Q{
         | 
| 50 | 
            +
                      def #{c}(string = nil)
         | 
| 51 | 
            +
                        result = ''
         | 
| 52 | 
            +
                        result << "\e[#{v}m" if @@coloring 
         | 
| 40 53 | 
             
                        if block_given?
         | 
| 41 | 
            -
             | 
| 42 | 
            -
                            result << "\e[0m"
         | 
| 54 | 
            +
                          result << yield
         | 
| 43 55 | 
             
                        elsif string
         | 
| 44 | 
            -
             | 
| 45 | 
            -
                            result << "\e[0m"
         | 
| 56 | 
            +
                          result << string
         | 
| 46 57 | 
             
                        elsif respond_to?(:to_str)
         | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 58 | 
            +
                          result << self
         | 
| 59 | 
            +
                        else
         | 
| 60 | 
            +
                          return result #only switch on
         | 
| 49 61 | 
             
                        end
         | 
| 50 | 
            -
                         | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 62 | 
            +
                        result << "\e[0m" if @@coloring
         | 
| 63 | 
            +
                        result
         | 
| 64 | 
            +
                      end
         | 
| 65 | 
            +
                  }
         | 
| 66 | 
            +
                end
         | 
| 54 67 |  | 
| 55 | 
            -
             | 
| 68 | 
            +
                # Regular expression that is used to scan for ANSI-sequences. It is used to
         | 
| 69 | 
            +
                # uncolor strins.
         | 
| 70 | 
            +
                COLORED_REGEXP = /\e\[([34][0-7]|[0-9])m/
         | 
| 56 71 |  | 
| 57 | 
            -
             | 
| 58 | 
            -
                 | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 61 | 
            -
             | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 64 | 
            -
             | 
| 65 | 
            -
             | 
| 72 | 
            +
                # Returns an uncolored version of the string, that is all
         | 
| 73 | 
            +
                # ANSI-sequences are stripped from the string.
         | 
| 74 | 
            +
                def uncolored(string = nil) # :yields:
         | 
| 75 | 
            +
                  if block_given?
         | 
| 76 | 
            +
                    yield.gsub(COLORED_REGEXP, '')
         | 
| 77 | 
            +
                  elsif string
         | 
| 78 | 
            +
                    string.gsub(COLORED_REGEXP, '')
         | 
| 79 | 
            +
                  elsif respond_to?(:to_str)
         | 
| 80 | 
            +
                    gsub(COLORED_REGEXP, '')
         | 
| 81 | 
            +
                  else
         | 
| 82 | 
            +
                    ''
         | 
| 83 | 
            +
                  end
         | 
| 66 84 | 
             
                end
         | 
| 67 | 
            -
              end
         | 
| 68 85 |  | 
| 69 | 
            -
             | 
| 70 | 
            -
                
         | 
| 71 | 
            -
              def attributes
         | 
| 72 | 
            -
                @@attributes.map { |c| c[0] }
         | 
| 73 | 
            -
              end
         | 
| 74 | 
            -
                
         | 
| 75 | 
            -
            end
         | 
| 86 | 
            +
                module_function
         | 
| 76 87 |  | 
| 88 | 
            +
                # Returns an array of all Term::ANSIColor attributes as symbols.
         | 
| 89 | 
            +
                def attributes
         | 
| 90 | 
            +
                  @@attributes.map { |c| c.first }
         | 
| 91 | 
            +
                end
         | 
| 92 | 
            +
                extend self
         | 
| 93 | 
            +
              end
         | 
| 77 94 | 
             
            end
         | 
| 78 95 | 
             
                # vim: set et sw=2 ts=2:
         | 
    
        metadata
    CHANGED
    
    | @@ -1,19 +1,18 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 | 
            -
            rubygems_version: 0.8. | 
| 2 | 
            +
            rubygems_version: 0.8.10
         | 
| 3 3 | 
             
            specification_version: 1
         | 
| 4 4 | 
             
            name: term-ansicolor
         | 
| 5 5 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 6 | 
            -
              version: 0.0 | 
| 7 | 
            -
            date:  | 
| 6 | 
            +
              version: 1.0.0
         | 
| 7 | 
            +
            date: 2005-04-15
         | 
| 8 8 | 
             
            summary: Ruby library that colors strings using ANSI escape sequences
         | 
| 9 9 | 
             
            require_paths: 
         | 
| 10 10 | 
             
              - lib
         | 
| 11 | 
            -
            author: Florian Frank
         | 
| 12 11 | 
             
            email: flori@ping.de
         | 
| 13 12 | 
             
            homepage: http://term-ansicolor.rubyforge.org
         | 
| 14 13 | 
             
            rubyforge_project: term-ansicolor
         | 
| 15 14 | 
             
            description: ''
         | 
| 16 | 
            -
            autorequire: 
         | 
| 15 | 
            +
            autorequire: term/ansicolor
         | 
| 17 16 | 
             
            default_executable: 
         | 
| 18 17 | 
             
            bindir: bin
         | 
| 19 18 | 
             
            has_rdoc: false
         | 
| @@ -25,8 +24,12 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement | |
| 25 24 | 
             
                    version: 0.0.0
         | 
| 26 25 | 
             
              version: 
         | 
| 27 26 | 
             
            platform: ruby
         | 
| 27 | 
            +
            authors: 
         | 
| 28 | 
            +
              - Florian Frank
         | 
| 28 29 | 
             
            files: 
         | 
| 29 30 | 
             
              - examples
         | 
| 31 | 
            +
              - examples/cdiff.rb
         | 
| 32 | 
            +
              - examples/example.rb
         | 
| 30 33 | 
             
              - CHANGES
         | 
| 31 34 | 
             
              - GPL
         | 
| 32 35 | 
             
              - README.en
         | 
| @@ -34,8 +37,6 @@ files: | |
| 34 37 | 
             
              - VERSION
         | 
| 35 38 | 
             
              - install.rb
         | 
| 36 39 | 
             
              - lib
         | 
| 37 | 
            -
              - examples/cdiff.rb
         | 
| 38 | 
            -
              - examples/example.rb
         | 
| 39 40 | 
             
              - lib/term
         | 
| 40 41 | 
             
              - lib/term/ansicolor.rb
         | 
| 41 42 | 
             
            test_files: []
         |