mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 10:25:06 -04:00
jline: split up cli line reading
This commit is contained in:
parent
abbf5d0f84
commit
d9a3221df4
@ -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.
|
||||
*
|
||||
|
@ -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,16 +90,19 @@ object CLI {
|
||||
exception.printStackTrace()
|
||||
continue
|
||||
}
|
||||
try {
|
||||
if (line.isBlank()) {
|
||||
continue
|
||||
}
|
||||
ROOT_NODE.execute(line, connection)
|
||||
} catch (error: ReaderError) {
|
||||
Log.log(LogMessageType.OTHER, LogLevels.WARN) { error.message }
|
||||
} catch (error: Throwable) {
|
||||
error.printStackTrace()
|
||||
}
|
||||
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 }
|
||||
} catch (error: Throwable) {
|
||||
error.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user