class Sus::Output::Lines
def []= index, line
def []= index, line @lines[index] = line redraw(index) end
def clear
def clear @lines.clear write end
def height
def height @output.size.first end
def initialize(output)
def initialize(output) @output = output @lines = [] @current_count = 0 end
def origin
def origin if @current_count > 0 @output.write("\e[#{@current_count}F\e[J") end @current_count = 0 end
def redraw(index)
def redraw(index) if index < @current_count update(index, @lines[index]) else write end end
def soft_wrap
def soft_wrap @output.write("\e[?7l") yield ensure @output.write("\e[?7h") end
def update(index, line)
def update(index, line) offset = @current_count - index @output.write("\e[#{offset}F\e[K") soft_wrap do line.print(@output) end if offset > 1 @output.write("\e[#{offset-1}E") end end
def write
def write origin height = self.height soft_wrap do @lines.each do |line| break if (@current_count+1) >= height if line line.print(@output) else @output.puts end @current_count += 1 end end end