ansiterm 0.3.1 → 0.3.2
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.
- checksums.yaml +5 -5
- data/lib/ansiterm/attr.rb +18 -9
- data/lib/ansiterm/string.rb +43 -7
- data/lib/ansiterm/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d38217a9590237a3e098e5cf097fc03bc055dbab158c7eaab8b730a9c51e28d8
|
4
|
+
data.tar.gz: fa2661f67e062ad9e8a12f930bb80e93aff47d41641da140ec8bc51a293b98ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84474fe763a85f88560157e7bf70d047e1bbf1efb72407b64b6f4cd9cac57be295f99d9720c5a28d7531873c8ac192c1c3ab63b37fa6d44d877729f96442d1bc
|
7
|
+
data.tar.gz: 809ec57358492a2b71a9ae095907248b1ff2e681f679ab3139d5cd7bede8198cb42408ece26e109859f3a0862702a37be9bb75de0b04ca1d9227abc1644a450d
|
data/lib/ansiterm/attr.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
|
2
2
|
module AnsiTerm
|
3
3
|
|
4
|
+
# # Attr #
|
5
|
+
#
|
4
6
|
# Attr represents the attributes of a given character.
|
5
7
|
# It is intended to follow the "Flyweight" GOF pattern
|
6
8
|
# in that any object representing a given combination
|
@@ -20,7 +22,7 @@ module AnsiTerm
|
|
20
22
|
ITALICS = 2
|
21
23
|
UNDERLINE = 4
|
22
24
|
CROSSED_OUT = 8
|
23
|
-
|
25
|
+
|
24
26
|
attr_reader :fgcol, :bgcol, :flags
|
25
27
|
|
26
28
|
def initialize(fgcol: nil, bgcol: nil, flags: 0)
|
@@ -31,11 +33,18 @@ module AnsiTerm
|
|
31
33
|
end
|
32
34
|
|
33
35
|
def merge(attrs)
|
36
|
+
if attrs.kind_of?(self.class)
|
37
|
+
old = attrs
|
38
|
+
attrs = {}
|
39
|
+
attrs[:bgcol] = old.bgcol if old.bgcol
|
40
|
+
attrs[:fgcol] = old.fgcol if old.fgcol
|
41
|
+
attrs[:flags] = old.flags if old.flags
|
42
|
+
end
|
34
43
|
self.class.new({bgcol: @bgcol, fgcol: @fgcol, flags: @flags}.merge(attrs))
|
35
44
|
end
|
36
|
-
|
45
|
+
|
37
46
|
def add_flag(flags); merge({flags: @flags | flags}); end
|
38
|
-
def clear_flag(flags); merge({flags: @flags & ~
|
47
|
+
def clear_flag(flags); merge({flags: @flags & ~flags}); end
|
39
48
|
|
40
49
|
def reset; self.class.new; end
|
41
50
|
def normal; clear_flag(BOLD); end
|
@@ -55,23 +64,23 @@ module AnsiTerm
|
|
55
64
|
|
56
65
|
def transition_to(other)
|
57
66
|
t = []
|
58
|
-
t << [other.fgcol] if other.fgcol != self.fgcol
|
59
|
-
t << [other.bgcol] if other.bgcol != self.bgcol
|
60
|
-
|
67
|
+
t << [other.fgcol] if other.fgcol && other.fgcol != self.fgcol
|
68
|
+
t << [other.bgcol] if other.bgcol && other.bgcol != self.bgcol
|
69
|
+
|
61
70
|
if other.bold? != self.bold?
|
62
71
|
t << [other.bold? ? 1 : 22]
|
63
72
|
end
|
64
|
-
|
73
|
+
|
65
74
|
if other.underline? != self.underline?
|
66
75
|
t << [other.underline? ? 4 : 24]
|
67
76
|
end
|
68
|
-
|
77
|
+
|
69
78
|
if other.crossed_out? != self.crossed_out?
|
70
79
|
t << [other.crossed_out? ? 9 : 29]
|
71
80
|
end
|
72
81
|
|
73
82
|
return "\e[0m" if other.normal? && !self.normal? && t.length != 1
|
74
|
-
|
83
|
+
|
75
84
|
if t.empty?
|
76
85
|
""
|
77
86
|
else
|
data/lib/ansiterm/string.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
|
2
|
+
# This is a test
|
2
3
|
module AnsiTerm
|
3
4
|
|
4
5
|
class String
|
@@ -6,6 +7,10 @@ module AnsiTerm
|
|
6
7
|
parse(str)
|
7
8
|
end
|
8
9
|
|
10
|
+
def to_plain_str
|
11
|
+
@str.dup
|
12
|
+
end
|
13
|
+
|
9
14
|
def to_str
|
10
15
|
out = ""
|
11
16
|
a = Attr.new
|
@@ -40,6 +45,25 @@ module AnsiTerm
|
|
40
45
|
@str, @attrs = str,Array(attrs)
|
41
46
|
end
|
42
47
|
|
48
|
+
def set_attr(range, attr)
|
49
|
+
min = range.first - 1
|
50
|
+
fattr = @attrs[min]
|
51
|
+
attr = fattr.merge(attr) if fattr
|
52
|
+
r = Array(@attrs[range]).count # Inefficient, but saves dealing with negative offsets etc. "manually"
|
53
|
+
last = nil
|
54
|
+
@attrs[range] = @attrs[range].map do |a|
|
55
|
+
a == last ? a : last = attr.merge(a)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def[]= range, str
|
60
|
+
s = @str
|
61
|
+
a = @attrs
|
62
|
+
parse(str)
|
63
|
+
@str = s[0..(range.min-1)].to_s + @str + s[(range.max)..-1].to_s
|
64
|
+
@attrs = a[0..(range.min-1)].to_a + @attrs + a[(range.max)..-1].to_a
|
65
|
+
end
|
66
|
+
|
43
67
|
def[] i
|
44
68
|
str = @str[i]
|
45
69
|
if str
|
@@ -51,6 +75,10 @@ module AnsiTerm
|
|
51
75
|
end
|
52
76
|
end
|
53
77
|
|
78
|
+
def attr_at(index)
|
79
|
+
@attrs[index]
|
80
|
+
end
|
81
|
+
|
54
82
|
def << str
|
55
83
|
parse(self.to_str + "\e[0m" + str.to_str)
|
56
84
|
end
|
@@ -64,7 +92,8 @@ module AnsiTerm
|
|
64
92
|
if par == "5"
|
65
93
|
col = [col,5,params.shift].join(";")
|
66
94
|
elsif par == "2"
|
67
|
-
col = [col,
|
95
|
+
col = ([col,2] << params.slice!(0..2)).join(";")
|
96
|
+
# ,params.shift,params.shift, params.shift].join(";")
|
68
97
|
end
|
69
98
|
end
|
70
99
|
a.merge(attr_name => col)
|
@@ -81,16 +110,22 @@ module AnsiTerm
|
|
81
110
|
while i < max
|
82
111
|
c = str[i]
|
83
112
|
if c == "\e" && str[i+1] == "[" # CSI
|
84
|
-
params =
|
113
|
+
params = []
|
85
114
|
i += 2
|
115
|
+
par = ""
|
86
116
|
while i < max && str[i].ord < 0x40
|
87
|
-
|
117
|
+
if str[i] == ";"
|
118
|
+
params << par
|
119
|
+
par = ""
|
120
|
+
else
|
121
|
+
par << str[i]
|
122
|
+
end
|
88
123
|
i+=1
|
89
124
|
end
|
125
|
+
params << par if !par.empty?
|
90
126
|
final = str[i]
|
91
127
|
|
92
128
|
if final == "m"
|
93
|
-
params = params.split(";")
|
94
129
|
while par = params.shift
|
95
130
|
par = par.to_i
|
96
131
|
case par
|
@@ -105,12 +140,13 @@ module AnsiTerm
|
|
105
140
|
when 22
|
106
141
|
a = a.normal
|
107
142
|
when 24
|
143
|
+
old = a
|
108
144
|
a = a.clear_flag(Attr::UNDERLINE)
|
109
145
|
when 29
|
110
146
|
a = a.clear_flag(Attr::CROSSED_OUT)
|
111
|
-
when 30..39
|
147
|
+
when 30..39, 90..98
|
112
148
|
a = parse_color(par, params, a, :fgcol)
|
113
|
-
when 40..49
|
149
|
+
when 40..49, 100..107
|
114
150
|
a = parse_color(par, params, a, :bgcol)
|
115
151
|
else
|
116
152
|
@str << "[unknown escape: #{par}]"
|
data/lib/ansiterm/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ansiterm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vidar Hokstad
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|
94
94
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.7.6
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: ANSI/VT102 terminal output with windowing
|