lotabout / tuikit

Tool kit for writing TUI applications in Rust.
MIT License
104 stars 28 forks source link

Inconsistent terminal state after tuikit exits, cursor position seems to reset #3

Closed totph closed 5 years ago

totph commented 5 years ago

If I modify the Hello World! 你好!今日は。 example by moving tuikit into a function and adding printf!() statements[1] most terminals do not position the cursor to print these lines correctly.

Expected (after export PS1='> ') and input Down/Right/q):

> target/release/tuikit-demo
press arrow key to move the text, (q) to quit

 end of main2 你好!今日は。

after tuikit is done
> 

In screen one line is missing:

> target/release/tuikit-demo 
press arrow key to move the text, (q) to quit

 end of main2 你好!今日は。
after tuikit is done
> 

However in xterm, konsole, terminator and some gnome-terminals I get:

after tuikit is donekit-demo 
> ess arrow key to move the text, (q) to quit

 end of main2 你好!今日は。

and if I have command output from for i in 1 2 3 4; do echo $i; done the result is:

after tuikit is donedo echo $i; done
> <-- THE NEW PROMPT IS HERE NOW
2
3
4
> target/release/tuikit-demo 
press arrow key to move the text, (q) to quit

 end of main2 你好!今日は。

The very first "correct" output is also from gnome-terminal, but most instances show the same mistakes.

1:

fn main2() {
    // was: let term = Term::with_height(TermHeight::Percent(30)).unwrap();
    let term = Term::with_height(TermHeight::Fixed(5)).unwrap();
    /*  rest of the hello-world main */
    println!("end of main2 ");
}
fn main() {
    main2();
    println!("after tuikit is done");
}
lotabout commented 5 years ago

@totph Would you please try again using term.print(0, 0, "end of main2 ")? The characters printed by println will mess up with tuikit.

totph commented 5 years ago

Even removing both println!() calls does not seem to fix it, konsole (18.08.3), terminator (1.91), gnome-terminal (3.30.2 using VTE 0.54.3 +GNUTLS) and xterm (334) still reset the cursor 0, 0 after exiting.

Same with urxvt (9.22), where $TERM is rxvt-unicode and which reads /usr/share/terminfo/r/rxvt-unicode instead of xterm-256color / /usr/share/terminfo/x/xterm-256color. In screen (reading /usr/share/terminfo/s/screen it all works fine.

With the let _ = term.print(0, 0, "end of main2 "); let _ = term.present(); at the end of main2():

ABCor i in 1 2 3 4 $TERM; do echo $i; done
> 
2
3
4
rxvt-unicode
> tuikit-demo; echo ABC
end of main2 ey to move the text, (q) to quit
totph commented 5 years ago

The very first "correct" output is also from gnome-terminal, but most instances show the same mistakes.

I could finally reproduce why some terminals are correct after using them for actual work:

> for i in `seq 1000`; do echo $i; done  # ensure the terminal has a scrollbar
[...]
997
998
999
1000
> vim   # open and close (:wq) vim
> tuikit-demo
end of main2 ey to move the text, (q) to quit

>  # everything works as expected
> ~/tuikit-demo
end of main2 ey to move the text, (q) to quit

 end of main2, println!()

after tuikit is done
> # even with println!()

vim is version 8.1, and it seems to "fix" all tested terminal emulators when a scollbar is present. But until this combination happens the output is jumbled.

lotabout commented 5 years ago

@totph I'd like to define "correct" behavior: All lines drawn by tuikit should be cleared after it exits.

Please try the latest snapshot for this behavior.

[dependencies]
tuikit = { git = "https://github.com/lotabout/tuikit.git" }
totph commented 5 years ago

Great, thanks! It now works as expected.

Though I could also think of situations where the last buffer state which tuikit showed should remain preserved on the terminal.