-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Description
I'm trying to listen for terminal inputs in a coroutine, to do so I think we need to use rawMode.readEventOrNull(...) so that cancelling cooperates, unless there's a better way?
runBlocking {
val inputCoroutine = launch(Dispatchers.IO) {
terminal.enterRawMode(MouseTracking.Off).use { rawMode ->
while (isActive) {
val event = rawMode.readEventOrNull(50.milliseconds) // <- throws here
if(event is KeyboardEvent && event.isCtrlC) {
println("EXIT")
exitProcess(0)
}
}
}
}
delay(5000)
inputCoroutine.cancelAndJoin()
println("DONE")
}But then a RuntimeException is thrown on Windows instead of returning null:
Exception in thread "main" java.lang.RuntimeException: Timeout reading from console input
at com.github.ajalt.mordant.terminal.terminalinterface.jna.TerminalInterfaceJnaWindows.readRawEvent(TerminalInterface.jna.windows.kt:278)
at com.github.ajalt.mordant.terminal.terminalinterface.TerminalInterfaceWindows.readInputEvent(TerminalInterface.windows.kt:85)
at com.github.ajalt.mordant.input.RawModeScope.readEventOrNull-LRDsOJo(RawMode.kt:140)
at net.stephcraft.MainKt$main$1$2$inputCoroutine$1.invokeSuspend(Main.kt:329)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:113)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:89)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:586)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:820)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels