SusSourceSusOutputLines

class Lines

Represents a line buffer for managing multiple lines of output on a terminal.

Definitions

def initialize(output)

Initialize a new Lines buffer.

Signature

parameter output Output

The output handler to write to.

Implementation

def initialize(output)
	@output = output
	@lines = []
	
	@current_count = 0
end

def height

Signature

returns Integer

The height of the terminal.

Implementation

def height
	@output.size.first
end

def []=(index, line)

Set a line at the given index.

Signature

parameter index Integer

The line index.

parameter line Object

The line content (should respond to #print).

Implementation

def []= index, line
	@lines[index] = line
	
	redraw(index)
end

def clear

Clear all lines.

Implementation

def clear
	@lines.clear
	write
end

def redraw(index)

Redraw a specific line or all lines.

Signature

parameter index Integer

The line index to redraw.

Implementation

def redraw(index)
	if index < @current_count
		update(index, @lines[index])
	else
		write
	end
end