nushell: Missing lines in terminal scrollback

Describe the bug

I’ve noticed that whenever the prompt is printed, a number of lines are trimmed from the top of the screen.

unfortunately I haven’t had the time to test thoroughly.

How to reproduce

  1. set a prompt taller than a single line
  2. run a command with more lines of output than the terminal is tall (e.g. seq 0 100)
  3. scroll up
  4. observe that several lines of the command are missing

Expected behavior

I expect that all lines of input and output are visible in the terminal history

Screenshots

image image

Configuration

key value
version 0.75.1
branch main
commit_hash 1096e653b0b03728a7d5ba56fc3ad703395bcfbe
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.66.1 (90743e729 2023-01-10)
rust_channel 1.66.1-x86_64-unknown-linux-gnu
cargo_version cargo 1.66.1 (ad779e08b 2023-01-10)
pkg_version 0.75.1
build_time 2023-02-12 19:31:10 +08:00
build_rust_channel release
features database, default, trash, which, zip
installed_plugins

Additional context

Possibly related to nushell/reedline#620

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 22 (3 by maintainers)

Most upvoted comments

Want to check in on this issue. Tested a little bit more and tried out some passable fixes.

First, I reproduced this issue on Alacritty, Windows Terminal and Console host on windows and also newest version of Alacritty on nixOS and Ubuntu. This issue can be triggered in one of two ways:

  1. Set your prompt to something multiline via $env.PROMPT_COMMAND = {|| "\n1\n2\n>" } Fill entire screen with stuff (e.g. use 1..100. Observer missing lines near edge of window.
  2. Have a single line prompt. Fill like half or more of screen with stuff. Press f1 or ctrl+R (or open any other menu). Again observe missing lines near edge of window.

Some debugging shows that this (at least on platforms and terminals i tested) is not the same issue of missing history like in 589 mentioned earlier because even scroll of 1 deletes history. Thus any of my attempts at using ScrollUp(1) failed.

However I noticed that scrolling produced by printing “\n” on last line works just fine everywhere (thank god). Thus i suggest this simple fix here and here that sidesteps using scrolling entirely by replacing usage of self.stdout.queue(ScrollUp(extra))?; with:

self.stdout.queue(cursor::MoveTo(0, screen_height - 1))?;
for i in 0..extra {
    self.stdout.queue(Print(&coerce_crlf("\n")))?;
}

First the cursor is moved to the last line of window. This way if scroll is needed when cursor has not yet reached end of screen (e.g. when menu is rendered) it still works. Second scrolling is done via suitable number of line breaks (not entirely sure why, but doing it in one print does not work). Last the cursor must be moved in position where it was before, but in two places in reedline mentioned earlier this is not needed since cursor is moved immediately after anyways.

In my testing this fixes everything just fine. I can easily see how this is too hackish to merge for everyone. If not I can create a PR and do some more tests

This should be closed by nushell/reedline#601

Instructions for enabling debug mode can be found here.

Normally this is the location of the Windows Terminal settings file: ~\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json

  • Add “debugFeatures”: true
  • Restart the terminal
  • Press both alt keys when starting a new Nushell tab

Focus on the debug screen, rightclick on the tab and choose export Text to create a text file with the debug results.

FYI, I looked into this a couple of years back, and the terminals at the time that matched the Windows Terminal behavior included Gnome Terminal (assumedly all VTE derivatives), Konsole, Hyper, and PowerTerm. There were also a whole lot of terminals that didn’t support the SU sequence at all. Also worth mentioning that the original DEC hardware terminals used SU for something else entirely. The bottom line is that sequence is best avoided.

Edit: Konsole has been fixed since I last tested (merge request 589).