colored-1.2/0000755000175000017500000000000012077611734012371 5ustar boutilboutilcolored-1.2/metadata.yml0000644000175000017500000000257012077611734014700 0ustar boutilboutil--- !ruby/object:Gem::Specification name: colored version: !ruby/object:Gem::Version version: "1.2" platform: ruby authors: - Chris Wanstrath autorequire: bindir: bin cert_chain: [] date: 2010-02-10 00:00:00 -08:00 default_executable: dependencies: [] description: " >> puts \"this is red\".red\n \n >> puts \"this is red with a blue background (read: ugly)\".red_on_blue\n\n >> puts \"this is red with an underline\".red.underline\n\n >> puts \"this is really bold and really blue\".bold.blue\n\n >> logger.debug \"hey this is broken!\".red_on_yellow # in rails\n\n >> puts Color.red \"This is red\" # but this part is mostly untested\n" email: chris@ozmm.org executables: [] extensions: [] extra_rdoc_files: [] files: - README - Rakefile - LICENSE - lib/colored.rb - test/colored_test.rb has_rdoc: true homepage: http://github.com/defunkt/colored licenses: [] post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: "0" version: required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: "0" version: requirements: [] rubyforge_project: rubygems_version: 1.3.5 signing_key: specification_version: 3 summary: Add some color to your life. test_files: [] colored-1.2/test/0000755000175000017500000000000012077611734013350 5ustar boutilboutilcolored-1.2/test/colored_test.rb0000644000175000017500000000237312077611734016370 0ustar boutilboutilrequire 'test/unit' require File.dirname(__FILE__) + '/../lib/colored' class TestColor < Test::Unit::TestCase def test_one_color assert_equal "\e[31mred\e[0m", "red".red end def test_two_colors assert_equal "\e[34m\e[31mblue\e[0m\e[0m", "blue".red.blue end def test_background_color assert_equal "\e[43mon yellow\e[0m", "on yellow".on_yellow end def test_hot_color_on_color_action assert_equal "\e[31m\e[44mred on blue\e[0m", "red on blue".red_on_blue end def test_modifier assert_equal "\e[1mway bold\e[0m", "way bold".bold end def test_modifiers_stack assert_equal "\e[4m\e[1munderlined bold\e[0m\e[0m", "underlined bold".bold.underline end def test_modifiers_stack_with_colors assert_equal "\e[36m\e[4m\e[1mcyan underlined bold\e[0m\e[0m\e[0m", "cyan underlined bold".bold.underline.cyan end def test_eol assert_equal "\e[2Knothing to see here really.", "nothing to see here really.".to_eol end def test_eol_with_with_two_colors assert_equal "\e[34m\e[31m\e[2Kblue\e[0m\e[0m", "blue".red.blue.to_eol end def test_eol_with_modifiers_stack_with_colors assert_equal "\e[36m\e[4m\e[1m\e[2Kcyan underlined bold\e[0m\e[0m\e[0m", "cyan underlined bold".bold.underline.cyan.to_eol end end colored-1.2/LICENSE0000644000175000017500000000203712077611734013400 0ustar boutilboutilCopyright (c) 2010 Chris Wanstrath Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. colored-1.2/README0000644000175000017500000000115112077611734013247 0ustar boutilboutilcute. >> puts "this is red".red >> puts "this is red with a blue background (read: ugly)".red_on_blue >> puts "this is red with an underline".red.underline >> puts "this is really bold and really blue".bold.blue >> logger.debug "hey this is broken!".red_on_yellow # in rails >> puts Color.red "This is red" # but this part is mostly untested Windows users: You will need the Win32 Console Ansi gem. Get it: $ sudo gem install win32console-1.0.0 --source require.errtheblog.com (We're trying to make it official. Hang in there.) >> chris[at]ozmm[dot]org => http://github.com/defunkt colored-1.2/Rakefile0000644000175000017500000000040012077611734014030 0ustar boutilboutilrequire 'rake/testtask' task :default => :test Rake::TestTask.new do |t| t.libs << 'lib' t.pattern = 'test/**/*_test.rb' t.verbose = false end begin require 'mg' MG.new("colored.gemspec") rescue LoadError abort "Please `gem install mg`" end colored-1.2/lib/0000755000175000017500000000000012077611734013137 5ustar boutilboutilcolored-1.2/lib/colored.rb0000644000175000017500000000403412077611734015114 0ustar boutilboutilrequire 'Win32/Console/ANSI' if RUBY_PLATFORM =~ /win32/ ## # cute. # # >> "this is red".red # # >> "this is red with a blue background (read: ugly)".red_on_blue # # >> "this is red with an underline".red.underline # # >> "this is really bold and really blue".bold.blue # # >> Colored.red "This is red" # but this part is mostly untested module Colored extend self COLORS = { 'black' => 30, 'red' => 31, 'green' => 32, 'yellow' => 33, 'blue' => 34, 'magenta' => 35, 'cyan' => 36, 'white' => 37 } EXTRAS = { 'clear' => 0, 'bold' => 1, 'underline' => 4, 'reversed' => 7 } COLORS.each do |color, value| define_method(color) do colorize(self, :foreground => color) end define_method("on_#{color}") do colorize(self, :background => color) end COLORS.each do |highlight, value| next if color == highlight define_method("#{color}_on_#{highlight}") do colorize(self, :foreground => color, :background => highlight) end end end EXTRAS.each do |extra, value| next if extra == 'clear' define_method(extra) do colorize(self, :extra => extra) end end define_method(:to_eol) do tmp = sub(/^(\e\[[\[\e0-9;m]+m)/, "\\1\e[2K") if tmp == self return "\e[2K" << self end tmp end def colorize(string, options = {}) colored = [color(options[:foreground]), color("on_#{options[:background]}"), extra(options[:extra])].compact * '' colored << string colored << extra(:clear) end def colors @@colors ||= COLORS.keys.sort end def extra(extra_name) extra_name = extra_name.to_s "\e[#{EXTRAS[extra_name]}m" if EXTRAS[extra_name] end def color(color_name) background = color_name.to_s =~ /on_/ color_name = color_name.to_s.sub('on_', '') return unless color_name && COLORS[color_name] "\e[#{COLORS[color_name] + (background ? 10 : 0)}m" end end unless Object.const_defined? :Colored String.send(:include, Colored)