jugyo-termcolor 0.3.2 → 0.4.6
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.rdoc +2 -10
- data/Rakefile +2 -4
- data/lib/termcolor.rb +8 -81
- data/spec/spec_helper.rb +1 -0
- data/spec/termcolor_spec.rb +3 -55
- metadata +17 -8
- data/examples/example.rb +0 -14
data/README.rdoc
CHANGED
@@ -4,14 +4,12 @@ http://wiki.github.com/jugyo/termcolor
|
|
4
4
|
|
5
5
|
== DESCRIPTION:
|
6
6
|
|
7
|
-
Termcolor is a library for
|
7
|
+
Termcolor is a library for ANSII color formatting like HTML for output in terminal.
|
8
8
|
|
9
9
|
== FEATURES/PROBLEMS:
|
10
10
|
|
11
|
-
== SYNOPSIS:
|
12
11
|
|
13
|
-
|
14
|
-
#=> "\e[34mHello\e[0m \e[31mWorld!\e[0m"
|
12
|
+
== SYNOPSIS:
|
15
13
|
|
16
14
|
== REQUIREMENTS:
|
17
15
|
|
@@ -19,17 +17,11 @@ Termcolor is a library for ANSI color formatting like HTML for output in termina
|
|
19
17
|
|
20
18
|
== INSTALL:
|
21
19
|
|
22
|
-
sudo gem install termcolor
|
23
|
-
|
24
|
-
or
|
25
|
-
|
26
20
|
gem source -a http://gems.github.com
|
27
21
|
sudo gem install jugyo-termcolor
|
28
22
|
|
29
23
|
== TODO:
|
30
24
|
|
31
|
-
for windows...
|
32
|
-
|
33
25
|
== LICENSE:
|
34
26
|
|
35
27
|
(The MIT License)
|
data/Rakefile
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
1
|
$:.unshift File.dirname(__FILE__) + '/lib/'
|
3
2
|
require 'termcolor'
|
4
3
|
require 'spec/rake/spectask'
|
@@ -13,12 +12,11 @@ desc 'Generate gemspec'
|
|
13
12
|
task :gemspec do |t|
|
14
13
|
open('termcolor.gemspec', "wb" ) do |file|
|
15
14
|
file << <<-EOS
|
16
|
-
# -*- coding: utf-8 -*-
|
17
15
|
Gem::Specification.new do |s|
|
18
16
|
s.name = 'termcolor'
|
19
17
|
s.version = '#{TermColor::VERSION}'
|
20
|
-
s.summary = "Termcolor is a library for
|
21
|
-
s.description = "Termcolor is a library for
|
18
|
+
s.summary = "Termcolor is a library for ANSII color formatting like HTML for output in terminal."
|
19
|
+
s.description = "Termcolor is a library for ANSII color formatting like HTML for output in terminal."
|
22
20
|
s.files = %w( #{Dir['lib/**/*.rb'].join(' ')}
|
23
21
|
#{Dir['spec/**/*.rb'].join(' ')}
|
24
22
|
#{Dir['examples/**/*.rb'].join(' ')}
|
data/lib/termcolor.rb
CHANGED
@@ -1,88 +1,15 @@
|
|
1
|
-
|
2
|
-
require 'rubygems'
|
3
|
-
require 'highline'
|
4
|
-
require 'cgi'
|
5
|
-
require 'rexml/parsers/streamparser'
|
6
|
-
require 'rexml/parsers/baseparser'
|
7
|
-
require 'rexml/streamlistener'
|
1
|
+
require "rexml/document"
|
8
2
|
|
9
|
-
|
10
|
-
VERSION = '0.
|
11
|
-
include REXML
|
3
|
+
class TermColor
|
4
|
+
VERSION = '0.0.1'
|
12
5
|
|
13
6
|
class << self
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
listener.result
|
18
|
-
end
|
19
|
-
|
20
|
-
def escape(text)
|
21
|
-
text.gsub(/[&<>'"]/) do | match |
|
22
|
-
case match
|
23
|
-
when '&' then '&'
|
24
|
-
when '<' then '<'
|
25
|
-
when '>' then '>'
|
26
|
-
when "'" then '''
|
27
|
-
when '"' then '"'
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def unescape(text)
|
33
|
-
text.gsub(/&(lt|gt|amp|quote|apos);/) do | match |
|
34
|
-
case match
|
35
|
-
when '&' then '&'
|
36
|
-
when '<' then '<'
|
37
|
-
when '>' then '>'
|
38
|
-
when ''' then "'"
|
39
|
-
when '"' then '"'
|
40
|
-
end
|
41
|
-
end
|
7
|
+
@highline = HighLine.new
|
8
|
+
def print(text)
|
9
|
+
print parse(text)
|
42
10
|
end
|
43
|
-
|
44
|
-
|
45
|
-
text.gsub(/<(\/?)(\d+)>/, '<\1_\2>')
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
class MyListener
|
50
|
-
include REXML::StreamListener
|
51
|
-
|
52
|
-
attr_reader :result
|
53
|
-
def initialize
|
54
|
-
@result = ''
|
55
|
-
@tag_stack = []
|
56
|
-
end
|
57
|
-
|
58
|
-
def tag_start(name, attrs)
|
59
|
-
esc_seq = to_esc_seq(name)
|
60
|
-
if esc_seq
|
61
|
-
@result << esc_seq
|
62
|
-
@tag_stack.push(name)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def text(text)
|
67
|
-
@result << CGI.unescapeHTML(text)
|
68
|
-
end
|
69
|
-
|
70
|
-
def tag_end(name)
|
71
|
-
@tag_stack.pop
|
72
|
-
@result << HighLine::CLEAR
|
73
|
-
@result << to_esc_seq(@tag_stack[-1]) unless @tag_stack.empty?
|
74
|
-
end
|
75
|
-
|
76
|
-
def to_esc_seq(name)
|
77
|
-
esc_seq = nil
|
78
|
-
begin
|
79
|
-
esc_seq = HighLine.const_get(name.upcase)
|
80
|
-
rescue NameError
|
81
|
-
if name =~ /^[^0-9]?(\d+)$/
|
82
|
-
esc_seq = "\e[#{$1}m"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
esc_seq
|
11
|
+
def parse(text)
|
12
|
+
# TODO
|
86
13
|
end
|
87
14
|
end
|
88
15
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/termcolor_spec.rb
CHANGED
@@ -1,63 +1,11 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
|
2
3
|
require File.dirname(__FILE__) + '/spec_helper'
|
3
4
|
|
4
|
-
|
5
|
+
class TermColor
|
5
6
|
describe TermColor do
|
6
7
|
before do
|
7
|
-
|
8
|
-
|
9
|
-
it 'should parse 1' do
|
10
|
-
text = TermColor.parse('aaa<red>aaaa<bold>foo</bold>bb<blue>bbbb</blue>bbb</red>ccc<on_yellow>ccccc</on_yellow>ccc')
|
11
|
-
puts text
|
12
|
-
text.should == "aaa\e[31maaaa\e[1mfoo\e[0m\e[31mbb\e[34mbbbb\e[0m\e[31mbbb\e[0mccc\e[43mccccc\e[0mccc"
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'should parse 2' do
|
16
|
-
text = TermColor.parse('aa<blue>a<foo>aaa<red>aa</red>aaaa</foo>a</blue>aaa')
|
17
|
-
puts text
|
18
|
-
text.should == "aa\e[34maaaa\e[31maa\e[0m\e[34maaaa\e[0ma\e[0maaa"
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should parse 3' do
|
22
|
-
text = TermColor.parse('aa<blue>aaaaa<aaa"aaa>aaa&aaaaa</blue>aaa')
|
23
|
-
puts text
|
24
|
-
text.should == "aa\e[34maaaaa<aaa\"aaa>aaa&aaaaa\e[0maaa"
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'should parse 3' do
|
28
|
-
text = TermColor.parse('aa<30>bbbbbbb<32>cccc<90>ddd</90>c</32>b</30>aaa')
|
29
|
-
puts text
|
30
|
-
text.should == "aa\e[30mbbbbbbb\e[32mcccc\e[90mddd\e[0m\e[32mc\e[0m\e[30mb\e[0maaa"
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should raise Error' do
|
34
|
-
lambda{ TermColor.parse('aaaaa<red>aaaaa</blue>aaaaa') }.should raise_error(REXML::ParseException)
|
35
|
-
lambda{ TermColor.parse('aaaaa<red>aaaaaaaaaa') }.should_not raise_error(REXML::ParseException)
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'should escape text' do
|
39
|
-
TermColor.escape('<>&"\'').should == "<>&"e;'"
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'should unescape text' do
|
43
|
-
TermColor.unescape("<>&"e;'").should == '<>&"\''
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should prepare parse' do
|
47
|
-
TermColor.prepare_parse("<10>10</10>").should == '<_10>10</_10>'
|
48
|
-
TermColor.prepare_parse("<32>10</32>").should == '<_32>10</_32>'
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'should convert to escape sequence' do
|
52
|
-
listener = TermColor::MyListener.new
|
53
|
-
listener.to_esc_seq('red').should == "\e[31m"
|
54
|
-
listener.to_esc_seq('on_red').should == "\e[41m"
|
55
|
-
listener.to_esc_seq('foo').should == nil
|
56
|
-
listener.to_esc_seq('0').should == "\e[0m"
|
57
|
-
listener.to_esc_seq('31').should == "\e[31m"
|
58
|
-
listener.to_esc_seq('031').should == "\e[031m"
|
59
|
-
listener.to_esc_seq('_0').should == "\e[0m"
|
60
|
-
listener.to_esc_seq('_31').should == "\e[31m"
|
8
|
+
@termcolor = TermColor.new
|
61
9
|
end
|
62
10
|
end
|
63
11
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jugyo-termcolor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jugyo
|
@@ -9,20 +9,20 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-02-13 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
16
|
+
name: json_pure
|
17
17
|
type: :runtime
|
18
18
|
version_requirement:
|
19
19
|
version_requirements: !ruby/object:Gem::Requirement
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 1.
|
23
|
+
version: 1.1.3
|
24
24
|
version:
|
25
|
-
description:
|
25
|
+
description: TermColor is a simple twitter client.
|
26
26
|
email: jugyo.org@gmail.com
|
27
27
|
executables: []
|
28
28
|
|
@@ -32,10 +32,19 @@ extra_rdoc_files:
|
|
32
32
|
- README.rdoc
|
33
33
|
- History.txt
|
34
34
|
files:
|
35
|
+
- lib/termcolor/connection.rb
|
35
36
|
- lib/termcolor.rb
|
36
|
-
- spec/spec_helper.rb
|
37
37
|
- spec/termcolor_spec.rb
|
38
|
-
-
|
38
|
+
- spec/spec_helper.rb
|
39
|
+
- examples/direct_message.rb
|
40
|
+
- examples/favorite.rb
|
41
|
+
- examples/follow.rb
|
42
|
+
- examples/friends_timeline.rb
|
43
|
+
- examples/limit.rb
|
44
|
+
- examples/replies.rb
|
45
|
+
- examples/search.rb
|
46
|
+
- examples/update_status.rb
|
47
|
+
- examples/user.rb
|
39
48
|
- README.rdoc
|
40
49
|
- History.txt
|
41
50
|
- Rakefile
|
@@ -67,6 +76,6 @@ rubyforge_project: termcolor
|
|
67
76
|
rubygems_version: 1.2.0
|
68
77
|
signing_key:
|
69
78
|
specification_version: 2
|
70
|
-
summary:
|
79
|
+
summary: Simple twitter client.
|
71
80
|
test_files: []
|
72
81
|
|
data/examples/example.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'rubygems'
|
3
|
-
require 'termcolor'
|
4
|
-
|
5
|
-
puts TermColor.parse <<EOS
|
6
|
-
|
7
|
-
<on_blue><white><bold>TermColor Example</bold></white></on_blue>
|
8
|
-
|
9
|
-
<on_green><white>Termcolor</white></on_green> is a library for <red><bold>ANSI</bold></red> <blue>c</blue><yellow>o</yellow><green>l</green>o<red>r</red> formatting like <on_magenta>HTML</on_magenta>
|
10
|
-
for output in terminal.
|
11
|
-
|
12
|
-
EOS
|
13
|
-
|
14
|
-
["REVERSE", "ON_RED", "DARK", "MAGENTA", "ColorScheme", "RESET", "RED", "ON_BLUE", "BLINK", "ON_BLACK", "BOLD", "BLUE", "ON_WHITE", "QuestionError", "CLEAR", "BLACK", "ON_YELLOW", "SampleColorScheme", "UNDERSCORE", "WHITE", "SystemExtensions", "ERASE_CHAR", "YELLOW", "ON_CYAN", "CONCEALED", "ON_GREEN", "CHARACTER_MODE", "UNDERLINE", "CYAN", "Question", "Menu", "VERSION", "ERASE_LINE", "GREEN", "ON_MAGENTA"]
|