lib/ansiterm/buffer.rb in ansiterm-0.4 vs lib/ansiterm/buffer.rb in ansiterm-0.4.1
- old
+ new
@@ -22,11 +22,11 @@
@h = h
@cache = []
end
def cls
- @lines = (1..@h).map { nil } #AnsiTerm::String.new } #AnsiTerm::String.new("\e[37;40;0m"+(" "*@w)) }
+ @lines = (1..@h).map { nil }
end
def reset
cls
@cache=[]
@@ -44,65 +44,48 @@
@w, @h = w,h
@cache = []
end
end
- def scroll
- while @y >= @h
- @lines.shift
- @lines << nil #AnsiTerm::String.new #"" #AnsiTerm::String.new("\e[37;40;0m"+(" "*@w))
- @y -= 1
- end
- true
- end
-
def print *args
args.each do |str|
- @lines[@y] ||= AnsiTerm::String.new("\e[0m")
- @dirty << @y
+ @lines[@y] ||= AnsiTerm::String.new
l = @lines[@y]
if l.length < @x
l << (" "*(@x - l.length))
end
- l[@x..@x+str.length] = str
- # l[@x] << str
- # if @x + s.length > @w
- # l[@x .. @w-1] = s[0 .. @w - @x]
- # @x = 0
- # @y += 1
- # scroll if @y >= @h
- # end
+
+ r=@x..@x+str.length-1
+ #p [r, str]
+ l[r] = str
end
end
def to_s
out = ""
cachehit=0
cachemiss=0
@lines.each_with_index do |line,y|
line ||= ""
- line = line[0..(@w-1)]
+ line = line[0..@w]
l = line.length
- #if l > @w
- # $editor&.log("WARNING: #{l} > @w #{@w}")
- #end
s = line.to_str
if @cache[y] != s
- out << ANSI.cup(y,0) << s << ANSI.sgr(:reset) << ANSI.el #<< X\n"
+ # Move to start of line; output line; clear to end
+ #if l > 0
+ out << "\e[#{y+1};1H" << s
+ if l < @w
+ out << "\e[0m\e[0K"
+ end
+ #end
cachemiss += s.length
old = @cache[y]
@cache[y] = s
- #$editor.pry([y,old, s])
else
cachehit += @cache[y].length
end
- # FIXME: This is only worthwhile if a background colour is set
- #if l < @w
- # out << ANSI.csi("m",0,38,48,2,48,48,64) << "-"*(@w-l)
- #end
end
- @dirty = Set[]
out
end
end
end