Skip to content

Feature Request Move scroll buffer instead of clearing on CTRL+L and on clear #2832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bbhopesh opened this issue Sep 20, 2019 · 19 comments · Fixed by #5683
Closed

Feature Request Move scroll buffer instead of clearing on CTRL+L and on clear #2832

bbhopesh opened this issue Sep 20, 2019 · 19 comments · Fixed by #5683
Labels
Area-VT Virtual Terminal sequence support Issue-Task It's a feature request, but it doesn't really need a major design. Priority-0 Bugs that we consider release-blocking/recall-class (P0) Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Milestone

Comments

@bbhopesh
Copy link

Description of the new feature/enhancement

On WSL, Typing clear or pressing CTRL+L clears the scroll buffer history while most Linux terminals(both real ones like gnome-terminal, and virtual ones like tmux) move the scroll history instead of clearing it. Can we use same semantics for Windows Terminal?

@bbhopesh bbhopesh added the Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. label Sep 20, 2019
@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Sep 20, 2019
@j4james
Copy link
Collaborator

j4james commented Sep 21, 2019

As far as I know, clearing the scrollback buffer has been the expected behaviour of the clear command for several years now. From the man page:

clear clears your screen if this is possible, including its scrollback buffer (if the extended “E3” capability is defined).

There are more details in the man page documenting the history of the change if you're interested.

