mabe02 / lanterna

Java library for creating text-based GUIs
GNU Lesser General Public License v3.0
2.24k stars 243 forks source link

Allow UnixTerminal to work without private mode (alternate screen) #466

Open keithkml opened 4 years ago

keithkml commented 4 years ago

We'd like to make a small interactive UI which does not use ANSI alternate screen. This doesn't seem that hard - UnixTerminal just needs to:

avl42 commented 4 years ago

Not sure if I understand this. So assume that a minimum height of 10 was set, and the terminal has its usual size of 24 lines. if the user then clears the screen, wich sets cursor position to topleft corner, then the app would use all 24 lines, but if cursor was at bottom, it would only come up and use 10 lines?

I've yet to look up diff between 0J and 2J.

I'm all for allowing lanterna apps to avoid private mode (even for standard utils, like "less", I often set the TERM to something dumber and then less's contents stay on screen after quit, but TERM doesn't help with lanterna)

Thanks a lot for the recent high-quality issues... my own lanterna projects only use screen layer, so I hardly ever notice gui bugs.

If you're into it, could you also do PRs? if not, no problem, I'll see what PRs I can come up with...

@mabe02 will be the one to merge the PR, but he has other priorities, so the more work we can do ahead, the faster it'll be fixed.

Keith Lea notifications@github.com schrieb am Do., 30. Apr. 2020 15:22:

We'd like to make a small interactive UI which does not use ANSI alternate screen. This doesn't seem that hard - UnixTerminal just needs to:

  • request & store the current cursor position in its constructor
  • require the developer to specify a minimum height, and print some newlines to stdout if there aren't enough rows available to achieve that
  • use [0J to clear screen from the top left corner (instead of [2J)
  • add the top left corner before calling setPosition
  • subtract the top left corner from findTerminalSize(), MouseActions, and maybe a few other places

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mabe02/lanterna/issues/466, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABIDBMXVJSURPPTGPOQA3BLRPF3PRANCNFSM4MVRMBQA .

avl42 commented 4 years ago

About "use [0J to clear screen from the top left corner (instead of [2J)"

I don't even know what <Esc>[0J is even supposed to do in the terminal. It doesn't show any visible effect in my tests... maybe you just wanted it "not to clear" the screen?

Even if lanterna eventually doesn't switch to alternate screen, it will pretty surely always need to start its screen- or gui-mode with an empty screen - otherwise, incremental updates would end up messing up the terminal, leaving spurious letters around. Lanterna has no way of knowing what characters are already on screen.

So, as much as I understand & support the wish for suppressing the alternative screen feature, if you want to do any kind of textgui you need a cleared screen to start.

Some workaround, for testing your ideas, would be to derive a new class NonPrivUnixTerminal from UnixTerminal and override enterPrivateMode and exitPrivateMode to do nothing, then let your app start with "new NonPrivUnixTerminal(...)" rather than the DefaultTerminalFactory...

keithkml commented 4 years ago

Thanks for the reply! I am planning to submit PR’s - glad you are open to the issues I’ve filed :) I just got approval from my employer to contribute.

I’ll double check the clear screen behavior - it seemed to work for me, but it occurs to me that in my case there’s usually nothing below the cursor, so maybe I wouldn’t have noticed anyway if it didn’t work.

mabe02 commented 4 years ago

Not sure I'm understanding what you are trying to do... You want to use the GUI classes on top of a terminal that isn't running in private mode?

keithkml commented 4 years ago

Yep! I actually have implemented this in our application by extending UnixTerminal and overriding a few functions, more or less how I described in this issue’s description above. It seems to work well.