Clean up terminal history
This commit is contained in:
parent
a20849a5b4
commit
1901b7f251
|
@ -13,7 +13,7 @@ class TerminalConfiguration {
|
|||
lateinit var inputReader: PipedInputStream
|
||||
lateinit var outputWriter: PipedOutputStream
|
||||
lateinit var outputReader: PipedInputStream
|
||||
lateinit var terminal: IOSafeTerminal
|
||||
var terminal: IOSafeTerminal? = null
|
||||
|
||||
fun setInputPair(inputWriter: PipedOutputStream, inputReader: PipedInputStream) {
|
||||
this.inputWriter = inputWriter
|
||||
|
|
|
@ -1,29 +1,16 @@
|
|||
package terminal
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
class TerminalHistory {
|
||||
|
||||
private val history: MutableList<String>
|
||||
private var lineIndex: Int = 0
|
||||
private val history = mutableListOf("")
|
||||
private var lineIndex = 0
|
||||
|
||||
val previousLine: String
|
||||
get() = if (isBeginning) history[lineIndex] else history[--lineIndex]
|
||||
fun getPreviousLine() = if (isBeginning()) history[lineIndex] else history[--lineIndex]
|
||||
fun getNextLine() = if (isEnd()) history[lineIndex] else history[++lineIndex]
|
||||
fun isBeginning() = lineIndex == 0
|
||||
fun isEnd() = lineIndex == lastIndex()
|
||||
|
||||
val isBeginning: Boolean
|
||||
get() = lineIndex == 0
|
||||
|
||||
val nextLine: String
|
||||
get() = if (isEnd) history[lineIndex] else history[++lineIndex]
|
||||
|
||||
val isEnd: Boolean
|
||||
get() = lineIndex == lastIndex()
|
||||
|
||||
init {
|
||||
this.history = ArrayList()
|
||||
this.history.add("")
|
||||
this.lineIndex = 0
|
||||
}
|
||||
private fun lastIndex() = history.size - 1
|
||||
|
||||
fun addLine(line: String) {
|
||||
history[lastIndex()] = line
|
||||
|
@ -31,10 +18,6 @@ class TerminalHistory {
|
|||
lineIndex = lastIndex()
|
||||
}
|
||||
|
||||
private fun lastIndex(): Int {
|
||||
return history.size - 1
|
||||
}
|
||||
|
||||
fun updateCurrentLine(line: String) {
|
||||
history[lineIndex] = line
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue