Linux: Exception in thread "main" com.sun.jna.LastErrorException: [25] Inappropriate ioctl for device
Linux Arch
GNOME Terminal
import com.github.ajalt.colormath.Color
import com.github.ajalt.colormath.model.HSL
import com.github.ajalt.colormath.model.Oklab
import com.github.ajalt.colormath.model.RGB
import com.github.ajalt.colormath.transform.interpolator
import com.github.ajalt.mordant.animation.coroutines.animateInCoroutine
import com.github.ajalt.mordant.animation.textAnimation
import com.github.ajalt.mordant.input.KeyboardEvent
import com.github.ajalt.mordant.input.MouseEvent
import com.github.ajalt.mordant.input.MouseTracking
import com.github.ajalt.mordant.input.coroutines.receiveEventsFlow
import com.github.ajalt.mordant.input.isCtrlC
import com.github.ajalt.mordant.rendering.AnsiLevel
import com.github.ajalt.mordant.rendering.TextColors
import com.github.ajalt.mordant.terminal.Terminal
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.takeWhile
import kotlinx.coroutines.launch
suspend fun main() = coroutineScope {
val terminal = Terminal(ansiLevel = AnsiLevel.TRUECOLOR, interactive = true)
var hue = 0
val canvas = List(terminal.info.height - 1) {
MutableList<Color>(terminal.info.width) { RGB("#000") }
}
val animation = terminal.textAnimation<Unit> {
buildString {
for ((y, row) in canvas.withIndex()) {
for ((x, color) in row.withIndex()) {
append(TextColors.color(color).bg(" "))
canvas[y][x] = Oklab.interpolator {
stop(color)
stop(RGB("#000"))
}.interpolate(0.025)
}
append("\n")
}
}
}.animateInCoroutine()
launch { animation.execute() }
terminal.receiveEventsFlow(MouseTracking.Button)
.takeWhile { it !is KeyboardEvent || !it.isCtrlC }
.filterIsInstance<MouseEvent>()
.filter { it.left }
.collect { event ->
canvas[event.y][event.x] = HSL(hue.toDouble(), 1, .5)
hue += 2
}
animation.clear()
}
There are 2 black squares between error:
> ./gradlew jvmRun -DmainClass=MainKt --quiet
Exception in thread "main" com.sun.jna.LastErrorException: [25] Inappropriate ioctl for device
at com.sun.jna.Native.invokeVoid(Native Method)
at com.sun.jna.Function.invoke(Function.java:418)
at com.sun.jna.Function.invoke(Function.java:364)
at com.sun.jna.Library$Handler.invoke(Library.java:270)
at com.github.ajalt.mordant.internal.syscalls.jna.$Proxy0.tcgetattr(Unknown Source)
at com.github.ajalt.mordant.internal.syscalls.jna.SyscallHandlerJnaLinux.getStdinTermios(SyscallHandler.jna.linux.kt:88)
at com.github.ajalt.mordant.internal.syscalls.SyscallHandlerPosix.enterRawMode(SyscallHandler.posix.kt:102)
at com.github.ajalt.mordant.input.RawModeKt.enterRawMode(RawMode.kt:21)
at com.github.ajalt.mordant.input.coroutines.ReceiveEventsFlowKt$receiveEventsFlow$1.invokeSuspend(ReceiveEventsFlow.kt:17)
at com.github.ajalt.mordant.input.coroutines.ReceiveEventsFlowKt$receiveEventsFlow$1.invoke(ReceiveEventsFlow.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':jvmRun'.
> Process 'command '/usr/lib/jvm/java-21-graalvm/bin/java'' finished with non-zero exit value 1
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
BUILD FAILED in 565ms
x64 or arm?
х64
I get the same error on Ubuntu 24.04 if i write
val terminal = Terminal(interactive = true)
val rawMode = terminal.enterRawMode()
When I copy the whole command that IntelliJ runs in a terminal, then I don't get an error message.
Thanks, I'll see if I can repro this locally. In the mean time, if you're able to use Java 22+ to test the FFM module to see if this is a JNA issue or not, that would be very helpful.
Sorry, I dont know what I should change in my Code. I loaded it in my Gradle-File. Now I get this error:
Exception in thread "main" java.lang.RuntimeException: failed to read terminal settings
at com.github.ajalt.mordant.terminal.terminalinterface.ffm.TerminalInterfaceFfmLinux.getStdinTermios(TerminalInterface.ffm.linux.kt:99)
at com.github.ajalt.mordant.terminal.terminalinterface.TerminalInterfacePosix.enterRawMode(TerminalInterface.posix.kt:109)
at com.github.ajalt.mordant.input.RawModeKt.enterRawMode(RawMode.kt:19)
at com.github.ajalt.mordant.input.RawModeKt.enterRawMode$default(RawMode.kt:15)
at org.example.SnakeUI.<init>(SnakeUI.kt:11)
at org.example.SnakeController.<init>(Main.kt:20)
at org.example.MainKt.main(Main.kt:7)
at org.example.MainKt.main(Main.kt)
Hi there! I faced with the same issue when I try to run the project with an interactive list multi-select directly in the IDEA. I use MacBook Pro M1 (MacOS 15.2 (24C101)) Meantime the run of the built .jar directly in the terminal works fine. Also if I comment the part of code responsible for the call of interactive list - everything also looks nice.
x toggle • ↑ up • ↓ down • enter confirmException in thread "main" com.sun.jna.LastErrorException: [25] Inappropriate ioctl for device
at com.sun.jna.Native.invokeVoid(Native Method)
at com.sun.jna.Function.invoke(Function.java:418)
at com.sun.jna.Function.invoke(Function.java:364)
at com.sun.jna.Library$Handler.invoke(Library.java:270)
at com.github.ajalt.mordant.terminal.terminalinterface.jna.$Proxy0.tcgetattr(Unknown Source)
at com.github.ajalt.mordant.terminal.terminalinterface.jna.TerminalInterfaceJnaMacos.getStdinTermios(TerminalInterface.jna.macos.kt:92)
at com.github.ajalt.mordant.terminal.terminalinterface.TerminalInterfacePosix.enterRawMode(TerminalInterface.posix.kt:109)
at com.github.ajalt.mordant.input.RawModeKt.enterRawMode(RawMode.kt:19)
at com.github.ajalt.mordant.input.ReceiveEventsKt.receiveEvents(ReceiveEvents.kt:16)
at com.github.ajalt.mordant.input.InteractiveSelectListKt.interactiveMultiSelectListString(InteractiveSelectList.kt:122)