[PR #10906] [MERGED] Implement and action for manually clearing the Terminal (and conpty) buffer #28288

Open
opened 2026-01-31 09:27:32 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/10906
Author: @zadjii-msft
Created: 8/9/2021
Status: Merged
Merged: 9/2/2021
Merged by: @undefined

Base: mainHead: dev/migrie/fhl-2021/clear-buffer-action


📝 Commits (10+)

  • 2436cc0 Blindly, I think this is the conpty half of the ask
  • 8e0ed29 This plumbs #1882 and #1193 all the way through.
  • 9c56177 The revert I was talking about
  • 6a07e3b This is almost right, but we're clearing the attributes of the top line, which is not right.
  • 885fbcc whatever, it works man
  • 9024fd2 Merge remote-tracking branch 'origin/main' into dev/migrie/fhl-2021/clear-buffer-action
  • a0d0a94 add a roundtrip test
  • eb7db72 much cleanup. Add resource strings
  • 2cde76a Comments comments comments
  • 397efc7 Write a test for ControlCore

📊 Changes

35 files changed (+536 additions, -1 deletions)

View changed files

📝 src/cascadia/TerminalApp/AppActionHandlers.cpp (+16 -0)
📝 src/cascadia/TerminalConnection/ConptyConnection.cpp (+10 -0)
📝 src/cascadia/TerminalConnection/ConptyConnection.h (+1 -0)
📝 src/cascadia/TerminalConnection/ConptyConnection.idl (+1 -0)
📝 src/cascadia/TerminalControl/ControlCore.cpp (+31 -0)
📝 src/cascadia/TerminalControl/ControlCore.h (+3 -0)
📝 src/cascadia/TerminalControl/ControlCore.idl (+9 -0)
📝 src/cascadia/TerminalControl/TermControl.cpp (+4 -0)
📝 src/cascadia/TerminalControl/TermControl.h (+2 -0)
📝 src/cascadia/TerminalControl/TermControl.idl (+2 -0)
📝 src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp (+2 -0)
📝 src/cascadia/TerminalSettingsModel/ActionArgs.cpp (+19 -0)
📝 src/cascadia/TerminalSettingsModel/ActionArgs.h (+53 -0)
📝 src/cascadia/TerminalSettingsModel/ActionArgs.idl (+7 -1)
📝 src/cascadia/TerminalSettingsModel/AllShortcutActions.h (+2 -0)
📝 src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw (+12 -0)
📝 src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h (+10 -0)
📝 src/cascadia/TerminalSettingsModel/defaults.json (+1 -0)
📝 src/cascadia/UnitTests_Control/ControlCoreTests.cpp (+132 -0)
📝 src/cascadia/UnitTests_TerminalCore/ConptyRoundtripTests.cpp (+83 -0)

...and 15 more files

📄 Description

Summary of the Pull Request

clear-buffer-000

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

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

  • 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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/10906 **Author:** [@zadjii-msft](https://github.com/zadjii-msft) **Created:** 8/9/2021 **Status:** ✅ Merged **Merged:** 9/2/2021 **Merged by:** [@undefined](undefined) **Base:** `main` ← **Head:** `dev/migrie/fhl-2021/clear-buffer-action` --- ### 📝 Commits (10+) - [`2436cc0`](https://github.com/microsoft/terminal/commit/2436cc09e980b0b7784832cbffefc8787dce8c44) Blindly, I think this is the conpty half of the ask - [`8e0ed29`](https://github.com/microsoft/terminal/commit/8e0ed2973cddce1b14cf132e94cbe1717f798600) This plumbs #1882 and #1193 all the way through. - [`9c56177`](https://github.com/microsoft/terminal/commit/9c56177da51b1b7a20cb20e17fdab76dc75e6217) The revert I was talking about - [`6a07e3b`](https://github.com/microsoft/terminal/commit/6a07e3bfa997bb5b286939a353f7a03d6fa52fc9) This is almost right, but we're clearing the attributes of the top line, which is _not_ right. - [`885fbcc`](https://github.com/microsoft/terminal/commit/885fbcc2df8c72db790c2f666d431178147c6267) whatever, it works man - [`9024fd2`](https://github.com/microsoft/terminal/commit/9024fd2342769688c4cd47094fef5ad1b8fa1173) Merge remote-tracking branch 'origin/main' into dev/migrie/fhl-2021/clear-buffer-action - [`a0d0a94`](https://github.com/microsoft/terminal/commit/a0d0a942835f6294a1529abfb1bc176e43b32cdf) add a roundtrip test - [`eb7db72`](https://github.com/microsoft/terminal/commit/eb7db72e7b1d534213c69c5717a28779938d6996) much cleanup. Add resource strings - [`2cde76a`](https://github.com/microsoft/terminal/commit/2cde76afa34db6392d7af3fe40550d79ca09d3fe) Comments comments comments - [`397efc7`](https://github.com/microsoft/terminal/commit/397efc7b02defd8e34ba43e801bdece75d874f91) Write a test for ControlCore ### 📊 Changes **35 files changed** (+536 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/TerminalApp/AppActionHandlers.cpp` (+16 -0) 📝 `src/cascadia/TerminalConnection/ConptyConnection.cpp` (+10 -0) 📝 `src/cascadia/TerminalConnection/ConptyConnection.h` (+1 -0) 📝 `src/cascadia/TerminalConnection/ConptyConnection.idl` (+1 -0) 📝 `src/cascadia/TerminalControl/ControlCore.cpp` (+31 -0) 📝 `src/cascadia/TerminalControl/ControlCore.h` (+3 -0) 📝 `src/cascadia/TerminalControl/ControlCore.idl` (+9 -0) 📝 `src/cascadia/TerminalControl/TermControl.cpp` (+4 -0) 📝 `src/cascadia/TerminalControl/TermControl.h` (+2 -0) 📝 `src/cascadia/TerminalControl/TermControl.idl` (+2 -0) 📝 `src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp` (+2 -0) 📝 `src/cascadia/TerminalSettingsModel/ActionArgs.cpp` (+19 -0) 📝 `src/cascadia/TerminalSettingsModel/ActionArgs.h` (+53 -0) 📝 `src/cascadia/TerminalSettingsModel/ActionArgs.idl` (+7 -1) 📝 `src/cascadia/TerminalSettingsModel/AllShortcutActions.h` (+2 -0) 📝 `src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw` (+12 -0) 📝 `src/cascadia/TerminalSettingsModel/TerminalSettingsSerializationHelpers.h` (+10 -0) 📝 `src/cascadia/TerminalSettingsModel/defaults.json` (+1 -0) 📝 `src/cascadia/UnitTests_Control/ControlCoreTests.cpp` (+132 -0) 📝 `src/cascadia/UnitTests_TerminalCore/ConptyRoundtripTests.cpp` (+83 -0) _...and 15 more files_ </details> ### 📄 Description ## 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:27:32 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#28288