smart_colored 1.0.2 → 1.1.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/VERSION +1 -1
- data/lib/smart_colored.rb +6 -2
- data/smart_colored.gemspec +6 -10
- data/spec/smart_colored_spec.rb +19 -1
- metadata +6 -9
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
data/lib/smart_colored.rb
CHANGED
@@ -20,6 +20,10 @@ module SmartColored
|
|
20
20
|
|
21
21
|
CLEAR_SEQUENCE = "\e[0m"
|
22
22
|
|
23
|
+
def width
|
24
|
+
gsub(/\e\[\d+(?:;\d+)*m/, '').length
|
25
|
+
end
|
26
|
+
|
23
27
|
def apply_format(format = {})
|
24
28
|
apply_attributes = {}
|
25
29
|
if color = COLOR_CODES[format[:color]]
|
@@ -37,7 +41,7 @@ module SmartColored
|
|
37
41
|
previous_attributes = {}
|
38
42
|
clear_sequence = false
|
39
43
|
str = "#{CLEAR_SEQUENCE}#{self}"
|
40
|
-
str.gsub!(/(
|
44
|
+
str.gsub!(/(?:\e\[\d+(?:;\d+)*m)+/) do |m|
|
41
45
|
unless $'.empty?
|
42
46
|
codes = m.scan(/\d+/).map(&:to_i).uniq
|
43
47
|
sequence_attributes = {}
|
@@ -92,7 +96,7 @@ module SmartColored
|
|
92
96
|
end
|
93
97
|
|
94
98
|
PART_REGEXP = "(?:on_)?(?:#{COLOR_CODES.keys.join('|')})|#{FORMAT_CODES.keys.join('|')}"
|
95
|
-
COMBINED_REGEXP =
|
99
|
+
COMBINED_REGEXP = /^(?:(?:#{PART_REGEXP})_){2,}$/
|
96
100
|
COMBINED_REGEXP_PART = /#{PART_REGEXP}/
|
97
101
|
|
98
102
|
def method_missing(method, *arguments, &block)
|
data/smart_colored.gemspec
CHANGED
@@ -4,12 +4,12 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "1.0
|
7
|
+
s.name = "smart_colored"
|
8
|
+
s.version = "1.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Ivan Kuchin"]
|
12
|
-
s.date =
|
12
|
+
s.date = "2011-10-18"
|
13
13
|
s.extra_rdoc_files = [
|
14
14
|
"LICENSE.txt",
|
15
15
|
"README.markdown"
|
@@ -26,15 +26,11 @@ Gem::Specification.new do |s|
|
|
26
26
|
"spec/smart_colored_spec.rb",
|
27
27
|
"spec/spec_helper.rb"
|
28
28
|
]
|
29
|
-
s.homepage =
|
29
|
+
s.homepage = "http://github.com/toy/smart_colored"
|
30
30
|
s.licenses = ["MIT"]
|
31
31
|
s.require_paths = ["lib"]
|
32
|
-
s.rubygems_version =
|
33
|
-
s.summary =
|
34
|
-
s.test_files = [
|
35
|
-
"spec/smart_colored_spec.rb",
|
36
|
-
"spec/spec_helper.rb"
|
37
|
-
]
|
32
|
+
s.rubygems_version = "1.8.11"
|
33
|
+
s.summary = "Color and formatting in terminal"
|
38
34
|
|
39
35
|
if s.respond_to? :specification_version then
|
40
36
|
s.specification_version = 3
|
data/spec/smart_colored_spec.rb
CHANGED
@@ -15,6 +15,24 @@ describe SmartColored do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
describe "width" do
|
19
|
+
it "should return width for unformatted string" do
|
20
|
+
'string'.width.should == 'string'.length
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should return width of red string" do
|
24
|
+
'string'.red.width.should == 'string'.length
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return width of bold underline cyan string" do
|
28
|
+
'string'.bold_underline_cyan.width.should == 'string'.length
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return width of complex formatted string" do
|
32
|
+
"#{"on yellow #{'red underlined'.red.underline} on yellow".on_yellow} #{"bold red".bold.red} blue inversed".blue.inverse.width.should == "on yellow red underlined on yellow bold red blue inversed".length
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
18
36
|
describe "simple" do
|
19
37
|
it "should apply none" do
|
20
38
|
'clear'.apply_format.should == 'clear'
|
@@ -89,7 +107,7 @@ describe SmartColored do
|
|
89
107
|
end
|
90
108
|
|
91
109
|
it "should apply bold, underlined, cyan on yellow" do
|
92
|
-
%w[bold
|
110
|
+
%w[bold underline cyan on_yellow].permutation.each do |parts|
|
93
111
|
'bold underlined cyan'.send(parts.join('_')).should == "\e[1;4;36;43m" 'bold underlined cyan' "\e[0m"
|
94
112
|
end
|
95
113
|
end
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.2
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ivan Kuchin
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
19
|
-
default_executable:
|
18
|
+
date: 2011-10-18 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: jeweler
|
@@ -82,7 +81,6 @@ files:
|
|
82
81
|
- smart_colored.gemspec
|
83
82
|
- spec/smart_colored_spec.rb
|
84
83
|
- spec/spec_helper.rb
|
85
|
-
has_rdoc: true
|
86
84
|
homepage: http://github.com/toy/smart_colored
|
87
85
|
licenses:
|
88
86
|
- MIT
|
@@ -112,10 +110,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
110
|
requirements: []
|
113
111
|
|
114
112
|
rubyforge_project:
|
115
|
-
rubygems_version: 1.
|
113
|
+
rubygems_version: 1.8.11
|
116
114
|
signing_key:
|
117
115
|
specification_version: 3
|
118
116
|
summary: Color and formatting in terminal
|
119
|
-
test_files:
|
120
|
-
|
121
|
-
- spec/spec_helper.rb
|
117
|
+
test_files: []
|
118
|
+
|