-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
Implement and action for manually clearing the Terminal (and conpty) buffer #10906
Conversation
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.
…ne, which is _not_ right.
…lear-buffer-action
This comment has been minimized.
This comment has been minimized.
…lear-buffer-action
… not building the whole sln
@check-spelling-bot ReportUnrecognized words, please review:
Previously acknowledged words that are now absentSPACEBAR UnregisterTo accept these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands... in a clone of the git@github.com:microsoft/terminal.git repository
✏️ Contributor please read thisBy default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.
If the listed items are:
See the 🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉 🗜️ If you see a bunch of garbageIf it relates to a ... well-formed patternSee if there's a pattern that would match it. If not, try writing one and adding it to a Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines. Note that patterns can't match multiline strings. binary-ish stringPlease add a file path to the File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty confident with the Terminal stuff (except maybe TermConnection). The rest looks good too, but I'm a lot less familiar with that area.
@@ -366,6 +366,7 @@ | |||
{ "command": "scrollUpPage", "keys": "ctrl+shift+pgup" }, | |||
{ "command": "scrollToTop", "keys": "ctrl+shift+home" }, | |||
{ "command": "scrollToBottom", "keys": "ctrl+shift+end" }, | |||
{ "command": { "action": "clearBuffer", "clear": "all" } }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ "command": { "action": "clearBuffer", "clear": "all" } }, | |
{ "command": { "action": "clearBuffer", "clear": "all" } }, | |
{ "command": { "action": "clearBuffer", "clear": "screen" } }, | |
{ "command": { "action": "clearBuffer", "clear": "scrollback" } }, |
Should we just go ahead and add all three to the command palette? It's filterable anyways. It also has the added benefit of allowing you to bind it to a key chord via SUI (because actions w/ args are not supported unless they've already been defined).
short sNewTop = oldCursorPos.Y; | ||
const Viewport oldViewport = _viewport; | ||
|
||
short delta = (sNewTop + _viewport.Height()) - (GetBufferSize().Height()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
short delta = (sNewTop + _viewport.Height()) - (GetBufferSize().Height()); | |
const short delta = (sNewTop + _viewport.Height()) - (GetBufferSize().Height()); |
auto fillPosition = COORD{ 0, _viewport.Top() + 1 }; | ||
auto fillLength = gsl::narrow_cast<size_t>(_viewport.Height() * GetBufferSize().Width()); | ||
auto fillData = OutputCellIterator{ fillAttributes, fillLength }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto fillPosition = COORD{ 0, _viewport.Top() + 1 }; | |
auto fillLength = gsl::narrow_cast<size_t>(_viewport.Height() * GetBufferSize().Width()); | |
auto fillData = OutputCellIterator{ fillAttributes, fillLength }; | |
const auto fillPosition = COORD{ 0, _viewport.Top() + 1 }; | |
const auto fillLength = gsl::narrow_cast<size_t>(_viewport.Height() * GetBufferSize().Width()); | |
const auto fillData = OutputCellIterator{ fillAttributes, fillLength }; |
Not sure if these can be const, but if they can, there ya go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, gonna approve. It is what it is.
I don't really like that we have to add another signal. Signaling to do the equivalent of SIGWNCH is well known and is what 8 is for, but this clear thing seems like a new invention which I'm not totally happy with. However... it's a problem that Windows sort of ends up with thanks to our weird architecture so I guess having our own solution is what's in order. Also it's just code so if we're proven wrong, we can just change it.
I want it to be like a VT signal on one of the existing channels, but on the input channel it makes no sense. And to get to the output channel, the alternative of making the Windows Terminal take a client-side reference to the same console as the client-app hosted in the ConPTY just to call clear seems ridiculous.
I think this is going to become less relevant over time as we approach passthrough mode where ConPTY will be less integral to the rendering on the Windows Terminal. But for now... the code must flow.
Hello @zadjii-msft! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
…lear-buffer-action
🎉 Handy links: |
As in microsoft/terminal#10906 ### Clear Buffer ([Preview](https://aka.ms/terminal-preview)) This action can be used to manually clear the Terminal buffer. This is useful for scenarios where you're not sitting at a command-line shell prompt and can't easily run `Clear-Host`/`cls`/`clear`. **Command name:** `clearBuffer` **Default bindings:** ```json { "command": { "action": "clearBuffer", "clear": "all" } }, ``` #### Actions | Name | Necessity | Accepts | Description | | ---- | --------- | ------- | ----------- | | `clear` | Optional | `"screen"`, `"scrollback"`, `"all"` | What part of the screen to clear. <ul><li>`"screen"`: Clear the terminal viewport content. Leaves the scrollback untouched. Moves the cursor row to the top of the viewport (unmodified).</li><li>`"scrollback"`: Clear the scrollback. Leaves the viewport untouched.</li><li>`"all"` (_default_): Clear the scrollback and the visible viewport. Moves the cursor row to the top of the viewport. </li></ul> | | `relative` | Optional | Boolean | If true, then adjust the current opacity by the given `opacity` parameter. If false, set the opacity to exactly that value. | > [!IMPORTANT] > This feature is only available in [Windows Terminal Preview](https://aka.ms/terminal-preview).
Summary of the Pull Request
This adds a new action,
clearBuffer
. It accepts 3 values for theclear
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
PR Checklist
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
ping -t 8.8.8.8
as you'd hope.