ansi_chameleon 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog +4 -0
- data/README.md +1 -1
- data/lib/ansi_chameleon/sequence_generator.rb +40 -14
- data/lib/ansi_chameleon/version.rb +1 -1
- metadata +4 -4
data/Changelog
CHANGED
data/README.md
CHANGED
@@ -90,7 +90,7 @@ Tag names in a style sheet can be written as either :symbols or "strings".
|
|
90
90
|
* `:foreground_color` (aliases: `:foreground`, `:fg_color`)
|
91
91
|
* `:background_color` (aliases: `:background`, `:bg_color`)
|
92
92
|
|
93
|
-
Available color values: `:black`, `:red`, `:green`, `:yellow`, `:blue`, `:magenta`, `:cyan`, `:white
|
93
|
+
Available color values: `:black`, `:red`, `:green`, `:yellow`, `:blue`, `:magenta`, `:cyan`, `:white` and a number/string between 0 and 255 that represents a color in xterm 256 color scale.
|
94
94
|
|
95
95
|
* `:effect`
|
96
96
|
|
@@ -1,32 +1,58 @@
|
|
1
1
|
module AnsiChameleon
|
2
2
|
module SequenceGenerator
|
3
3
|
|
4
|
-
class
|
5
|
-
class
|
4
|
+
class InvalidColorValueError < ArgumentError; end
|
5
|
+
class InvalidEffectValueError < ArgumentError; end
|
6
6
|
|
7
7
|
COLORS = [:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white]
|
8
8
|
EFFECTS = { :none => 0, :bright => 1, :underline => 4, :blink => 5, :reverse => 7 }
|
9
9
|
|
10
|
-
def self.
|
11
|
-
|
10
|
+
def self.generate(effect_value, foreground_color_value=nil, background_color_value=nil)
|
11
|
+
if effect_value.to_sym == :reset
|
12
|
+
"\033[0m"
|
13
|
+
else
|
14
|
+
"#{effect_sequence(effect_value)}#{foreground_color_sequence(foreground_color_value)}#{background_color_sequence(background_color_value)}"
|
15
|
+
end
|
12
16
|
end
|
13
17
|
|
14
|
-
def self.
|
15
|
-
|
16
|
-
|
18
|
+
def self.effect_sequence(value)
|
19
|
+
if EFFECTS.include?(value.to_sym)
|
20
|
+
"\033[#{EFFECTS[value.to_sym]}m"
|
21
|
+
|
22
|
+
else
|
23
|
+
raise InvalidEffectValueError.new("Invalid effect value #{value.inspect}")
|
24
|
+
|
25
|
+
end
|
17
26
|
end
|
18
27
|
|
19
|
-
def self.
|
20
|
-
|
21
|
-
|
28
|
+
def self.foreground_color_sequence(value)
|
29
|
+
if number_from_0_to_255?(value)
|
30
|
+
"\033[38;5;#{value}m"
|
31
|
+
|
32
|
+
elsif COLORS.include?(value.to_s.to_sym)
|
33
|
+
"\033[#{COLORS.index(value.to_sym) + 30}m"
|
34
|
+
|
35
|
+
else
|
36
|
+
raise InvalidColorValueError.new("Invalid foreground color value #{value.inspect}")
|
37
|
+
|
38
|
+
end
|
22
39
|
end
|
23
40
|
|
24
|
-
def self.
|
25
|
-
if
|
26
|
-
"\033[
|
41
|
+
def self.background_color_sequence(value)
|
42
|
+
if number_from_0_to_255?(value)
|
43
|
+
"\033[48;5;#{value}m"
|
44
|
+
|
45
|
+
elsif COLORS.include?(value.to_s.to_sym)
|
46
|
+
"\033[#{COLORS.index(value.to_sym) + 40}m"
|
47
|
+
|
27
48
|
else
|
28
|
-
"
|
49
|
+
raise InvalidColorValueError.new("Invalid background color value #{value.inspect}")
|
50
|
+
|
29
51
|
end
|
30
52
|
end
|
53
|
+
|
54
|
+
def self.number_from_0_to_255?(value)
|
55
|
+
value.to_s =~ /^\d+$/ && (0..255).member?(value.to_i)
|
56
|
+
end
|
31
57
|
end
|
32
58
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ansi_chameleon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-02-02 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &79655270 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '2.0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *79655270
|
25
25
|
description: Colorizes text terminal output by converting custom HTML-like tags into
|
26
26
|
color ANSI escape sequences.
|
27
27
|
email: jacekmikrut.software@gmail.com
|