Clean up terminal history

This commit is contained in:
Mike Cifelli 2018-09-15 15:36:35 -04:00
parent a20849a5b4
commit 1901b7f251
2 changed files with 8 additions and 25 deletions

View File

@ -13,7 +13,7 @@ class TerminalConfiguration {
lateinit var inputReader: PipedInputStream lateinit var inputReader: PipedInputStream
lateinit var outputWriter: PipedOutputStream lateinit var outputWriter: PipedOutputStream
lateinit var outputReader: PipedInputStream lateinit var outputReader: PipedInputStream
lateinit var terminal: IOSafeTerminal var terminal: IOSafeTerminal? = null
fun setInputPair(inputWriter: PipedOutputStream, inputReader: PipedInputStream) { fun setInputPair(inputWriter: PipedOutputStream, inputReader: PipedInputStream) {
this.inputWriter = inputWriter this.inputWriter = inputWriter

View File

@ -1,29 +1,16 @@
package terminal package terminal
import java.util.ArrayList
class TerminalHistory { class TerminalHistory {
private val history: MutableList<String> private val history = mutableListOf("")
private var lineIndex: Int = 0 private var lineIndex = 0
val previousLine: String fun getPreviousLine() = if (isBeginning()) history[lineIndex] else history[--lineIndex]
get() = 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 private fun lastIndex() = history.size - 1
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
}
fun addLine(line: String) { fun addLine(line: String) {
history[lastIndex()] = line history[lastIndex()] = line
@ -31,10 +18,6 @@ class TerminalHistory {
lineIndex = lastIndex() lineIndex = lastIndex()
} }
private fun lastIndex(): Int {
return history.size - 1
}
fun updateCurrentLine(line: String) { fun updateCurrentLine(line: String) {
history[lineIndex] = line history[lineIndex] = line
} }