dye 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +8 -1
- data/VERSION +1 -1
- data/dye.gemspec +1 -1
- data/lib/dye.rb +15 -4
- data/test/raw_sgr.irt +18 -0
- metadata +6 -23
data/README.rdoc
CHANGED
@@ -44,6 +44,13 @@ Easy ANSI code coloring for strings in libraries.
|
|
44
44
|
# back to plain text
|
45
45
|
plain_text = Dye.strip_ansi(ansi_string)
|
46
46
|
|
47
|
+
# raw SGR escape sequences
|
48
|
+
Dye.sgr(:cyan) #=> "\e[36m"
|
49
|
+
# strict_ansi?
|
50
|
+
Dye.sgr(:cyan, :bold) #=> "\e[36;1m"
|
51
|
+
# !strict_ansi?
|
52
|
+
Dye.sgr(:cyan, :bold) #=> "\e[36m\e[1m"
|
53
|
+
|
47
54
|
=== Feedback!!!
|
48
55
|
|
49
56
|
This is feedback-driven software. Just send me a line about you and/or what you think about it:
|
@@ -54,7 +61,7 @@ My email address is ddnexus at gmail.com ... waiting for your. Ciao.
|
|
54
61
|
== Features
|
55
62
|
|
56
63
|
* Does not define methods in String
|
57
|
-
* Allows you to
|
64
|
+
* Allows you to set basic styles by just requiring the lib
|
58
65
|
* Allows you to easily add your own custom styles
|
59
66
|
* Allows extended (Select Graphic Rendition) parameters
|
60
67
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/dye.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.summary = 'Easy ANSI code coloring for strings in libraries'
|
11
11
|
s.description = 'Dye adds the basic ANSI styles to any string, allowing also to define your own stiles'
|
12
12
|
|
13
|
-
s.add_development_dependency('irt', [">= 1.
|
13
|
+
s.add_development_dependency('irt', [">= 1.1.2"])
|
14
14
|
|
15
15
|
s.files = `git ls-files -z`.split("\0")
|
16
16
|
|
data/lib/dye.rb
CHANGED
@@ -54,6 +54,7 @@ module Dye
|
|
54
54
|
|
55
55
|
@strict_ansi = !!ENV['DYE_STRICT_ANSI']
|
56
56
|
attr_accessor :strict_ansi
|
57
|
+
alias_method :strict_ansi?, :strict_ansi
|
57
58
|
|
58
59
|
def dye(*args)
|
59
60
|
apply_styles( {}, *args )
|
@@ -63,6 +64,12 @@ module Dye
|
|
63
64
|
string.gsub(/\e\[[\d;]+m/, '')
|
64
65
|
end
|
65
66
|
|
67
|
+
def sgr(*names)
|
68
|
+
return if names.empty?
|
69
|
+
codes = names.map{|n| sgr_to_code(n) }
|
70
|
+
strict_ansi? ? "\e[#{codes.join(';')}m" : codes.map{|c| "\e[#{c}m" }.join
|
71
|
+
end
|
72
|
+
|
66
73
|
private
|
67
74
|
|
68
75
|
def apply_styles(custom_styles, *args)
|
@@ -77,13 +84,11 @@ module Dye
|
|
77
84
|
sgr = [sgr] unless sgr.is_a?(Array)
|
78
85
|
sgr.map do |n|
|
79
86
|
next if n.nil?
|
80
|
-
|
81
|
-
raise UnknownSgrCode.new(n) unless code.is_a?(Integer) && (0..109).include?(code)
|
82
|
-
code
|
87
|
+
sgr_to_code(n)
|
83
88
|
end
|
84
89
|
end.flatten.compact
|
85
90
|
return string if codes.empty?
|
86
|
-
if strict_ansi
|
91
|
+
if strict_ansi?
|
87
92
|
string.match(/^\e\[[\d;]+m.*\e\[0m$/m) ?
|
88
93
|
string.sub(/^(\e\[[\d;]+)/, '\1;' + codes.join(';')) :
|
89
94
|
sprintf("\e[0;%sm%s\e[0m", codes.join(';'), string)
|
@@ -94,4 +99,10 @@ module Dye
|
|
94
99
|
end
|
95
100
|
end
|
96
101
|
|
102
|
+
def sgr_to_code(name)
|
103
|
+
code = name.is_a?(Symbol) ? BASIC_SGR[name] : name
|
104
|
+
raise UnknownSgrCode.new(n) unless code.is_a?(Integer) && (0..109).include?(code)
|
105
|
+
code
|
106
|
+
end
|
107
|
+
|
97
108
|
end
|
data/test/raw_sgr.irt
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
desc 'one code strict'
|
2
|
+
Dye.sgr(:cyan)
|
3
|
+
_eql?( "\e[36m" )
|
4
|
+
|
5
|
+
desc 'two codes strict'
|
6
|
+
Dye.sgr(:cyan, :bold)
|
7
|
+
_eql?( "\e[36;1m" )
|
8
|
+
|
9
|
+
Dye.strict_ansi = false
|
10
|
+
|
11
|
+
desc 'one code no strict'
|
12
|
+
Dye.sgr(:cyan)
|
13
|
+
_eql?( "\e[36m" )
|
14
|
+
|
15
|
+
desc 'two codes no strict'
|
16
|
+
Dye.sgr(:cyan, :bold)
|
17
|
+
_eql?( "\e[36m\e[1m" )
|
18
|
+
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dye
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 1
|
10
|
-
version: 0.1.1
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.2
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Domizio Demichelis
|
@@ -15,7 +10,7 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-02 00:00:00 -04:00
|
19
14
|
default_executable:
|
20
15
|
dependencies:
|
21
16
|
- !ruby/object:Gem::Dependency
|
@@ -26,12 +21,7 @@ dependencies:
|
|
26
21
|
requirements:
|
27
22
|
- - ">="
|
28
23
|
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 1
|
32
|
-
- 0
|
33
|
-
- 0
|
34
|
-
version: 1.0.0
|
24
|
+
version: 1.1.2
|
35
25
|
type: :development
|
36
26
|
version_requirements: *id001
|
37
27
|
description: Dye adds the basic ANSI styles to any string, allowing also to define your own stiles
|
@@ -54,6 +44,7 @@ files:
|
|
54
44
|
- test/custom.irt
|
55
45
|
- test/irt_helper.rb
|
56
46
|
- test/module.irt
|
47
|
+
- test/raw_sgr.irt
|
57
48
|
- test/sgr.irt
|
58
49
|
has_rdoc: true
|
59
50
|
homepage: http://github.com/ddnexus/dye
|
@@ -69,25 +60,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
60
|
requirements:
|
70
61
|
- - ">="
|
71
62
|
- !ruby/object:Gem::Version
|
72
|
-
hash: 3
|
73
|
-
segments:
|
74
|
-
- 0
|
75
63
|
version: "0"
|
76
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
65
|
none: false
|
78
66
|
requirements:
|
79
67
|
- - ">="
|
80
68
|
- !ruby/object:Gem::Version
|
81
|
-
hash: 23
|
82
|
-
segments:
|
83
|
-
- 1
|
84
|
-
- 3
|
85
|
-
- 6
|
86
69
|
version: 1.3.6
|
87
70
|
requirements: []
|
88
71
|
|
89
72
|
rubyforge_project:
|
90
|
-
rubygems_version: 1.
|
73
|
+
rubygems_version: 1.5.0
|
91
74
|
signing_key:
|
92
75
|
specification_version: 3
|
93
76
|
summary: Easy ANSI code coloring for strings in libraries
|