termcolor 1.1.0 → 1.2.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/Rakefile CHANGED
@@ -17,8 +17,8 @@ task :gemspec do |t|
17
17
  Gem::Specification.new do |s|
18
18
  s.name = 'termcolor'
19
19
  s.version = '#{TermColor::VERSION}'
20
- s.summary = "Termcolor is a library for ANSI color formatting like HTML for output in terminal."
21
- s.description = "Termcolor is a library for ANSI color formatting like HTML for output in terminal."
20
+ s.summary = %q(Termcolor is a library for ANSI color formatting like HTML for output in terminal.)
21
+ s.description = %q(Termcolor is a library for ANSI color formatting like HTML for output in terminal. '<red>red</red>'.termcolor #=> "\e[31mred\e[0m")
22
22
  s.files = %w( #{Dir['lib/**/*.rb'].join(' ')}
23
23
  #{Dir['spec/**/*.rb'].join(' ')}
24
24
  #{Dir['examples/**/*.rb'].join(' ')}
@@ -7,7 +7,7 @@ require 'rexml/parsers/baseparser'
7
7
  require 'rexml/streamlistener'
8
8
 
9
9
  module TermColor
10
- VERSION = '1.1.0'
10
+ VERSION = '1.2.0'
11
11
  include REXML
12
12
 
13
13
  class << self
@@ -86,15 +86,24 @@ module TermColor
86
86
  end
87
87
 
88
88
  def to_esc_seq(name)
89
- esc_seq = nil
90
- begin
91
- esc_seq = HighLine.const_get(name.upcase)
92
- rescue NameError
93
- if name =~ /^[^0-9]?(\d+)$/
94
- esc_seq = "\e[#{$1}m"
89
+ if (HighLine.const_defined?(name.upcase) rescue false)
90
+ HighLine.const_get(name.upcase)
91
+ else
92
+ case name
93
+ when /^([fb])(\d+)$/
94
+ fb = $1 == 'f' ? 38 : 48
95
+ color = $2.size == 3 ? 16 + $2.to_i(6) : 232 + $2.to_i
96
+ "\e[#{fb};5;#{color}m"
97
+ when /^[^0-9]?(\d+)$/
98
+ "\e[#{$1}m"
95
99
  end
96
100
  end
97
- esc_seq
98
101
  end
99
102
  end
100
103
  end
104
+
105
+ class String
106
+ def termcolor
107
+ TermColor.parse(self)
108
+ end
109
+ end
@@ -30,6 +30,18 @@ module TermColor
30
30
  text.should == "aa\e[30mbbbbbbb\e[32mcccc\e[90mddd\e[0m\e[32mc\e[0m\e[30mb\e[0maaa"
31
31
  end
32
32
 
33
+ it 'should parse 4' do
34
+ text = TermColor.parse('aa<f123>bbbbbbb<b321>ccccc</b321>b</f123>aaa')
35
+ puts text
36
+ text.should == "aa\e[38;5;67mbbbbbbb\e[48;5;137mccccc\e[0m\e[38;5;67mb\e[0maaa"
37
+ end
38
+
39
+ it 'should parse 5' do
40
+ text = TermColor.parse('aa<f12>bbbbbbb<b6>ccccc</b6>b</f12>aaa')
41
+ puts text
42
+ text.should == "aa\e[38;5;244mbbbbbbb\e[48;5;238mccccc\e[0m\e[38;5;244mb\e[0maaa"
43
+ end
44
+
33
45
  it 'should raise Error' do
34
46
  lambda{ TermColor.parse('aaaaa<red>aaaaa</blue>aaaaa') }.should raise_error(REXML::ParseException)
35
47
  lambda{ TermColor.parse('aaaaa<red>aaaaaaaaaa') }.should_not raise_error(REXML::ParseException)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: termcolor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jugyo
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-18 00:00:00 +09:00
12
+ date: 2009-12-28 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,7 +22,7 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 1.5.0
24
24
  version:
25
- description: Termcolor is a library for ANSI color formatting like HTML for output in terminal.
25
+ description: "Termcolor is a library for ANSI color formatting like HTML for output in terminal. '<red>red</red>'.termcolor #=> \"\e[31mred\e[0m\""
26
26
  email: jugyo.org@gmail.com
27
27
  executables: []
28
28
 
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  requirements: []
67
67
 
68
68
  rubyforge_project: termcolor
69
- rubygems_version: 1.3.4
69
+ rubygems_version: 1.3.5
70
70
  signing_key:
71
71
  specification_version: 3
72
72
  summary: Termcolor is a library for ANSI color formatting like HTML for output in terminal.