TUI opens below cursor thus shifts the prompt up

I have been wondering for a while now. When you use the terminal, your prompt is mostly at the bottom in an interactive session, except when you open the terminal window.

So… here’s the thing I do not understand.

The prompt is at the bottom and you invoke atuin via Ctrl-R. The inline_height is set to let’s say about 50% of what you terminal height is. what happens then is the following, no matter if invert is true or false:

The current prompt is moved to the middle of the terminal and the tui is presented below the prompt. One of the reasons I set invert to true is because I dislike my cursor jumping around like crazy when I work in the terminal. I always want my cursor close to the prompt I am working on.
If I use invert=false, my prompt does not only jump to middle of the terminal, the cursor then jumps to the bottom of the terminal.

Example with invert=true


Now here is my question: Why does the TUI not open above the prompt?

Afaik ratatui apps save (or can save) the current terminal and restore it afterwards, so the text won’t be gone after the TUI ends.
Additionally the prompt would still be at the bottom, when atuin’s TUI is invoked (no jump of prompt) and the cursor would also be close to the prompt to input your search term. No more jumping of prompt or cursor.

1 Like

I guess it’s because the application doesn’t know what was previously above the prompt. (Well, unless you draw things outside the current terminal, e.g. in a new pane of tmux.)

Hmm, this can’t be it. e.g. you can run the ratatui examples. After they exit, the terminal looks as it was before.

As I mentioned, ratatui saves the terminal state (content) and restores it afterwards. One can even do pop up windows and whatnot.

So from an architectural point: 1) save state 2) create TUI from current y to y - inline_height 3) after TUI exit, restore terminal

Which example do you mean? I don’t see an example that can use part of the screen and the restore it with previous content. Full screen programs can use the alternative screen so they can switch back when done, but it’s fullscreen.

I remember an example where part of the terminal was obstructed with a window. I have to aearch for it. But maybe there are some ratatui experts in this forum who can elaborate on this.

Pretty much the only way you can render something over the top of previous output (without replacing it) is with the alternate screen (“altscreen”), which is full screen only - as @lilydjwg has already said. You can read more about these here

Otherwise, you can either move the cursor around and overwrite previous input (and be careful not to hit the prompt), or just scroll down like we do at the moment. Overwriting previous output is almost certainly not desired for most people, and would likely be very error-prone.

You can see the implementation for Ratatui’s inline viewport here - which Conrad completed from fdehau’s initial work, specifically for Atuin to use:

You may have mixed this up with the “insert before” behaviour, which shifts an already-existing inline ratatui viewport down, in order to render text above it.

This is really strange. I have this “altscreen” behavior clearly in my mind for non-fullscreen terminal apps. I have to trace back where this is coming from. :thinking: This is driving me nuts.

In this case I want to apologize to @lilydjwg: I was wrong.

Unfortunately this also makes my initial question obsolete. :cry:

With that sentiment, I wish it was possible…