mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 02:45:13 -04:00
jline: split up cli line reading
This commit is contained in:
parent
abbf5d0f84
commit
d9a3221df4
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Minosoft
|
* 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.
|
* 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() }
|
this::connection.observe(this) { register() }
|
||||||
|
|
||||||
|
reader.pollLines()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun LineReader.pollLines() {
|
||||||
while (true) {
|
while (true) {
|
||||||
var line = ""
|
val line: String
|
||||||
try {
|
try {
|
||||||
line = reader.readLine().trimWhitespaces()
|
line = readLine().trimWhitespaces()
|
||||||
terminal.flush()
|
terminal.flush()
|
||||||
} catch (exception: EndOfFileException) {
|
} catch (exception: EndOfFileException) {
|
||||||
Log.log(LogMessageType.GENERAL, LogLevels.VERBOSE) { exception.printStackTrace() }
|
Log.log(LogMessageType.GENERAL, LogLevels.VERBOSE) { exception.printStackTrace() }
|
||||||
@ -87,16 +90,19 @@ object CLI {
|
|||||||
exception.printStackTrace()
|
exception.printStackTrace()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
try {
|
if (line.isBlank()) continue
|
||||||
if (line.isBlank()) {
|
|
||||||
continue
|
processLine(line)
|
||||||
}
|
}
|
||||||
ROOT_NODE.execute(line, connection)
|
}
|
||||||
} catch (error: ReaderError) {
|
|
||||||
Log.log(LogMessageType.OTHER, LogLevels.WARN) { error.message }
|
private fun processLine(line: String) {
|
||||||
} catch (error: Throwable) {
|
try {
|
||||||
error.printStackTrace()
|
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