ansiterm 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ansiterm/attr.rb +14 -3
- data/lib/ansiterm/string.rb +55 -10
- data/lib/ansiterm/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 594990b07d22ef5777b36348387c47a3061c4772f5e830a2240294c77574b3ea
|
4
|
+
data.tar.gz: 772aa91059ffa9d4e59bd06b33fd607726befacd0ecfafa61db3a5df862897a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3e0fba3540ea67e4126c9ccc6918b778d7fffd971f407c3d4045148dda5b5edf2ef00761ec2465eea55e1e930da15e8a111e62a214753cbfd8a2c6d77fd753b
|
7
|
+
data.tar.gz: 59a9fa226a211ce692a446c7e895631bc19c30e729d3597a7f5f6f97e1de267ac16e4593fe363f460d4a37e3c02bbfb01112772d1cd7489e05cc6ae0406d471c
|
data/lib/ansiterm/attr.rb
CHANGED
@@ -12,7 +12,7 @@ module AnsiTerm
|
|
12
12
|
# whether to e.g. encode a string as spans with one Attr,
|
13
13
|
# or characters with one Attr per character.
|
14
14
|
#
|
15
|
-
# Use Attr#transition(other_attr) to retrieve an ANSI
|
15
|
+
# Use `Attr#transition(other_attr)` to retrieve an ANSI
|
16
16
|
# sequence that represents the changes from self to
|
17
17
|
# other_attr.
|
18
18
|
#
|
@@ -32,7 +32,15 @@ module AnsiTerm
|
|
32
32
|
freeze
|
33
33
|
end
|
34
34
|
|
35
|
+
def ==(other)
|
36
|
+
return false if !other.kind_of?(self.class)
|
37
|
+
return fgcol == other.fgcol &&
|
38
|
+
bgcol == other.bgcol &&
|
39
|
+
flags == other.flags
|
40
|
+
end
|
41
|
+
|
35
42
|
def merge(attrs)
|
43
|
+
return self if self == attrs
|
36
44
|
if attrs.kind_of?(self.class)
|
37
45
|
old = attrs
|
38
46
|
attrs = {}
|
@@ -64,8 +72,8 @@ module AnsiTerm
|
|
64
72
|
|
65
73
|
def transition_to(other)
|
66
74
|
t = []
|
67
|
-
t << [other.fgcol] if other.fgcol
|
68
|
-
t << [other.bgcol] if other.bgcol
|
75
|
+
t << [other.fgcol] if other.fgcol != self.fgcol && other.fgcol
|
76
|
+
t << [other.bgcol] if other.bgcol != self.fgcol && other.bgcol
|
69
77
|
|
70
78
|
if other.bold? != self.bold?
|
71
79
|
t << [other.bold? ? 1 : 22]
|
@@ -89,4 +97,7 @@ module AnsiTerm
|
|
89
97
|
end
|
90
98
|
end
|
91
99
|
|
100
|
+
def self.attr(*args)
|
101
|
+
Attr.new(*args)
|
102
|
+
end
|
92
103
|
end
|
data/lib/ansiterm/string.rb
CHANGED
@@ -1,16 +1,20 @@
|
|
1
|
-
|
2
|
-
# This is a test
|
1
|
+
# coding: utf-8
|
3
2
|
module AnsiTerm
|
4
3
|
|
5
4
|
class String
|
6
|
-
def initialize(str=
|
7
|
-
|
5
|
+
def initialize(str=nil)
|
6
|
+
if str
|
7
|
+
parse(str)
|
8
|
+
else
|
9
|
+
@str = ""
|
10
|
+
@attrs = []
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
14
|
def to_plain_str
|
11
15
|
@str.dup
|
12
16
|
end
|
13
|
-
|
17
|
+
|
14
18
|
def to_str
|
15
19
|
out = ""
|
16
20
|
a = Attr.new
|
@@ -45,15 +49,39 @@ module AnsiTerm
|
|
45
49
|
@str, @attrs = str,Array(attrs)
|
46
50
|
end
|
47
51
|
|
52
|
+
def raw
|
53
|
+
return @str, Array(@attrs)
|
54
|
+
end
|
55
|
+
|
48
56
|
def set_attr(range, attr)
|
49
|
-
min
|
57
|
+
min = [range.first - 1,0].max
|
58
|
+
fattr = @attrs[min]
|
59
|
+
attr = fattr.merge(attr)
|
60
|
+
r = Array(@attrs[range]).count # Inefficient, but saves dealing with negative offsets etc. "manually"
|
61
|
+
last = nil
|
62
|
+
@attrs[range] = @attrs[range].map do |a|
|
63
|
+
n = a.merge(attr)
|
64
|
+
last == n ? last : n
|
65
|
+
end
|
66
|
+
rm = range.last
|
67
|
+
if a = @attrs[rm]
|
68
|
+
@attrs[rm] = Attr.new(bgcol:40).merge(fattr).merge(a)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def merge_attr_below(range, attr)
|
73
|
+
min = [0,range.first - 1].max
|
50
74
|
fattr = @attrs[min]
|
51
|
-
attr = fattr.merge(attr) if fattr
|
52
75
|
r = Array(@attrs[range]).count # Inefficient, but saves dealing with negative offsets etc. "manually"
|
53
76
|
last = nil
|
54
|
-
@attrs[range] = @attrs[range].map do |a|
|
55
|
-
a ==
|
77
|
+
@attrs[range] = @attrs[range].map do |a|
|
78
|
+
if a.bgcol == 49
|
79
|
+
a.merge(attr)
|
80
|
+
else
|
81
|
+
attr.merge(a)
|
82
|
+
end
|
56
83
|
end
|
84
|
+
#fattr #@attrs[min+r].merge(fattr)
|
57
85
|
end
|
58
86
|
|
59
87
|
def[]= range, str
|
@@ -75,12 +103,25 @@ module AnsiTerm
|
|
75
103
|
end
|
76
104
|
end
|
77
105
|
|
106
|
+
def char_at(index)
|
107
|
+
@str[index]
|
108
|
+
end
|
109
|
+
|
78
110
|
def attr_at(index)
|
79
111
|
@attrs[index]
|
80
112
|
end
|
81
113
|
|
82
114
|
def << str
|
83
|
-
|
115
|
+
return self if str.nil?
|
116
|
+
if !str.kind_of?(self.class)
|
117
|
+
parse(self.to_str + "\e[0m" + str.to_str)
|
118
|
+
return self
|
119
|
+
end
|
120
|
+
|
121
|
+
s,a = str.raw
|
122
|
+
@str.concat(s)
|
123
|
+
@attrs.concat(a)
|
124
|
+
self
|
84
125
|
end
|
85
126
|
|
86
127
|
private
|
@@ -162,4 +203,8 @@ module AnsiTerm
|
|
162
203
|
self
|
163
204
|
end
|
164
205
|
end
|
206
|
+
|
207
|
+
def self.str(*args)
|
208
|
+
AnsiTerm::String.new(*args)
|
209
|
+
end
|
165
210
|
end
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vidar Hokstad
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -91,8 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
91
|
- !ruby/object:Gem::Version
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|
94
|
-
|
95
|
-
rubygems_version: 2.7.6
|
94
|
+
rubygems_version: 3.1.4
|
96
95
|
signing_key:
|
97
96
|
specification_version: 4
|
98
97
|
summary: ANSI/VT102 terminal output with windowing
|