jline: split up cli line reading

This commit is contained in:
Bixilon 2023-03-19 16:40:46 +01:00
parent abbf5d0f84
commit d9a3221df4
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 19 additions and 13 deletions

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2022 Moritz Zwerger
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*

View File

@ -70,11 +70,14 @@ object CLI {
this::connection.observe(this) { register() }
reader.pollLines()
}
private fun LineReader.pollLines() {
while (true) {
var line = ""
val line: String
try {
line = reader.readLine().trimWhitespaces()
line = readLine().trimWhitespaces()
terminal.flush()
} catch (exception: EndOfFileException) {
Log.log(LogMessageType.GENERAL, LogLevels.VERBOSE) { exception.printStackTrace() }
@ -87,10 +90,14 @@ object CLI {
exception.printStackTrace()
continue
}
try {
if (line.isBlank()) {
continue
if (line.isBlank()) continue
processLine(line)
}
}
private fun processLine(line: String) {
try {
ROOT_NODE.execute(line, connection)
} catch (error: ReaderError) {
Log.log(LogMessageType.OTHER, LogLevels.WARN) { error.message }
@ -98,7 +105,6 @@ object CLI {
error.printStackTrace()
}
}
}
object NodeCompleter : Completer {