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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92d53d94db9dcd9ed7d7369d4b7df040c5da231bfb2985399b783716f12c7fa0
4
- data.tar.gz: 7a50dcdbadfe4cf828de6b98ac674f36052525e0fc5c390a4d018167ccffb4cb
3
+ metadata.gz: 67a711d64ca029c1b3fb2a2cea32da16996f76ad440e901c4a2edad13564b7fd
4
+ data.tar.gz: dd675c62ede4b0530ffa53fcd9208f312bc6e44757d62ce3fa01b14d5ac9c392
5
5
  SHA512:
6
- metadata.gz: a0c1b315496296dd0a9c6015c5907a0d08eb6d4c4a17756d8ce22f4929b6ff571e448bf9b83a902949be6b625706e9d796d9c59d742f90fb5b0f7b2ffec3c1a9
7
- data.tar.gz: c595e0ca1516a21f033317f997f31981bc6899263ce8407065244d76f8bb41bfe339a5435df048be64a149da36e692bcfc04e695e95cc9664e379a5ed8e7e4e6
6
+ metadata.gz: 053de29389ed592194707f8406d83f7b56d09932657288d43a679a63bdd14300d73520160d932957c4f61919cfad4e1633519eb583a24a6a765f22f3d0edeca1
7
+ data.tar.gz: edd85d4d45baed56de37b1637ff4111e8e4687610fb91a4ea2206a4d92b0542899285da0766640b3eda2c8bb1bf0e05228d0473f5f0dc0cc7495251151d557ae
@@ -24,7 +24,7 @@ module AnsiTerm
24
24
  end
25
25
 
26
26
  def cls
27
- @lines = (1..@h).map { nil } #AnsiTerm::String.new } #AnsiTerm::String.new("\e[37;40;0m"+(" "*@w)) }
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("\e[0m")
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
- l[@x..@x+str.length] = str
68
- # l[@x] << str
69
- # if @x + s.length > @w
70
- # l[@x .. @w-1] = s[0 .. @w - @x]
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..(@w-1)]
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
- out << ANSI.cup(y,0) << s << ANSI.sgr(:reset) << ANSI.el #<< X\n"
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
@@ -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
- @str = s[0..(range.min-1)].to_s + @str + s[(range.max)..-1].to_s
96
- @attrs = a[0..(range.min-1)].to_a + @attrs + a[(range.max)..-1].to_a
95
+ s[range] = @str
96
+ @str = s
97
+ a[range] = @attrs
98
+ @attrs = a
97
99
  end
98
100
 
99
101
  def[] i
@@ -1,3 +1,3 @@
1
1
  module AnsiTerm
2
- VERSION = "0.4"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -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: '0.4'
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 00:00:00.000000000 Z
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