Class: Sus::Output::Lines

Inherits:
Object
  • Object
show all
Defined in:
lib/sus/output/lines.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ Lines

Initialize a new Lines buffer.



14
15
16
17
18
19
# File 'lib/sus/output/lines.rb', line 14

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

Instance Method Details

#[]=(index, line) ⇒ Object

Set a line at the given index.



29
30
31
32
33
# File 'lib/sus/output/lines.rb', line 29

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

#clearObject

Clear all lines.



36
37
38
39
# File 'lib/sus/output/lines.rb', line 36

def clear
	@lines.clear
	write
end

#heightObject



22
23
24
# File 'lib/sus/output/lines.rb', line 22

def height
	@output.size.first
end

#redraw(index) ⇒ Object

Redraw a specific line or all lines.



43
44
45
46
47
48
49
# File 'lib/sus/output/lines.rb', line 43

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