Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit e6d124af246385b07132a1b26f5a45768ab0a6b2 @flori committed Jul 23, 2009
Showing with 861 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +22 −0 CHANGES
  3. +340 −0 COPYING
  4. +31 −0 README
  5. +86 −0 Rakefile
  6. +1 −0 VERSION
  7. +119 −0 doc-main.txt
  8. +19 −0 examples/cdiff.rb
  9. +89 −0 examples/example.rb
  10. +15 −0 install.rb
  11. +102 −0 lib/term/ansicolor.rb
  12. 0 lib/term/ansicolor/.keep
  13. +10 −0 lib/term/ansicolor/version.rb
  14. +4 −0 make_doc.rb
  15. +20 −0 term-ansicolor.gemspec
@@ -0,0 +1,3 @@
+*.sw[pon]
+coverage
+pkg
22 CHANGES
@@ -0,0 +1,22 @@
+2009-07-23 - 1.0.4 * Some cleanup.
+ * Build a gemspec file.
+2007-10-05 - 1.0.3 * Better documentation + some code clean up.
+ * Deleted autorequire from Rakefile.
+2005-11-12 - 1.0.2 * Added DESTDIR in front of install path to make repackaging
+ easier. Thanks to Tilman Sauerbeck <tilman@code-monkey.de>
+ for giving the hint.
+2005-09-05 - 1.0.1 * Fixed install bug in Rakefile, reported by
+ Martin DeMello <martindemello@gmail.com>
+2004-12-23 - 1.0.0 * Added Term::ANSIColor.coloring[?=]? methods.
+ Thanks, Thomas Husterer for the contribution.
+ * Minor cleanup of code.
+ * Documented visible methods in the module.
+2004-09-28 - 0.0.4 * First release on Rubyforge
+ * Supports Rubygems now
+2003-10-09 - 0.0.3 * Added uncolored method as suggested by
+ Thomas Husterer <Thomas.Husterer@heidelberg.com>
+ * Added attribute methods with string arguments
+ * Deleted now unused files
+2002-07-27 - 0.0.2 * Minor Code Cleanup
+ * Added cdiff.rb
+2002-06-12 - 0.0.1 * Initial Release
340 COPYING

Large diffs are not rendered by default.

