Package net.morimekta.console.terminal
Class LineBuffer
- java.lang.Object
-
- net.morimekta.console.terminal.LineBuffer
-
public class LineBuffer extends java.lang.Object
Class that holds a set of lines, that are printed to the terminal, and methods to dynamically update those buffer. It will keep the cursor at the bottom line (end of printed line) for easy continuation.The class acts as a wrapper around a
Terminal
instance, and makes sure that a list of lines can be updated and printed properly to the terminal in the most efficient order.Example uses are for showing a list of
Progress
'es, or handling the internals of aInputSelection
.
-
-
Constructor Summary
Constructors Constructor Description LineBuffer(Terminal terminal)
Create a LineBuffer instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(java.lang.String... lines)
Add new lines to the end of the buffer, and print them out.void
add(java.util.Collection<java.lang.String> lines)
Add new lines to the end of the buffer, and print them out.void
clear()
Clear the entire buffer, and the terminal area it represents.void
clearLast(int N)
Clear the last N lines, and move the cursor to the end of the last remaining line.int
count()
java.util.List<java.lang.String>
lines()
void
update(int offset, java.lang.String... lines)
Update a number of lines starting at a specific offset.void
update(int offset, java.util.List<java.lang.String> lines)
Update a number of lines starting at a specific offset.
-
-
-
Constructor Detail
-
LineBuffer
public LineBuffer(Terminal terminal)
Create a LineBuffer instance.- Parameters:
terminal
- The terminal to wrap.
-
-
Method Detail
-
count
public int count()
- Returns:
- Number of lines in the buffer.
-
add
public void add(java.lang.String... lines)
Add new lines to the end of the buffer, and print them out.- Parameters:
lines
- The lines to add.
-
add
public void add(java.util.Collection<java.lang.String> lines)
Add new lines to the end of the buffer, and print them out.- Parameters:
lines
- The lines to add.
-
update
public void update(int offset, java.lang.String... lines)
Update a number of lines starting at a specific offset.- Parameters:
offset
- The line offset (0-indexed to count).lines
- The new line content.
-
update
public void update(int offset, java.util.List<java.lang.String> lines)
Update a number of lines starting at a specific offset.- Parameters:
offset
- The line offset (0-indexed to count).lines
- The new line content.
-
clear
public void clear()
Clear the entire buffer, and the terminal area it represents.
-
clearLast
public void clearLast(int N)
Clear the last N lines, and move the cursor to the end of the last remaining line.- Parameters:
N
- Number of lines to clear.
-
lines
public java.util.List<java.lang.String> lines()
- Returns:
- The current set of lines shown.
-
-