ajalt / mordant

Multiplatform text styling for Kotlin command-line applications
https://ajalt.github.io/mordant/
Apache License 2.0
962 stars 35 forks source link

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

Open gavr123456789 opened 1 month ago

gavr123456789 commented 1 month ago

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 commented 1 month ago

x64 or arm?

gavr123456789 commented 1 month ago

х64