Oops, something went wrong.
31 README
@@ -0,0 +1,31 @@
+Installation
+============
+
+Just type into the command line as root:
+
+# ruby install.rb
+
+Or if you prefer using Rake, try:
+
+# rake install
+
+Or if you want to use rubygems just type this and rubygems fetches the gem and
+installs it for you:
+
+# gem install term-ansicolor
+
+Documentation
+=============
+
+Look into examples/example.rb to get an idea how this library is used.
+
+Author
+======
+
+Florian Frank <flori@ping.de>
+
+License
+=======
+
+GNU General Public License (GPL)
+
@@ -0,0 +1,86 @@
+begin
+ require 'rake/gempackagetask'
+rescue LoadError
+end
+require 'rake/clean'
+require 'rbconfig'
+include Config
+
+PKG_NAME = 'term-ansicolor'
+PKG_VERSION = File.read('VERSION').chomp
+PKG_FILES = FileList['**/*'].exclude(/(CVS|\.svn|pkg|coverage|doc)/)
+CLEAN.include 'coverage', 'doc'
+
+desc "Installing library"
+task :install do
+ ruby 'install.rb'
+end
+
+desc "Creating documentation"
+task :doc do
+ ruby 'make_doc.rb'
+end
+
+
+if defined? Gem
+ spec_src =<<GEM
+# -*- encoding: utf-8 -*-
+Gem::Specification.new do |s|
+ s.name = '#{PKG_NAME}'
+ s.version = '#{PKG_VERSION}'
+ s.summary = "Ruby library that colors strings using ANSI escape sequences"
+ s.description = ""
+
+ s.files = #{PKG_FILES.to_a.sort.inspect}
+
+ s.require_path = 'lib'
+
+ s.has_rdoc = true
+ s.extra_rdoc_files << 'doc-main.txt'
+ s.rdoc_options << '--main' << 'doc-main.txt'
+
+ s.author = "Florian Frank"
+ s.email = "flori@ping.de"
+ s.homepage = "http://#{PKG_NAME}.rubyforge.org"
+ s.rubyforge_project = '#{PKG_NAME}'
+end
+GEM
+
+ desc 'Create a gemspec file'
+ task :gemspec do
+ File.open("#{PKG_NAME}.gemspec", 'w') do |f|
+ f.puts spec_src
+ end
+ end
+
+ spec = eval(spec_src)
+ Rake::GemPackageTask.new(spec) do |pkg|
+ pkg.need_tar = true
+ pkg.package_files += PKG_FILES
+ end
+end
+
+desc m = "Writing version information for #{PKG_VERSION}"
+task :version do
+ puts m
+ File.open(File.join('lib', 'term', 'ansicolor', 'version.rb'), 'w') do |v|
+ v.puts <<EOT
+module Term
+ module ANSIColor
+ # Term::ANSIColor version
+ VERSION = '#{PKG_VERSION}'
+ VERSION_ARRAY = VERSION.split(/\\./).map { |x| x.to_i } # :nodoc:
+ VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
+ VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
+ VERSION_BUILD = VERSION_ARRAY[2] # :nodoc:
+ end
+end
+EOT
+ end
+end
+
+desc "Default"
+task :default => [ :version, :gemspec ]
+
+desc "Prepare a release"
+task :release => [ :clean, :version, :gemspec, :package ]
@@ -0,0 +1 @@
+1.0.4
@@ -0,0 +1,119 @@
+== Term::ANSIColor - ANSI escape sequences in Ruby
+
+=== Description
+
+This library can be used to color/uncolor strings using ANSI escape sequences.
+
+=== Author
+
+Florian Frank mailto:flori@ping.de
+
+=== License
+
+This is free software; you can redistribute it and/or modify it under the
+terms of the GNU General Public License Version 2 as published by the Free
+Software Foundation: www.gnu.org/copyleft/gpl.html
+
+=== Download
+
+The latest version of this library can be downloaded at
+
+* http://rubyforge.org/frs?group_id=391
+
+The homepage of this library is located at
+
+* http://term-ansicolor.rubyforge.org
+
+=== Examples
+
+The file examples/example.rb in the source/gem-distribution shows how
+this library can be used:
+ require 'term/ansicolor'
+
+ # Use this trick to work around namespace cluttering that
+ # happens if you just include Term::ANSIColor:
+
+ class Color
+ class << self
+ include Term::ANSIColor
+ end
+ end
+
+ print Color.red, Color.bold, "No Namespace cluttering:", Color.clear, "\n"
+ print Color.green + "green" + Color.clear, "\n"
+ print Color.on_red(Color.green("green")), "\n"
+ print Color.yellow { Color.on_black { "yellow on_black" } }, "\n\n"
+
+ # Or shortcut Term::ANSIColor by assignment:
+ c = Term::ANSIColor
+
+ print c.red, c.bold, "No Namespace cluttering (alternative):", c.clear, "\n"
+ print c.green + "green" + c.clear, "\n"
+ print c.on_red(c.green("green")), "\n"
+ print c.yellow { c.on_black { "yellow on_black" } }, "\n\n"
+
+ # Anyway, I don't define any of Term::ANSIColor's methods in this example
+ # and I want to keep it short:
+ include Term::ANSIColor
+
+ print red, bold, "Usage as constants:", reset, "\n"
+ print clear, "clear", reset, reset, "reset", reset,
+ bold, "bold", reset, dark, "dark", reset,
+ underscore, "underscore", reset, blink, "blink", reset,
+ negative, "negative", reset, concealed, "concealed", reset, "|\n",
+ black, "black", reset, red, "red", reset, green, "green", reset,
+ yellow, "yellow", reset, blue, "blue", reset, magenta, "magenta", reset,
+ cyan, "cyan", reset, white, "white", reset, "|\n",
+ on_black, "on_black", reset, on_red, "on_red", reset,
+ on_green, "on_green", reset, on_yellow, "on_yellow", reset,
+ on_blue, "on_blue", reset, on_magenta, "on_magenta", reset,
+ on_cyan, "on_cyan", reset, on_white, "on_white", reset, "|\n\n"
+
+ print red, bold, "Usage as unary argument methods:", reset, "\n"
+ print clear("clear"), reset("reset"), bold("bold"), dark("dark"),
+ underscore("underscore"), blink("blink"), negative("negative"),
+ concealed("concealed"), "|\n",
+ black("black"), red("red"), green("green"), yellow("yellow"),
+ blue("blue"), magenta("magenta"), cyan("cyan"), white("white"), "|\n",
+ on_black("on_black"), on_red("on_red"), on_green("on_green"),#
+ on_yellow("on_yellow"), on_blue("on_blue"), on_magenta("on_magenta"),
+ on_cyan("on_cyan"), on_white("on_white"), "|\n\n"
+
+ print red { bold { "Usage as block forms:" } }, "\n"
+ print clear { "clear" }, reset { "reset" }, bold { "bold" },
+ dark { "dark" }, underscore { "underscore" }, blink { "blink" },
+ negative { "negative" }, concealed { "concealed" }, "|\n",
+ black { "black" }, red { "red" }, green { "green" },
+ yellow { "yellow" }, blue { "blue" }, magenta { "magenta" },
+ cyan { "cyan" }, white { "white" }, "|\n",
+ on_black { "on_black" }, on_red { "on_red" }, on_green { "on_green" },
+ on_yellow { "on_yellow" }, on_blue { "on_blue" },
+ on_magenta { "on_magenta" }, on_cyan { "on_cyan" },
+ on_white { "on_white" }, "|\n\n"
+
+ # Usage as Mixin into String or its Subclasses
+ class String
+ include Term::ANSIColor
+ end
+
+ print "Usage as String Mixins:".red.bold, "\n"
+ print "clear".clear, "reset".reset, "bold".bold, "dark".dark,
+ "underscore".underscore, "blink".blink, "negative".negative,
+ "concealed".concealed, "|\n",
+ "black".black, "red".red, "green".green, "yellow".yellow,
+ "blue".blue, "magenta".magenta, "cyan".cyan, "white".white, "|\n",
+ "on_black".on_black, "on_red".on_red, "on_green".on_green,
+ "on_yellow".on_yellow, "on_blue".on_blue, "on_magenta".on_magenta,
+ "on_cyan".on_cyan, "on_white".on_white, "|\n\n"
+
+ symbols = Term::ANSIColor::attributes
+ print red { bold { "All supported attributes = " } },
+ blue { symbols.inspect }, "\n\n"
+
+ print "Send symbols to strings:".send(:red).send(:bold), "\n"
+ print symbols[12, 8].map { |c| c.to_s.send(c) }, "\n\n"
+
+ print red { bold { "Make strings monochromatic again:" } }, "\n"
+ print [ "red".red, "not red anymore".red.uncolored,
+ uncolored { "not red anymore".red }, uncolored("not red anymore".red)
+ ].map { |x| x + "\n" }
@@ -0,0 +1,19 @@
+#!/usr/bin/env ruby
+#
+## Little unix filter that colorizes diff output
+#
+
+require 'term/ansicolor'
+
+include Term::ANSIColor
+
+ARGF.each do |line|
+ print(
+ case line
+ when /^\+/ then green { line }
+ when /^-/ then red { line }
+ when /^(@@|diff)/ then blue { line }
+ else line
+ end
+ )
+end
@@ -0,0 +1,89 @@
+require 'term/ansicolor'
+
+# Use this trick to work around namespace cluttering that
+# happens if you just include Term::ANSIColor:
+
+class Color
+ class << self
+ include Term::ANSIColor
+ end
+end
+
+print Color.red, Color.bold, "No Namespace cluttering:", Color.clear, "\n"
+print Color.green + "green" + Color.clear, "\n"
+print Color.on_red(Color.green("green")), "\n"
+print Color.yellow { Color.on_black { "yellow on_black" } }, "\n\n"
+
+# Or shortcut Term::ANSIColor by assignment:
+c = Term::ANSIColor
+
+print c.red, c.bold, "No Namespace cluttering (alternative):", c.clear, "\n"
+print c.green + "green" + c.clear, "\n"
+print c.on_red(c.green("green")), "\n"
+print c.yellow { c.on_black { "yellow on_black" } }, "\n\n"
+
+# Anyway, I don't define any of Term::ANSIColor's methods in this example
+# and I want to keep it short:
+include Term::ANSIColor
+
+print red, bold, "Usage as constants:", reset, "\n"
+print clear, "clear", reset, reset, "reset", reset,
+ bold, "bold", reset, dark, "dark", reset,
+ underscore, "underscore", reset, blink, "blink", reset,
+ negative, "negative", reset, concealed, "concealed", reset, "|\n",
+ black, "black", reset, red, "red", reset, green, "green", reset,
+ yellow, "yellow", reset, blue, "blue", reset, magenta, "magenta", reset,
+ cyan, "cyan", reset, white, "white", reset, "|\n",
+ on_black, "on_black", reset, on_red, "on_red", reset,
+ on_green, "on_green", reset, on_yellow, "on_yellow", reset,
+ on_blue, "on_blue", reset, on_magenta, "on_magenta", reset,
+ on_cyan, "on_cyan", reset, on_white, "on_white", reset, "|\n\n"
+
+print red, bold, "Usage as unary argument methods:", reset, "\n"
+print clear("clear"), reset("reset"), bold("bold"), dark("dark"),
+ underscore("underscore"), blink("blink"), negative("negative"),
+ concealed("concealed"), "|\n",
+ black("black"), red("red"), green("green"), yellow("yellow"),
+ blue("blue"), magenta("magenta"), cyan("cyan"), white("white"), "|\n",
+ on_black("on_black"), on_red("on_red"), on_green("on_green"),#
+ on_yellow("on_yellow"), on_blue("on_blue"), on_magenta("on_magenta"),
+ on_cyan("on_cyan"), on_white("on_white"), "|\n\n"
+
+print red { bold { "Usage as block forms:" } }, "\n"
+print clear { "clear" }, reset { "reset" }, bold { "bold" },
+ dark { "dark" }, underscore { "underscore" }, blink { "blink" },
+ negative { "negative" }, concealed { "concealed" }, "|\n",
+ black { "black" }, red { "red" }, green { "green" },
+ yellow { "yellow" }, blue { "blue" }, magenta { "magenta" },
+ cyan { "cyan" }, white { "white" }, "|\n",
+ on_black { "on_black" }, on_red { "on_red" }, on_green { "on_green" },
+ on_yellow { "on_yellow" }, on_blue { "on_blue" },
+ on_magenta { "on_magenta" }, on_cyan { "on_cyan" },
+ on_white { "on_white" }, "|\n\n"
+
+# Usage as Mixin into String or its Subclasses
+class String
+ include Term::ANSIColor
+end
+
+print "Usage as String Mixins:".red.bold, "\n"
+print "clear".clear, "reset".reset, "bold".bold, "dark".dark,
+ "underscore".underscore, "blink".blink, "negative".negative,
+ "concealed".concealed, "|\n",
+ "black".black, "red".red, "green".green, "yellow".yellow,
+ "blue".blue, "magenta".magenta, "cyan".cyan, "white".white, "|\n",
+ "on_black".on_black, "on_red".on_red, "on_green".on_green,
+ "on_yellow".on_yellow, "on_blue".on_blue, "on_magenta".on_magenta,
+ "on_cyan".on_cyan, "on_white".on_white, "|\n\n"
+
+symbols = Term::ANSIColor::attributes
+print red { bold { "All supported attributes = " } },
+ blue { symbols.inspect }, "\n\n"
+
+print "Send symbols to strings:".send(:red).send(:bold), "\n"
+print symbols[12, 8].map { |c| c.to_s.send(c) }, "\n\n"
+
+print red { bold { "Make strings monochromatic again:" } }, "\n"
+print [ "red".red, "not red anymore".red.uncolored,
+ uncolored { "not red anymore".red }, uncolored("not red anymore".red)
+ ].map { |x| x + "\n" }
@@ -0,0 +1,15 @@
+#!/usr/bin/env ruby
+
+require 'rbconfig'
+include Config
+require 'fileutils'
+include FileUtils::Verbose
+
+destdir = "#{ENV['DESTDIR']}"
+libdir = CONFIG["sitelibdir"]
+dest = destdir + File.join(libdir, 'term')
+mkdir_p dest
+install 'lib/term/ansicolor.rb', dest
+dest = destdir + File.join(libdir, 'term', 'ansicolor')
+mkdir_p dest
+install 'lib/term/ansicolor/version.rb', dest
Oops, something went wrong.

0 comments on commit e6d124a

Please sign in to comment.