ansiterm 0.4 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ansiterm/buffer.rb +14 -31
- data/lib/ansiterm/string.rb +6 -4
- data/lib/ansiterm/version.rb +1 -1
- data/visual-spec/buffer.rb +25 -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: 67a711d64ca029c1b3fb2a2cea32da16996f76ad440e901c4a2edad13564b7fd
|
4
|
+
data.tar.gz: dd675c62ede4b0530ffa53fcd9208f312bc6e44757d62ce3fa01b14d5ac9c392
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 053de29389ed592194707f8406d83f7b56d09932657288d43a679a63bdd14300d73520160d932957c4f61919cfad4e1633519eb583a24a6a765f22f3d0edeca1
|
7
|
+
data.tar.gz: edd85d4d45baed56de37b1637ff4111e8e4687610fb91a4ea2206a4d92b0542899285da0766640b3eda2c8bb1bf0e05228d0473f5f0dc0cc7495251151d557ae
|
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,18 @@ 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
|
-
# @x = 0
|
72
|
-
# @y += 1
|
73
|
-
# scroll if @y >= @h
|
74
|
-
# end
|
57
|
+
|
58
|
+
r=@x..@x+str.length-1
|
59
|
+
#p [r, str]
|
60
|
+
l[r] = str
|
75
61
|
end
|
76
62
|
end
|
77
63
|
|
@@ -81,27 +67,24 @@ module AnsiTerm
|
|
81
67
|
cachemiss=0
|
82
68
|
@lines.each_with_index do |line,y|
|
83
69
|
line ||= ""
|
84
|
-
line = line[0
|
70
|
+
line = line[0..@w]
|
85
71
|
l = line.length
|
86
|
-
#if l > @w
|
87
|
-
# $editor&.log("WARNING: #{l} > @w #{@w}")
|
88
|
-
#end
|
89
72
|
s = line.to_str
|
90
73
|
if @cache[y] != s
|
91
|
-
|
74
|
+
# Move to start of line; output line; clear to end
|
75
|
+
#if l > 0
|
76
|
+
out << "\e[#{y+1};1H" << s
|
77
|
+
if l < @w
|
78
|
+
out << "\e[0m\e[0K"
|
79
|
+
end
|
80
|
+
#end
|
92
81
|
cachemiss += s.length
|
93
82
|
old = @cache[y]
|
94
83
|
@cache[y] = s
|
95
|
-
#$editor.pry([y,old, s])
|
96
84
|
else
|
97
85
|
cachehit += @cache[y].length
|
98
86
|
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
87
|
end
|
104
|
-
@dirty = Set[]
|
105
88
|
out
|
106
89
|
end
|
107
90
|
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,25 @@
|
|
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)
|
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")
|
24
|
+
print t.to_s
|
25
|
+
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vidar Hokstad
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-12 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
|