mordant icon indicating copy to clipboard operation
mordant copied to clipboard

Animations with newlines do not render correctly in JetBrains' run output

Open pindab0ter opened this issue 1 year ago • 5 comments

When I create a textAnimation, only everything after the last \n is cleared and redrawn.

import com.github.ajalt.mordant.animation.textAnimation
import com.github.ajalt.mordant.terminal.Terminal

fun main() {
    val terminal = Terminal()

    val animation = terminal.textAnimation<Int> { value -> "${value}\n" }

    for (i in 1..5) {
        animation.update(i)
        Thread.sleep(250)
    }
}

This results in:

1
2
3
4
5

However, when I add something after the final newline, e.g. "${value}\nTest", "Test" is drawn and replaced each time and ends up like so:

1
2
3
4
5
Test

Am I missing something, or is this a bug?

Edit: This is in the IntelliJ built-in terminal. Maybe related to #49?

pindab0ter avatar Dec 08 '24 00:12 pindab0ter

When running in a terminal with the generated run script by IntelliJ it doesn't work as intended, but when run through gradle :installDist && build/install/<…> it displays correctly.

Edit: When displayed in a normal terminal, proving that the problem lies in the IntelliJ run output 'terminal'.

I guess part of the question is: Is there a way to marry IntelliJ's "Run" feature with the terminal functionality Mordant needs somehow?

pindab0ter avatar Dec 08 '24 01:12 pindab0ter

You're correct that this is a known issue. Last I checked, the IntelliJ console doesn't support ANSI cursor movements, and we have code to specifically handle that case. Are you saying that you were able to get multi-line animations working on the IntelliJ console?

ajalt avatar Dec 09 '24 17:12 ajalt

Unfortunately no. What's more, animations in tasks run through Gradle also perform poorly. In the end I had to use the installDist task to generate a binary and run that to be able to reach 60fps. Maybe good to note somewhere in the docs.

pindab0ter avatar Dec 10 '24 08:12 pindab0ter

I have similar issue when using multiple progress bars, output gets duplicated in intellij console on every update, while works fine from normal console. Is this fixable?

NoUsernameProvided avatar Feb 24 '25 19:02 NoUsernameProvided

I don't think is fixable on Mordant's end, but you could try filing a bug against IntelliJ to get them to support ANSI cursor movements.

ajalt avatar Feb 24 '25 20:02 ajalt