colored 1.0 → 1.1

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/README CHANGED
@@ -1,6 +1,5 @@
1
1
  cute.
2
2
 
3
- usage:
4
3
  >> puts "this is red".red
5
4
 
6
5
  >> puts "this is red with a blue background (read: ugly)".red_on_blue
@@ -1,9 +1,7 @@
1
1
  require 'Win32/Console/ANSI' if PLATFORM =~ /win32/
2
2
 
3
- #
3
+ ##
4
4
  # cute.
5
- #
6
- # usage:
7
5
  #
8
6
  # >> "this is red".red
9
7
  #
@@ -14,7 +12,6 @@ require 'Win32/Console/ANSI' if PLATFORM =~ /win32/
14
12
  # >> "this is really bold and really blue".bold.blue
15
13
  #
16
14
  # >> Colored.red "This is red" # but this part is mostly untested
17
- #
18
15
  module Colored
19
16
  extend self
20
17
 
@@ -33,7 +30,7 @@ module Colored
33
30
  'clear' => 0,
34
31
  'bold' => 1,
35
32
  'underline' => 4,
36
- 'reverse' => 7
33
+ 'reversed' => 7
37
34
  }
38
35
 
39
36
  COLORS.each do |color, value|
@@ -60,8 +57,15 @@ module Colored
60
57
  end
61
58
  end
62
59
 
60
+ define_method(:to_eol) do
61
+ tmp = sub(/^(\e\[[\[\e0-9;m]+m)/, "\\1\e[2K")
62
+ if tmp == self
63
+ return "\e[2K" << self
64
+ end
65
+ tmp
66
+ end
67
+
63
68
  def colorize(string, options = {})
64
- colored = ''
65
69
  colored = [color(options[:foreground]), color("on_#{options[:background]}"), extra(options[:extra])].compact * ''
66
70
  colored << string
67
71
  colored << extra(:clear)
@@ -1,5 +1,5 @@
1
1
  require 'test/unit'
2
- require File.dirname(__FILE__) + '/../lib/color'
2
+ require File.dirname(__FILE__) + '/../lib/colored'
3
3
 
4
4
  class TestColor < Test::Unit::TestCase
5
5
  def test_one_color
@@ -29,4 +29,16 @@ class TestColor < Test::Unit::TestCase
29
29
  def test_modifiers_stack_with_colors
30
30
  assert_equal "\e[36m\e[4m\e[1mcyan underlined bold\e[0m\e[0m\e[0m", "cyan underlined bold".bold.underline.cyan
31
31
  end
32
+
33
+ def test_eol
34
+ assert_equal "\e[2Knothing to see here really.", "nothing to see here really.".to_eol
35
+ end
36
+
37
+ def test_eol_with_with_two_colors
38
+ assert_equal "\e[34m\e[31m\e[2Kblue\e[0m\e[0m", "blue".red.blue.to_eol
39
+ end
40
+
41
+ def test_eol_with_modifiers_stack_with_colors
42
+ 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
43
+ end
32
44
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: colored
5
5
  version: !ruby/object:Gem::Version
6
- version: "1.0"
7
- date: 2006-11-09 00:00:00 -08:00
6
+ version: "1.1"
7
+ date: 2007-07-25 00:00:00 -07:00
8
8
  summary: Add some color to your life.
9
9
  require_paths:
10
10
  - lib
@@ -31,7 +31,7 @@ authors:
31
31
  files:
32
32
  - README
33
33
  - lib/colored.rb
34
- - test/test_color.rb
34
+ - test/colored_test.rb
35
35
  test_files: []
36
36
 
37
37
  rdoc_options: []