ansiterm 0.4 → 0.4.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 +4 -4
- data/lib/ansiterm/buffer.rb +26 -31
- data/lib/ansiterm/string.rb +6 -4
- data/lib/ansiterm/version.rb +1 -1
- data/visual-spec/buffer.rb +41 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 769f26bf92779ce6c3530bd496dc889cccbcbda18b6447472d910b00810749b4
|
4
|
+
data.tar.gz: 9f4599f5b8146011dcb6b56101536a14b4a4317baa2f528e3f947170d6c42366
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2656c8bdee346170e74c725712fe202474cb779d3c74067b9df42769a8fdc736ecc550859a658b1e4f44ff827a5657e49627ab437de464fa5427c8b126cc822
|
7
|
+
data.tar.gz: 998ee1fa03b7d442edcd5f2535d9ad8c5ff16ea7c26795e35e9f42a9540b374608194ab3a32aef627e4e6daf4c1b3e85402c548222333052df4e223c38e497f4
|
data/lib/ansiterm/buffer.rb
CHANGED
@@ -24,7 +24,7 @@ module AnsiTerm
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def cls
|
27
|
-
@lines = (1..@h).map { nil }
|
27
|
+
@lines = (1..@h).map { nil }
|
28
28
|
end
|
29
29
|
|
30
30
|
def reset
|
@@ -46,32 +46,30 @@ module AnsiTerm
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
def scroll
|
50
|
-
while @y >= @h
|
51
|
-
@lines.shift
|
52
|
-
@lines << nil #AnsiTerm::String.new #"" #AnsiTerm::String.new("\e[37;40;0m"+(" "*@w))
|
53
|
-
@y -= 1
|
54
|
-
end
|
55
|
-
true
|
56
|
-
end
|
57
|
-
|
58
49
|
def print *args
|
59
50
|
args.each do |str|
|
60
|
-
@lines[@y] ||= AnsiTerm::String.new
|
61
|
-
@dirty << @y
|
51
|
+
@lines[@y] ||= AnsiTerm::String.new
|
62
52
|
l = @lines[@y]
|
63
53
|
|
64
54
|
if l.length < @x
|
65
55
|
l << (" "*(@x - l.length))
|
66
56
|
end
|
67
|
-
|
68
|
-
|
69
|
-
#
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
57
|
+
|
58
|
+
r=@x..@x+str.length-1
|
59
|
+
#p [r, str]
|
60
|
+
l[r] = str
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
# This scrolls the *buffer* up
|
65
|
+
# If you want it to also scroll the *cache*
|
66
|
+
# pass `scroll_cache: true`. This will presume
|
67
|
+
# that you've scrolled the *terminal* yourself.
|
68
|
+
def scroll_up(num=1, scroll_cache: false)
|
69
|
+
@lines.slice!(0)
|
70
|
+
@lines << AnsiTerm::String.new
|
71
|
+
if scroll_cache
|
72
|
+
@cache.slice!(0)
|
75
73
|
end
|
76
74
|
end
|
77
75
|
|
@@ -81,27 +79,24 @@ module AnsiTerm
|
|
81
79
|
cachemiss=0
|
82
80
|
@lines.each_with_index do |line,y|
|
83
81
|
line ||= ""
|
84
|
-
line = line[0
|
82
|
+
line = line[0..@w]
|
85
83
|
l = line.length
|
86
|
-
#if l > @w
|
87
|
-
# $editor&.log("WARNING: #{l} > @w #{@w}")
|
88
|
-
#end
|
89
84
|
s = line.to_str
|
90
85
|
if @cache[y] != s
|
91
|
-
|
86
|
+
# Move to start of line; output line; clear to end
|
87
|
+
#if l > 0
|
88
|
+
out << "\e[#{y+1};1H" << s
|
89
|
+
if l < @w
|
90
|
+
out << "\e[0m\e[0K"
|
91
|
+
end
|
92
|
+
#end
|
92
93
|
cachemiss += s.length
|
93
94
|
old = @cache[y]
|
94
95
|
@cache[y] = s
|
95
|
-
#$editor.pry([y,old, s])
|
96
96
|
else
|
97
97
|
cachehit += @cache[y].length
|
98
98
|
end
|
99
|
-
# FIXME: This is only worthwhile if a background colour is set
|
100
|
-
#if l < @w
|
101
|
-
# out << ANSI.csi("m",0,38,48,2,48,48,64) << "-"*(@w-l)
|
102
|
-
#end
|
103
99
|
end
|
104
|
-
@dirty = Set[]
|
105
100
|
out
|
106
101
|
end
|
107
102
|
end
|
data/lib/ansiterm/string.rb
CHANGED
@@ -89,11 +89,13 @@ module AnsiTerm
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def[]= range, str
|
92
|
-
s = @str
|
93
|
-
a = @attrs
|
92
|
+
s = @str.dup
|
93
|
+
a = @attrs.dup
|
94
94
|
parse(str)
|
95
|
-
|
96
|
-
@
|
95
|
+
s[range] = @str
|
96
|
+
@str = s
|
97
|
+
a[range] = @attrs
|
98
|
+
@attrs = a
|
97
99
|
end
|
98
100
|
|
99
101
|
def[] i
|
data/lib/ansiterm/version.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
$: << File.dirname(__FILE__)+"/../lib"
|
3
|
+
|
4
|
+
require 'ansiterm'
|
5
|
+
require 'io/console'
|
6
|
+
|
7
|
+
h,w = IO.console.winsize
|
8
|
+
|
9
|
+
t = AnsiTerm::Buffer.new(w,h-1)
|
10
|
+
|
11
|
+
t.cls
|
12
|
+
t.move_cursor(1,1)
|
13
|
+
t.print([h,w].inspect)
|
14
|
+
t.move_cursor(0,0)
|
15
|
+
t.print("UL")
|
16
|
+
t.move_cursor(w-2,0)
|
17
|
+
t.print("UR")
|
18
|
+
t.move_cursor(w-2,h-2)
|
19
|
+
t.print("LR")
|
20
|
+
t.move_cursor(0,h-2)
|
21
|
+
t.print("LL")
|
22
|
+
t.move_cursor(1,2)
|
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")
|
40
|
+
print t.to_s
|
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:
|
4
|
+
version: 0.4.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:
|
11
|
+
date: 2022-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- lib/ansiterm/buffer.rb
|
74
74
|
- lib/ansiterm/string.rb
|
75
75
|
- lib/ansiterm/version.rb
|
76
|
+
- visual-spec/buffer.rb
|
76
77
|
homepage: https://github.com/vidarh/ansiterm
|
77
78
|
licenses:
|
78
79
|
- MIT
|