Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gavr123456789 opened this issue Jul 31, 2024 · 4 comments

Comments

@gavr123456789
Copy link

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
@ajalt
Copy link
Owner

ajalt commented Aug 6, 2024

x64 or arm?

@gavr123456789
Copy link
Author

х64

@TheGhostOfTomJoad
Copy link

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.

@ajalt
Copy link
Owner

ajalt commented Sep 26, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants