Skip to content
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

Add a terminal-side shortcut for clearing the screen and/or scrollback #1882

Closed
prumbles opened this issue Jul 8, 2019 · 31 comments · Fixed by #10906
Closed

Add a terminal-side shortcut for clearing the screen and/or scrollback #1882

prumbles opened this issue Jul 8, 2019 · 31 comments · Fixed by #10906
Labels
Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.

Comments

@prumbles
Copy link

prumbles commented Jul 8, 2019

It would be great to have the equivalent of Command+K on the Mac terminal. This clears the terminal completely, not the equivalent of typing "clear", which only scrolls the cursor to the top of the terminal. My use case is the following:

  • Open an Ubuntu terminal
  • ssh into a server
  • run a command which may produce large amounts of content and exceptions within the content
  • fix the exceptions by making a code change
  • CLEAR the terminal completely (not just a "clear" command)
  • re-run the command
  • now that the previous command output was cleared, we can search for new exceptions without getting the previous exceptions
  • NOTE: this also requires a "ctrl+F" type feature to exist in the terminal, which currently does not
@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 Jul 8, 2019
@mdtauk
Copy link

mdtauk commented Jul 8, 2019

Why just clear screen? Why not a toolbar where common commands can be added as quick shortcuts?

@prumbles
Copy link
Author

prumbles commented Jul 8, 2019

But, this isn't a bash command, as I think that's what you are asking. Command+K on a mac doesn't run any commands in the terminal such as "clear"... it clears the entire terminal buffer. Commands such as "clear" don't do the equivalent. I personally don't need a toolbar - I'm fine with adding them to the "Settings.json" file like all the other keyboard shortcuts. Its just that "Clear terminal" is not one of the available options to create a shortcut for. If you use VSCode, the exact equivalent command is "Terminal:Clear". I map that to Alt+K to get the same experience.

@fzed51
Copy link

fzed51 commented Jul 11, 2019

Are we not talking about the same thing as issue # 1189 ?

@zadjii-msft
Copy link
Member

@fzed51 Nope, this is unrelated to that one.

To clarify for future me - cmd+k is not something that's being handled by bash or the shell. This is the Terminal itself handling the keybinding, and clearing both the buffer and the scrollback.

You've described a user story that makes sense to me, so I'm gonna put this on the backlog.

@zadjii-msft zadjii-msft added Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal. labels Jul 11, 2019
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Jul 11, 2019
@zadjii-msft zadjii-msft added this to the Terminal Backlog milestone Jul 11, 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 Jul 15, 2019
@DHowett-MSFT DHowett-MSFT changed the title Clear screen shortcut Add a terminal-side shortcut for clearing the screen and/or scrollback Jul 15, 2019
@eduardonunesp
Copy link

I would like to help with that if possible, shouldn't be so difficult right? I mean can be just reset the buffer and initialize again the buffer

@DHowett-MSFT
Copy link
Contributor

You should definitely read the comments here. Because of the windows console infrastructure we’re built on it’s not quite that easy.

@eduardonunesp
Copy link

Ok, I don't have any idea about the internals of the terminal, however, if in order to clear a buffer after press a key combination is so complex probably it will be impossible to scale the product when adding more complex stuff than this

@DHowett-MSFT
Copy link
Contributor

It's just this issue in particular that's thornier than most. For compatibility with Windows console applications that do not expect a terminal to be connected, we need to maintain a text buffer for them to read. That's all. Because we don't have a way to clear that text buffer (from the terminal side), and we just haven't written one yet, it's only more complex than clearing the local screen. It's not a complexity class issue with all of Terminal.

@eduardonunesp
Copy link

Gotcha, thanks for the clarification, definitely isn't a beginners task

@xoofx
Copy link

xoofx commented Jan 21, 2020

I'm discovering this while switching to this terminal and this is really annoying.
I was previously using cls to clear not only the screen but also the history, when you are using the same terminal for hours, and you are running commands that can generate errors, scrolling back is making things very difficult to spot which command is failing (when the errors can span on several pages), the sensitivity of the scroll is making too easy to scroll back to a previous command without noticing.

So big 👍 for a keystroke as I understand that cls is not meant for the history.

Thinking about it, also, as a nice improvement, maybe it is something that has a feature request on its own, but a "bird-view" side pane on the right side where we could spot easily where commands are and where are the outputs would be also super useful...

@DHowett

This comment has been minimized.

@mt33

This comment has been minimized.

@swinder0161

This comment has been minimized.

@zadjii-msft

This comment has been minimized.

@jijiechen
Copy link

On my terminal, it worked by input tput reset
But tput clear did not work.

@csabka
Copy link

csabka commented Mar 14, 2021

I have created a workaround which worked on WSL/bash, SSH/bash (Linux tested) and PowerShell 7 for me with CTRL+ALT+K:

{ "command": { "action": "sendInput", "input": "\u001B[H#\rtput reset || printf '\e[1J\e[3J\e[r'|| Clear-Host\r\u001B[A\u001B[A\u001B[H\u001B[3~\u001B[F" }, "name":"Clear screen and Scrollback", "keys": "ctrl+alt+k" },

These steps will done with sendInput action:

  1. send home key (if you already type something into shell)
  2. send # (comment out what you have already typed)
  3. send return (save commented out strings to history note: \n : only work on linux so I used \r)
  4. send tput reset or printf with CSI codes (if tput command fails) or Clear-Host (if both commands failed: eg in PowerShell)
  5. send two times up key for history (needs to have history in shells)
  6. send home key
  7. send delete key to remove first character "#" from the beginning (written by step 2.)
  8. send end key to put cursor back to the end (you can continue typing of the command)

For me the history and scrollback are cleared

@mia-riezebos
Copy link

open a second tab?

@carlosmunozrodriguez
Copy link

open a second tab?

I have a running process that is logging to the console, but since it is logging too much things and I just want to concentrate in newer lines I just want to clear the screen so new lines don't get confused with older ones.

A new tab doesn't work for this case

@tommiv
Copy link

tommiv commented Mar 24, 2021

Second tab doesn't work for many cases. SSH sessions, tail -f, long CWD you don't want to type again and again – to start with.

@chilipepper987
Copy link

Any updates on this? Still annoying that there is no clear scrollback option. That's the only thing stopping me from uninstalling MobaXTerm

@astraw
Copy link

astraw commented Jun 13, 2021

Others have noted that the command cls is not a perfect solution but for me it has reduced the issue to background noise and I am happy to have rediscovered cls (after approximately 30+ years -- I think I used to use it in DOS if I remember correctly).

zadjii-msft added a commit that referenced this issue Jul 29, 2021
  Unfortunately, I need to reset the cursor position, and I actually just need
  to do this differently entirely.

  iTerm actually maintains the last line of the buffer entirely. That's kind of
  important! Otherwise the prompt just disappears too.

  They're actually even smarter than that:
  * https://gitlab.com/gnachman/iterm2/-/issues/1330
  * https://gitlab.com/gnachman/iterm2/-/issues/4393

  and know where the prompt starts and ends, and keep all of multi-line prompts.
  That's a very 2023 feature, but we should keep at least one line.
@zadjii-msft
Copy link
Member

There are other details in #1193 for those interested in the technical bits.

For everyone else who's just here for results:
clear-buffer-000

@VanilsonFernandes
Copy link

There are other details in #1193 for those interested in the technical bits.

For everyone else who's just here for results:
clear-buffer-000

Nice work! This works while running a "ping google.com -t"?

Thanks

@ghost ghost added the In-PR This issue has a related PR label Aug 9, 2021
@ghost ghost closed this as completed in #10906 Sep 2, 2021
ghost pushed a commit that referenced this issue Sep 2, 2021
…buffer (#10906)

## Summary of the Pull Request

![clear-buffer-000](https://user-images.githubusercontent.com/18356694/127570078-90c6089e-0430-4dfc-bcd4-a0cde20c9167.gif)

This adds a new action, `clearBuffer`. It accepts 3 values for the `clear` type:
* `"clear": "screen"`: Clear the terminal viewport content. Leaves the scrollback untouched. Moves the cursor row to the top of the viewport (unmodified).
* `"clear": "scrollback"`: Clear the scrollback. Leaves the viewport untouched.
* `"clear": "all"`: (**default**) Clear the scrollback and the visible viewport. Moves the cursor row to the top of the viewport (unmodified).

"Clear Buffer" has also been added to `defaults.json`.

## References
* From microsoft/vscode#75141 originally

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

## Detailed Description of the Pull Request / Additional comments

This is a bit tricky, because we need to plumb it all the way through conpty to clear the buffer. If we don't, then conpty will immediately just redraw the screen. So this sends a signal to the attached conpty, and then waits for conpty to draw the updated, cleared, screen back to us.

## Validation Steps Performed
* works for each of the three clear types as expected
* tests pass.
* works even with `ping -t 8.8.8.8` as you'd hope.
@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 Sep 2, 2021
@KaoruDev
Copy link

KaoruDev commented Sep 21, 2021

I'm sort of confused, I'm hitting ctrl+shift+p to pull up the command menu, but I can't seem to find Clear buffer? I'm on version: 1.10.2383.0

@DHowett
Copy link
Member

DHowett commented Sep 21, 2021

1.12 should be the first version that has this feature.

@KaoruDev
Copy link

KaoruDev commented Sep 21, 2021

1.12 should be the first version that has this feature.

ah got it, thank you! can't wait!

@ghost
Copy link

ghost commented Oct 20, 2021

🎉This issue was addressed in #10906, which has now been successfully released as Windows Terminal Preview v1.12.2922.0.:tada:

Handy links:

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Issue-Task It's a feature request, but it doesn't really need a major design. 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.