mordant icon indicating copy to clipboard operation
mordant copied to clipboard

Linux: Exception in thread "main" com.sun.jna.LastErrorException: [25] Inappropriate ioctl for device

Open gavr123456789 opened this issue 1 year ago • 6 comments

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: image

> ./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

gavr123456789 avatar Jul 31 '24 03:07 gavr123456789

x64 or arm?

ajalt avatar Aug 06 '24 15:08 ajalt

х64

gavr123456789 avatar Aug 06 '24 23:08 gavr123456789

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.

MaximilianHertenstein avatar Sep 26 '24 18:09 MaximilianHertenstein

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.

ajalt avatar Sep 26 '24 20:09 ajalt

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)

MaximilianHertenstein avatar Oct 06 '24 07:10 MaximilianHertenstein

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)

den-solo-work avatar Dec 19 '24 09:12 den-solo-work