diff --git a/src/main/kotlin/terminal/TerminalConfiguration.kt b/src/main/kotlin/terminal/TerminalConfiguration.kt index d3b88a3..90615e9 100644 --- a/src/main/kotlin/terminal/TerminalConfiguration.kt +++ b/src/main/kotlin/terminal/TerminalConfiguration.kt @@ -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 diff --git a/src/main/kotlin/terminal/TerminalHistory.kt b/src/main/kotlin/terminal/TerminalHistory.kt index f721d78..b246a39 100644 --- a/src/main/kotlin/terminal/TerminalHistory.kt +++ b/src/main/kotlin/terminal/TerminalHistory.kt @@ -1,29 +1,16 @@ package terminal -import java.util.ArrayList - class TerminalHistory { - private val history: MutableList - 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 }