And if you don't like this behaviour, you may be able to update your terminfo to remove the E3 capability, which I think should get you the old behaviour. There's an answer on superuser.com describing how to do this for CentOS, which may also work for WSL (I haven't tried it myself).

https://superuser.com/a/1110683

@bbhopesh
Copy link
Author

By old behavior, you mean the behavior of clearing scroll back buffer instead of just moving it?

I am actually looking for behavior where scroll buffer is not cleared and I still have capability to scroll back and see older commands.

@egmontkob
Copy link

On modern Linux systems, clear and Ctrl+L do different things. clear instructs the terminal emulator to clear the history, and most terminals do so. bash's Ctrl+L keyboard shortcut doesn't, it preserves the scrollback buffer, just like clear -x.


About clearing the current screen (but not the scrollback):

The traditional way of implementing onscreen clear (without clearing the scrollback), e.g. the way xterm does it, is simply to erase the onscreen lines. This results in the last screenful of your work getting wiped out: e.g. execute seq 1000, then press Ctrl+L, scroll back, the last number is 977 or so.

Some terminals (e.g. VTE, and Konsole up until recently) think this is not what the user wants to have, and instead push these lines up into the scrollback buffer. [There is even a difference of 1 between the number of lines VTE scrolls vs. Konsole scrolled out. VTE scrolls one more, you often end up with a blank line. Konsole, however, wiped out the partial line before the cursor if your output didn't end in a newline.] [A terminal could even easily implement an adaptive scrollout, based on the cursor's location, or the actual onscreen nonempty vs. empty lines.]

clear (in ncurses) about a year ago fixed its behavior to clear the onscreen contents first, followed by the scrollback. Up until a year ago it performed these two steps in the opposite order, which resulted in one page of data remaining in the scrollback in VTE and recent Konsole.

See VTE 506438 for boring details, most of which are no longer relevant due to this recent fix in clear; as well as Konsole 384218 for their counterpart, and also how they reverted to the traditional behavior unaware of the recent clear fix which made it pointless.


About clearing (or not) the scrollback:

As of the aforementioned clear fix, the entire scrollback is properly cleaned both on xterm-like and VTE-like emulators.

However, nothing stops a terminal from offering a config option to deliberately refuse to clear the scrollback, just as filed at VTE 771953 (not yet implemented). Not sure how much it's worth it. One could argue that user can just alias clear to clear -x, or hack around in terminfo as per an aforementioned answer, and that's probably good enough.

@j4james
Copy link
Collaborator

j4james commented Sep 21, 2019

One could argue that user can just alias clear to clear -x

I hadn't noticed that -x option - this seems like the perfect solution to me. I definitely wouldn't be in favour of adding a terminal option to break the E3 functionality - that sounds like a recipe for disaster.

@bbhopesh
Copy link
Author

I am coming here from gnome world(Ubuntu 18.0, Fedora Workstation). In gnome-terminal, CTRL+L and clear behave almost identically if not exactly. -x flag is a useful workaround for now but I am more used to CTRL+L and I will find it extremely useful if I could configure what CTRL+L does on Windows terminal.

@DHowett-MSFT
Copy link
Contributor

What ^L does is up to your shell, not up to the terminal. Sorry!

@egmontkob
Copy link

Well, ^L emits the standard clear escape sequence, most likely ^[[H^[[2J, out of which the second half matters here. And as I've stated before, there's some room for terminals to behave differently here, like xterm clearing in-place the onscreen contents vs. VTE scrolling them out.

I think both of them are equally valid, since probably no terminal emulation standard knows about a scrollback buffer. Anything that happens to the scrollback is unspecified territory.

IMO in an ideal world all terminals and applications would agree on the behavior, decide whose responsibility it is to scroll out, and then consistently implement scrolling out the contents, since losing the last page of data is hardly likely what the user wants. Unfortunately there's no common agreement whether this should be the responsibility of the terminal or the application, hence the confusion and the hacks like vte's. So you can also change Windows Terminal's behavior to some extent and remain standards-complying.

@DHowett-MSFT
Copy link
Contributor

That’s fair, actually. I think that conhost implements scroll-off for ED 2, but perhaps somewhere in our translation later we are mishandling that. Standardization would be great 😄

@bbhopesh
Copy link
Author

I didn't spend enough time to understand how ctrl+l or clear work but it looks like when a virtual terminal is running, it handles ctrl+l and when it is not physical terminal handles it e.g. when I am using tmux on Windows terminal, ctrl+l is handled by tmux. It moves tmux's scroll buffer instead of clearing it. However, when tmux is not running, windows terminal handles it and clears the scroll buffer.

@zadjii-msft zadjii-msft added Area-VT Virtual Terminal sequence support Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal. and removed Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. labels Sep 23, 2019
@zadjii-msft zadjii-msft added this to the Terminal v1.0 milestone Sep 23, 2019
@DHowett-MSFT DHowett-MSFT removed the Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting label Sep 23, 2019
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Sep 23, 2019
@getify
Copy link

getify commented Nov 8, 2019

iterm2 (mac) has "cmd+r" for the kind of clear that is just scrolling the contents off screen (but not clearing the buffer). I find this a useful form of clearing.

It would be nice if there was a "command" for "clearByScroll" or something like that, so that we could assign our own keyboard shortcut for it.

@ghost ghost added Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. and removed In-PR This issue has a related PR labels May 5, 2020
ghost pushed a commit that referenced this issue May 5, 2020
The Erase All VT sequence (`^[[2J`) is supposed to erase the entire
contents of the viewport. The way it usually does this is by shifting
the entirety of the viewport contents into scrollback, and starting the
new viewport below it. 

Currently, conpty doesn't propagate that state change correctly. When
conpty gets a 2J, it simply erases the content of the connected
terminal's viewport, by writing over it with spaces. Conpty didn't
really have a good way of communicating "your viewport should move", it
only knew "the buffer is now full of spaces".

This would lead to bugs like #2832, where pressing <kbd>ctrl+L</kbd> in
`bash` would delete the current contents of the viewport, instead of
moving the viewport down.

This PR makes sure that when conpty sees a 2J, it passes that through
directly to the connected terminal application as well. Fortunately, 2J
was already implemented in the Windows Terminal, so this actually fixes
the behavior of <kbd>ctrl+L</kbd>/`clear` in WSL in the Terminal.

## References

* #4252 - right now this isn't the _most_ optimal scenario, we're
  literally just printing a 2J, then we'll perform "erase line" `height`
  times. The erase line operations are all redundant at this point - the
  entire viewport is blank, but conpty doesn't really know that.
  Fortunately, #4252 was already filed for me to come through and
  optimize this path.

## PR Checklist
* [x] Closes #2832
* [x] I work here
* [x] Tests added/passed
* [n/a] Requires documentation to be updated

## Validation Steps Performed
* ran tests
* compared <kbd>ctrl+L</kbd> with its behavior in conhost
* compared `clear` with its behavior in conhost
DHowett-MSFT pushed a commit that referenced this issue May 5, 2020
The Erase All VT sequence (`^[[2J`) is supposed to erase the entire
contents of the viewport. The way it usually does this is by shifting
the entirety of the viewport contents into scrollback, and starting the
new viewport below it. 

Currently, conpty doesn't propagate that state change correctly. When
conpty gets a 2J, it simply erases the content of the connected
terminal's viewport, by writing over it with spaces. Conpty didn't
really have a good way of communicating "your viewport should move", it
only knew "the buffer is now full of spaces".

This would lead to bugs like #2832, where pressing <kbd>ctrl+L</kbd> in
`bash` would delete the current contents of the viewport, instead of
moving the viewport down.

This PR makes sure that when conpty sees a 2J, it passes that through
directly to the connected terminal application as well. Fortunately, 2J
was already implemented in the Windows Terminal, so this actually fixes
the behavior of <kbd>ctrl+L</kbd>/`clear` in WSL in the Terminal.

## References

* #4252 - right now this isn't the _most_ optimal scenario, we're
  literally just printing a 2J, then we'll perform "erase line" `height`
  times. The erase line operations are all redundant at this point - the
  entire viewport is blank, but conpty doesn't really know that.
  Fortunately, #4252 was already filed for me to come through and
  optimize this path.

## PR Checklist
* [x] Closes #2832
* [x] I work here
* [x] Tests added/passed
* [n/a] Requires documentation to be updated

## Validation Steps Performed
* ran tests
* compared <kbd>ctrl+L</kbd> with its behavior in conhost
* compared `clear` with its behavior in conhost
DHowett-MSFT pushed a commit that referenced this issue May 5, 2020
The Erase All VT sequence (`^[[2J`) is supposed to erase the entire
contents of the viewport. The way it usually does this is by shifting
the entirety of the viewport contents into scrollback, and starting the
new viewport below it.

Currently, conpty doesn't propagate that state change correctly. When
conpty gets a 2J, it simply erases the content of the connected
terminal's viewport, by writing over it with spaces. Conpty didn't
really have a good way of communicating "your viewport should move", it
only knew "the buffer is now full of spaces".

This would lead to bugs like #2832, where pressing <kbd>ctrl+L</kbd> in
`bash` would delete the current contents of the viewport, instead of
moving the viewport down.

This PR makes sure that when conpty sees a 2J, it passes that through
directly to the connected terminal application as well. Fortunately, 2J
was already implemented in the Windows Terminal, so this actually fixes
the behavior of <kbd>ctrl+L</kbd>/`clear` in WSL in the Terminal.

## References

* #4252 - right now this isn't the _most_ optimal scenario, we're
  literally just printing a 2J, then we'll perform "erase line" `height`
  times. The erase line operations are all redundant at this point - the
  entire viewport is blank, but conpty doesn't really know that.
  Fortunately, #4252 was already filed for me to come through and
  optimize this path.

## PR Checklist
* [x] Closes #2832
* [x] I work here
* [x] Tests added/passed
* [n/a] Requires documentation to be updated

## Validation Steps Performed
* ran tests
* compared <kbd>ctrl+L</kbd> with its behavior in conhost
* compared `clear` with its behavior in conhost

(cherry picked from commit 9fe624f)
@getify
Copy link

getify commented May 11, 2020

It's not clear what the outcome is of this issue?

@DHowett-MSFT
Copy link
Contributor

There was a pull request that fixed it, and there was a fix, and that fix was committed, and that's the absolute most current status of this issue.

@zadjii-msft
Copy link
Member

zadjii-msft commented May 11, 2020

I implemented support for passing through the ^[[2J sequence (which is emitted when the user presses ctrl+L or runs clear) in #5683. It'll be available in a future Windows Terminal release (when the bot comes through and says it is 😝)

EDIT: damn Dustin beat me

@ghost
Copy link

ghost commented May 13, 2020

🎉This issue was addressed in #5683, which has now been successfully released as Windows Terminal Release Candidate v0.11.1333.0 (1.0rc2).:tada:

Handy links:

@KaKi87
Copy link

KaKi87 commented May 21, 2020

Hello,
I'm currently running v0.11.1333.0, and, while clear and cls works, Ctrl+L doesn't.
Any ideas why ?
Thanks

@DHowett
Copy link
Member

DHowett commented May 21, 2020

That depends very heavily on what she’ll you are using. It is your shell’s job to handle Ctrl+L.

What shell are you using?

@KaKi87
Copy link

KaKi87 commented May 21, 2020

As recommended in #5458, I emptied my settings file, so that defaults can be regenerated.
And, the default shell in the default configuration is set to PowerShell 6.
So, in PowerShell 6, Ctrl + L doesn't work.
Thanks

@jbraidju
Copy link

Ctrl-L is literally ^L; (0x0C/FF/Form Feed) in ASCII.

To quote wikipedia, it "moves a printer to top of next page". It does NOT move back up page, erasing what has gone before. So it should scroll the buffer, providing a clear page in the terminal, but preserving history, as if you were still using a teletype (which is what a video terminal is really; an advanced teletype that uses light instead of paper), and it had printed a bunch of blank lines.

@KaKi87
Copy link

KaKi87 commented Nov 24, 2021

True, but the visual consequence is that the visible area is cleared, I actually don't really care how it should be done, but just that I want it to be doable using Ctrl+L.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-VT Virtual Terminal sequence support Issue-Task It's a feature request, but it doesn't really need a major design. Priority-0 Bugs that we consider release-blocking/recall-class (P0) Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants