fixed CLI input problem and tetris sample

This commit is contained in:
Sergey Chernov 2026-05-10 13:00:08 +03:00
parent 31fac1a73c
commit 3e74019d9d
2 changed files with 5 additions and 6 deletions

View File

@ -636,13 +636,10 @@ if (!Console.isSupported()) {
}
}
var inputRunning = true
launch {
while (inputRunning) {
while (true) {
try {
for (ev in Console.events()) {
if (!inputRunning) break
// Isolate per-event failures so one bad event does not unwind the stream.
try {
if (ev is ConsoleKeyEvent) {
@ -675,7 +672,6 @@ if (!Console.isSupported()) {
}
} catch (err: Object) {
// Recover stream-level failures by recreating event stream in next loop turn.
if (!inputRunning) break
logError("Input stream recovered after error", err)
Console.setRawMode(true)
delay(50)
@ -803,7 +799,6 @@ if (!Console.isSupported()) {
delay(FRAME_DELAY_MS)
}
} finally {
inputRunning = false
Console.setRawMode(false)
Console.setCursorVisible(true)
Console.leaveAltScreen()

View File

@ -237,6 +237,10 @@ object JvmLyngConsole : LyngConsole {
val attrs = term.attributes
attrs.setLocalFlag(Attributes.LocalFlag.ICANON, false)
attrs.setLocalFlag(Attributes.LocalFlag.ECHO, false)
attrs.setLocalFlag(Attributes.LocalFlag.IEXTEN, false)
attrs.setLocalFlag(Attributes.LocalFlag.ISIG, false)
attrs.setInputFlag(Attributes.InputFlag.ICRNL, false)
attrs.setInputFlag(Attributes.InputFlag.IXON, false)
attrs.setControlChar(Attributes.ControlChar.VMIN, 0)
attrs.setControlChar(Attributes.ControlChar.VTIME, 1)
term.setAttributes(attrs)