- java.lang.Object
-
- net.morimekta.terminal.LineBuffer
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Iterable<String>
,Collection<String>
,List<String>
,RandomAccess
public class LineBuffer extends Object implements List<String>, RandomAccess, Closeable
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
ProgressLine
'es, or handling the internals of aSelection
.
-
-
Constructor Summary
Constructors Constructor Description LineBuffer(PrintStream writer)
Create a LineBuffer instance.LineBuffer(PrintStream writer, int initialCapacity)
Create a LineBuffer instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int i, String line)
boolean
add(String line)
boolean
addAll(int i, Collection<? extends String> collection)
boolean
addAll(Collection<? extends String> collection)
List<String>
asList()
void
clear()
void
clearLast(int N)
Clear the last N lines, and move the cursor to the end of the last remaining line.void
close()
boolean
contains(Object o)
boolean
containsAll(Collection<?> collection)
boolean
equals(Object obj)
String
get(int i)
int
hashCode()
int
indexOf(Object o)
boolean
isEmpty()
Iterator<String>
iterator()
int
lastIndexOf(Object o)
ListIterator<String>
listIterator()
ListIterator<String>
listIterator(int i)
String
remove(int i)
boolean
remove(Object o)
boolean
removeAll(Collection<?> collection)
boolean
retainAll(Collection<?> collection)
List<String>
reversed()
Compatibility method for java-21.String
set(int i, String line)
boolean
setAll(int startOffset, Collection<String> lines)
Set a number of lines starting at given offset.int
size()
List<String>
subList(int start, int end)
Object[]
toArray()
<T> T[]
toArray(T[] ts)
String
toString()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
replaceAll, sort, spliterator
-
-
-
-
Constructor Detail
-
LineBuffer
public LineBuffer(PrintStream writer)
Create a LineBuffer instance.- Parameters:
writer
- The terminal to wrap.
-
LineBuffer
public LineBuffer(PrintStream writer, int initialCapacity)
Create a LineBuffer instance.- Parameters:
writer
- The terminal to wrap.initialCapacity
- Initial capacity of contained array list.
-
-
Method Detail
-
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.
-
setAll
public boolean setAll(int startOffset, Collection<String> lines)
Set a number of lines starting at given offset.- Parameters:
startOffset
- The start offset.lines
- The lines to set.- Returns:
- If any lines were set.
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
clear
public void clear()
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
add
public boolean add(String line)
-
addAll
public boolean addAll(int i, Collection<? extends String> collection)
-
addAll
public boolean addAll(Collection<? extends String> collection)
-
remove
public boolean remove(Object o)
-
removeAll
public boolean removeAll(Collection<?> collection)
-
retainAll
public boolean retainAll(Collection<?> collection)
-
lastIndexOf
public int lastIndexOf(Object o)
- Specified by:
lastIndexOf
in interfaceList<String>
-
contains
public boolean contains(Object o)
-
containsAll
public boolean containsAll(Collection<?> collection)
- Specified by:
containsAll
in interfaceCollection<String>
- Specified by:
containsAll
in interfaceList<String>
-
toArray
public Object[] toArray()
-
toArray
public <T> T[] toArray(T[] ts)
-
listIterator
public ListIterator<String> listIterator()
- Specified by:
listIterator
in interfaceList<String>
-
listIterator
public ListIterator<String> listIterator(int i)
- Specified by:
listIterator
in interfaceList<String>
-
equals
public boolean equals(Object obj)
-
hashCode
public int hashCode()
-
-