jline / jline3

JLine is a Java library for handling console input.
Other
1.49k stars 217 forks source link

Full-screen Display on windows goes off by one line #963

Closed jvalkeal closed 6 months ago

jvalkeal commented 6 months ago

In spring-shell with full-screen terminal app(on windows) I noticed an issue [1041] that there is extra line break thus causing lines to go vertically off by one line. This essentially makes first line scroll out and extra empty line at a bottom. Linked issue has screenshots which probably makes it more clear than what I tried to describe above. It does't matter which combination is used cmd/powershell and jna/jansi.

Looks to be caused by:

https://github.com/jline/jline3/blob/19c031c0bccaeea6a4346bc82c04c7bd3ec18888/terminal/src/main/java/org/jline/utils/Display.java#L310-L312

I did some experiments by forking Display class to try out some fixes and something like this seems to work.

if (this.wrapAtEol) {
    if (fullScreen && lineIndex < numLines) {
        terminal.writer().write(" \b");
        cursorPos++;
    }
}

I started to read what terminal caps eat_newline_glitch and auto_right_margin mean and now I'm not sure if my proposed fix would be good enough to PR it. While this look to fix my issue I'm wondering if it's a generic fix. Writing space and backspace looks to go back to issue [123].

I was reading https://stackoverflow.com/questions/31360385/an-obscure-one-documented-vt100-soft-wrap-escape-sequence and it gets awfully complex around line breaks.

[1041] https://github.com/spring-projects/spring-shell/issues/1041 [123] https://github.com/jline/jline3/issues/123

gnodet commented 6 months ago

Yes, line breaks are a mess :-(

jvalkeal commented 6 months ago

Would you like me to PR this change?

gnodet commented 6 months ago

Yes, the space + backspace think should not be done on the last line I think, or at least, not when running in a fullscreen application mode, where you don't really want the screen to scroll at all.