[PR #14989] [MERGED] Add support for the DECRQCRA checksum report #30333

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/14989
Author: @j4james
Created: 3/14/2023
Status: Merged
Merged: 3/14/2023
Merged by: @DHowett

Base: mainHead: feature-decrqcra


📝 Commits (5)

  • 2a7ecff Hook up the DECRQCRA sequence to the dispatcher.
  • e25f173 Implement DECRQCRA checksum.
  • 296f7db Hide DECRQCRA support behind a feature flag.
  • 5ae902d Add some unit tests.
  • 837d797 Add expected words to spelling dictionary.

📊 Changes

11 files changed (+208 additions, -0 deletions)

View changed files

📝 .github/actions/spelling/expect/expect.txt (+5 -0)
📝 src/features.xml (+10 -0)
📝 src/terminal/adapter/ITermDispatch.hpp (+1 -0)
📝 src/terminal/adapter/adaptDispatch.cpp (+78 -0)
📝 src/terminal/adapter/adaptDispatch.hpp (+1 -0)
📝 src/terminal/adapter/termDispatch.hpp (+1 -0)
📝 src/terminal/adapter/ut_adapter/adapterTest.cpp (+105 -0)
📝 src/terminal/parser/OutputStateMachineEngine.cpp (+4 -0)
📝 src/terminal/parser/OutputStateMachineEngine.hpp (+1 -0)
📝 src/terminal/parser/telemetry.cpp (+1 -0)
📝 src/terminal/parser/telemetry.hpp (+1 -0)

📄 Description

This PR implements the DECRQCRA escape sequence, which lets you
request a checksum of a portion of the screen. This is most useful in
automated testing to verify that the generated screen content is what it
was expected to be.

For now this functionality is gated behind a feature flag which is only
enabled for dev builds.

Detailed Description of the Pull Request / Additional comments

I've done my best to match the DEC checksum algorithm as closely as
possible, which we've determined by testing on a real VT525 terminal
(many thanks to @al20878 for that).

The checksum is an unsigned 16-bit value that starts off at zero, and
from which you then subtract the ordinal value of every character in the
selected range. It's also affected by the rendition attributes in the
selected cells.

  • Bold/Intense - subtract 0x80
  • Blinking - subtract 0x40
  • Reverse video - subtract 0x20
  • Underlined - subtract 0x10
  • Invisible - subtract 0x08
  • Protected - subtract 0x04
  • Background color - subtract the color index
  • Foreground color - subtract the color index * 0x10

I should note that our ordinal calculation only matches DEC for the
characters in the ASCII and Latin-1 range, because the original
algorithm predates Unicode. If we want to support the other character
sets correctly we'll need custom mapping tables, but I didn't think that
was essential for now.

It's also worth mentioning that we don't handle "empty" cells correctly,
but that's not the fault of the checksum calculation - it's just that
our default fill character is a space rather than a NUL.

Validation Steps Performed

I've manually compared our implementation against the tests results that
@al20878 got from the VT525, and confirmed that we match as well as was
expected (i.e. taking into account the limitations mentioned above).

I've also added a few basic unit tests that verify we're generating the
expected checksums for the various renditions and color attributes.

Closes #14974


🔄 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/14989 **Author:** [@j4james](https://github.com/j4james) **Created:** 3/14/2023 **Status:** ✅ Merged **Merged:** 3/14/2023 **Merged by:** [@DHowett](https://github.com/DHowett) **Base:** `main` ← **Head:** `feature-decrqcra` --- ### 📝 Commits (5) - [`2a7ecff`](https://github.com/microsoft/terminal/commit/2a7ecfff0170e1f8ed1b313acd63b8261de86569) Hook up the DECRQCRA sequence to the dispatcher. - [`e25f173`](https://github.com/microsoft/terminal/commit/e25f173612764bf088e7f2f9ce002cf1a8780197) Implement DECRQCRA checksum. - [`296f7db`](https://github.com/microsoft/terminal/commit/296f7db9e0e0792a2d5d2d716294bf17329e83b2) Hide DECRQCRA support behind a feature flag. - [`5ae902d`](https://github.com/microsoft/terminal/commit/5ae902d86920b448528b09000a5ab1ecf8ec95a7) Add some unit tests. - [`837d797`](https://github.com/microsoft/terminal/commit/837d797e4ca4426181f27c228478108462995109) Add expected words to spelling dictionary. ### 📊 Changes **11 files changed** (+208 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `.github/actions/spelling/expect/expect.txt` (+5 -0) 📝 `src/features.xml` (+10 -0) 📝 `src/terminal/adapter/ITermDispatch.hpp` (+1 -0) 📝 `src/terminal/adapter/adaptDispatch.cpp` (+78 -0) 📝 `src/terminal/adapter/adaptDispatch.hpp` (+1 -0) 📝 `src/terminal/adapter/termDispatch.hpp` (+1 -0) 📝 `src/terminal/adapter/ut_adapter/adapterTest.cpp` (+105 -0) 📝 `src/terminal/parser/OutputStateMachineEngine.cpp` (+4 -0) 📝 `src/terminal/parser/OutputStateMachineEngine.hpp` (+1 -0) 📝 `src/terminal/parser/telemetry.cpp` (+1 -0) 📝 `src/terminal/parser/telemetry.hpp` (+1 -0) </details> ### 📄 Description This PR implements the `DECRQCRA` escape sequence, which lets you request a checksum of a portion of the screen. This is most useful in automated testing to verify that the generated screen content is what it was expected to be. For now this functionality is gated behind a feature flag which is only enabled for dev builds. ## Detailed Description of the Pull Request / Additional comments I've done my best to match the DEC checksum algorithm as closely as possible, which we've determined by testing on a real VT525 terminal (many thanks to @al20878 for that). The checksum is an unsigned 16-bit value that starts off at zero, and from which you then subtract the ordinal value of every character in the selected range. It's also affected by the rendition attributes in the selected cells. * Bold/Intense - subtract 0x80 * Blinking - subtract 0x40 * Reverse video - subtract 0x20 * Underlined - subtract 0x10 * Invisible - subtract 0x08 * Protected - subtract 0x04 * Background color - subtract the color index * Foreground color - subtract the color index * 0x10 I should note that our ordinal calculation only matches DEC for the characters in the ASCII and Latin-1 range, because the original algorithm predates Unicode. If we want to support the other character sets correctly we'll need custom mapping tables, but I didn't think that was essential for now. It's also worth mentioning that we don't handle "empty" cells correctly, but that's not the fault of the checksum calculation - it's just that our default fill character is a space rather than a `NUL`. ## Validation Steps Performed I've manually compared our implementation against the tests results that @al20878 got from the VT525, and confirmed that we match as well as was expected (i.e. taking into account the limitations mentioned above). I've also added a few basic unit tests that verify we're generating the expected checksums for the various renditions and color attributes. Closes #14974 --- <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:40:10 +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#30333