ansiterm 0.4.1 → 0.4.3
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 +4 -4
- data/lib/ansiterm/attr.rb +3 -3
- data/lib/ansiterm/buffer.rb +33 -5
- data/lib/ansiterm/string.rb +18 -9
- data/lib/ansiterm/version.rb +1 -1
- data/visual-spec/buffer.rb +18 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0dae91bb1ebbc0bda9632bf8846262e97819da55d1288c3c0b5beed53a3b11f
|
4
|
+
data.tar.gz: 055362e6766853205246e45ed3ee67646c30b0233cdbcdeeceaf6809e938ce7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 620a6db97f8729c25c336c663db0ec2d27ef412414990f4317fc115a77fab2ec7d316b46c8677b9aa300ea50cd83c4aaa6a10e132aafa787a1465ef54ac1dda9
|
7
|
+
data.tar.gz: 84cdb955fdebe1ea70e0f9ee7cf3c8795217929b3d65984868d799576b97eec6ed73def2d849c2685661754d30bcc3750008372aa4a79e4942e9680d1615e9c9
|
data/lib/ansiterm/attr.rb
CHANGED
@@ -55,7 +55,7 @@ module AnsiTerm
|
|
55
55
|
attrs.delete(ignore)
|
56
56
|
end
|
57
57
|
attrs = to_h.merge(attrs)
|
58
|
-
self.class.new(attrs)
|
58
|
+
self.class.new(**attrs)
|
59
59
|
end
|
60
60
|
|
61
61
|
def add_flag(flags); merge({flags: @flags.to_i | flags.to_i}); end
|
@@ -104,7 +104,7 @@ module AnsiTerm
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
def self.attr(
|
108
|
-
Attr.new(
|
107
|
+
def self.attr(...)
|
108
|
+
Attr.new(...)
|
109
109
|
end
|
110
110
|
end
|
data/lib/ansiterm/buffer.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
|
2
|
+
|
3
|
+
|
4
|
+
|
2
5
|
module AnsiTerm
|
3
6
|
|
4
7
|
# # AnsiTerm::Buffer #
|
@@ -20,7 +23,7 @@ module AnsiTerm
|
|
20
23
|
@y = 0
|
21
24
|
@w = w
|
22
25
|
@h = h
|
23
|
-
@cache =
|
26
|
+
@cache = Array.new { AnsiTerm::String.new }
|
24
27
|
end
|
25
28
|
|
26
29
|
def cls
|
@@ -58,6 +61,20 @@ module AnsiTerm
|
|
58
61
|
r=@x..@x+str.length-1
|
59
62
|
#p [r, str]
|
60
63
|
l[r] = str
|
64
|
+
@x += str.length
|
65
|
+
# FIXME: Handle wrap.
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# This scrolls the *buffer* up
|
70
|
+
# If you want it to also scroll the *cache*
|
71
|
+
# pass `scroll_cache: true`. This will presume
|
72
|
+
# that you've scrolled the *terminal* yourself.
|
73
|
+
def scroll_up(num=1, scroll_cache: false)
|
74
|
+
@lines.slice!(0)
|
75
|
+
@lines << AnsiTerm::String.new
|
76
|
+
if scroll_cache
|
77
|
+
@cache.slice!(0)
|
61
78
|
end
|
62
79
|
end
|
63
80
|
|
@@ -73,11 +90,22 @@ module AnsiTerm
|
|
73
90
|
if @cache[y] != s
|
74
91
|
# Move to start of line; output line; clear to end
|
75
92
|
#if l > 0
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
93
|
+
#s.lstrip!
|
94
|
+
#x = l - s.length
|
95
|
+
out << "\e[#{y+1};1H"
|
96
|
+
#if x > 1
|
97
|
+
# out << "\e[1K"
|
80
98
|
#end
|
99
|
+
#FIXME: We can only do this if:
|
100
|
+
#1. we know no background color has been set
|
101
|
+
#2. OR we add support for specifying it.
|
102
|
+
#out << s.rstrip
|
103
|
+
out << s
|
104
|
+
if l < @w
|
105
|
+
# FIXME: Allow setting background colour
|
106
|
+
out << "\e[0m\e[0K"
|
107
|
+
#end
|
108
|
+
end
|
81
109
|
cachemiss += s.length
|
82
110
|
old = @cache[y]
|
83
111
|
@cache[y] = s
|
data/lib/ansiterm/string.rb
CHANGED
@@ -11,6 +11,8 @@ module AnsiTerm
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
attr_reader :str, :attrs
|
15
|
+
|
14
16
|
def to_plain_str
|
15
17
|
@str.dup
|
16
18
|
end
|
@@ -78,7 +80,7 @@ module AnsiTerm
|
|
78
80
|
r = Array(@attrs[range]).count # Inefficient, but saves dealing with negative offsets etc. "manually"
|
79
81
|
last = nil
|
80
82
|
@attrs[range] = @attrs[range].map do |a|
|
81
|
-
if a
|
83
|
+
if a&.bgcol == 49
|
82
84
|
n = attr.merge(a, ignore: :bgcol)
|
83
85
|
else
|
84
86
|
n = attr.merge(a)
|
@@ -89,13 +91,20 @@ module AnsiTerm
|
|
89
91
|
end
|
90
92
|
|
91
93
|
def[]= range, str
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
94
|
+
if str.is_a?(self.class)
|
95
|
+
#@str = @str.dup
|
96
|
+
#@attrs = @attrs.dup
|
97
|
+
@str[range] = str.str
|
98
|
+
@attrs[range] = str.attrs
|
99
|
+
else
|
100
|
+
s = @str.dup
|
101
|
+
a = @attrs.dup
|
102
|
+
parse(str)
|
103
|
+
s[range] = @str
|
104
|
+
@str = s
|
105
|
+
a[range] = @attrs
|
106
|
+
@attrs = a
|
107
|
+
end
|
99
108
|
end
|
100
109
|
|
101
110
|
def[] i
|
@@ -143,7 +152,7 @@ module AnsiTerm
|
|
143
152
|
# ,params.shift,params.shift, params.shift].join(";")
|
144
153
|
end
|
145
154
|
end
|
146
|
-
a.merge(attr_name => col)
|
155
|
+
a.merge({attr_name => col})
|
147
156
|
end
|
148
157
|
|
149
158
|
def parse(str)
|
data/lib/ansiterm/version.rb
CHANGED
data/visual-spec/buffer.rb
CHANGED
@@ -6,7 +6,7 @@ require 'io/console'
|
|
6
6
|
|
7
7
|
h,w = IO.console.winsize
|
8
8
|
|
9
|
-
t = AnsiTerm::Buffer.new(w,h)
|
9
|
+
t = AnsiTerm::Buffer.new(w,h-1)
|
10
10
|
|
11
11
|
t.cls
|
12
12
|
t.move_cursor(1,1)
|
@@ -20,6 +20,22 @@ t.print("LR")
|
|
20
20
|
t.move_cursor(0,h-2)
|
21
21
|
t.print("LL")
|
22
22
|
t.move_cursor(1,2)
|
23
|
-
t.print ("Hello world")
|
23
|
+
t.print ("Hello world. UL/UR/LL/LR should fit the corners but one line above the bottom.")
|
24
|
+
print t.to_s
|
25
|
+
gets
|
26
|
+
t.scroll_up
|
27
|
+
t.move_cursor(0,0)
|
28
|
+
t.print("ul")
|
29
|
+
t.move_cursor(w-2,0)
|
30
|
+
t.print("ur")
|
31
|
+
t.move_cursor(w-2,h-2)
|
32
|
+
t.print("lr")
|
33
|
+
t.move_cursor(0,h-2)
|
34
|
+
t.print("ll")
|
35
|
+
|
36
|
+
t.move_cursor(1,2)
|
37
|
+
t.print ("We've scrolled one line up. This should display right below the Hello World.")
|
38
|
+
t.move_cursor(1,3)
|
39
|
+
t.print ("Old LL/LR should be visible one line up; new, lower case ones replacing them")
|
24
40
|
print t.to_s
|
25
41
|
gets
|
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.4.
|
4
|
+
version: 0.4.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: 2025-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '0'
|
95
95
|
requirements: []
|
96
|
-
rubygems_version: 3.
|
96
|
+
rubygems_version: 3.4.10
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: ANSI/VT102 terminal output with windowing
|