[PR #14821] [MERGED] Add an efficient text stream write function #30262

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/14821
Author: @lhecker
Created: 2/10/2023
Status: ✅ Merged
Merged: 3/24/2023
Merged by: @DHowett

Base: main ← Head: dev/lhecker/8000-stream-writing


📝 Commits (10+)

  • a6c5e7a Add an efficient text stream write function
  • f8e6884 Address feedback, Simplify code
  • 3d04d37 Make spell-check happy
  • 99f19a9 Fix AuditMode failures
  • 173e916 Add CopyRangeFrom to later implement TextBuffer::Reflow
  • 5040328 Remove debug helpers
  • 17e3ca5 Fix AuditMode failures
  • f9fbb8a Fix compilation
  • d1163b5 Simplify member naming scheme, Improve performance
  • 94fbb52 Fix cursor movement and attribute writing

📊 Changes

18 files changed (+566 additions, -217 deletions)

View changed files

📝 .github/actions/spelling/expect/alphabet.txt (+1 -0)
📝 .github/actions/spelling/expect/expect.txt (+0 -2)
📝 src/buffer/out/Row.cpp (+270 -65)
📝 src/buffer/out/Row.hpp (+77 -3)
📝 src/buffer/out/precomp.h (+4 -38)
📝 src/buffer/out/textBuffer.cpp (+26 -0)
📝 src/buffer/out/textBuffer.hpp (+3 -0)
📝 src/cascadia/LocalTests_SettingsModel/pch.h (+3 -2)
📝 src/host/ut_host/ScreenBufferTests.cpp (+10 -0)
📝 src/host/ut_host/TextBufferTests.cpp (+82 -0)
📝 src/inc/LibraryIncludes.h (+9 -9)
📝 src/inc/test/CommonState.hpp (+7 -36)
📝 src/inc/til/point.h (+2 -0)
📝 src/inc/til/rle.h (+9 -0)
📝 src/inc/til/unicode.h (+24 -0)
📝 src/terminal/adapter/adaptDispatch.cpp (+34 -38)
📝 src/til/ut_til/RunLengthEncodingTests.cpp (+1 -1)
📝 tools/ConsoleTypes.natvis (+4 -23)

📄 Description

This adds PR adds a couple foundational functions and classes to make
our TextBuffer more performant and allow us to improve our Unicode
correctness in the future, by getting rid of our dependence on
OutputCellIterator. In the future we can then replace the simple
UTF-16 code point iterator with a proper grapheme cluster iterator.

While my focus is technically on Unicode correctness, the ~4x VT
throughput increase in OpenConsole is pretty nice too.

This PR adds:

  • A new, simpler ROW iterator (unused in this PR)
  • Cursor movement functions (NavigateToPrevious, NavigateToNext)
    They're based on functions that align the cursor to the start/end
    of the current cell, so such functions can be added as well.
  • ReplaceText to write a raw string of text with the possibility to
    specify a right margin.
  • CopyRangeFrom will allow us to make reflow much faster, as it's able
    to bulk-copy already measured strings without re-measuring them.

Related to #8000

Validation Steps Performed

  • enwik8.txt, zhwik8.txt, emoji-test.txt, all work with proper
    wide glyph reflow at the end of a row ✅
  • This produces "a 咪" where only "a" has a white background:
    printf '\e7こん\e8\x1b[107ma\x1b[m\n'
    
  • This produces "abん":
    stdbuf -o0 printf '\x1b7こん\x1b8a'; printf 'b\n'
    
  • This produces "xy" at the end of the line:
    stdbuf -o0 printf '\e[999C\bこ\bx'; printf 'y\n'
    
  • This produces red whitespace followed by "こ " in the default
    background color at the end of the line, and "ん" on the next line:
    printf '\e[41m\e[K\e[m\e[999C\e[2Dこん\n'
    

🔄 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/14821 **Author:** [@lhecker](https://github.com/lhecker) **Created:** 2/10/2023 **Status:** ✅ Merged **Merged:** 3/24/2023 **Merged by:** [@DHowett](https://github.com/DHowett) **Base:** `main` ← **Head:** `dev/lhecker/8000-stream-writing` --- ### 📝 Commits (10+) - [`a6c5e7a`](https://github.com/microsoft/terminal/commit/a6c5e7a9436c5377a5c7c93e6aba6d206e8385fa) Add an efficient text stream write function - [`f8e6884`](https://github.com/microsoft/terminal/commit/f8e6884fac1460661737bdc600ed5f2796fa9052) Address feedback, Simplify code - [`3d04d37`](https://github.com/microsoft/terminal/commit/3d04d37b3aef45804aff9b259ce269da91bbb8c5) Make spell-check happy - [`99f19a9`](https://github.com/microsoft/terminal/commit/99f19a9c0adb0763b748203664d0dcbe3126b4bf) Fix AuditMode failures - [`173e916`](https://github.com/microsoft/terminal/commit/173e916bcdd648f78a895bc6a5e1304a2088f09f) Add CopyRangeFrom to later implement TextBuffer::Reflow - [`5040328`](https://github.com/microsoft/terminal/commit/5040328a06fa31a70f7aadcdc109019fce402a66) Remove debug helpers - [`17e3ca5`](https://github.com/microsoft/terminal/commit/17e3ca539065ad8f895456ce0a0a412da501cd4f) Fix AuditMode failures - [`f9fbb8a`](https://github.com/microsoft/terminal/commit/f9fbb8ab3d4b227fdb7a19a4f0b9713924e85995) Fix compilation - [`d1163b5`](https://github.com/microsoft/terminal/commit/d1163b5eaa287e2ee80d98776a4c2ff955ad2dff) Simplify member naming scheme, Improve performance - [`94fbb52`](https://github.com/microsoft/terminal/commit/94fbb52d5832ffbeed959e545b977acaeb199160) Fix cursor movement and attribute writing ### 📊 Changes **18 files changed** (+566 additions, -217 deletions) <details> <summary>View changed files</summary> 📝 `.github/actions/spelling/expect/alphabet.txt` (+1 -0) 📝 `.github/actions/spelling/expect/expect.txt` (+0 -2) 📝 `src/buffer/out/Row.cpp` (+270 -65) 📝 `src/buffer/out/Row.hpp` (+77 -3) 📝 `src/buffer/out/precomp.h` (+4 -38) 📝 `src/buffer/out/textBuffer.cpp` (+26 -0) 📝 `src/buffer/out/textBuffer.hpp` (+3 -0) 📝 `src/cascadia/LocalTests_SettingsModel/pch.h` (+3 -2) 📝 `src/host/ut_host/ScreenBufferTests.cpp` (+10 -0) 📝 `src/host/ut_host/TextBufferTests.cpp` (+82 -0) 📝 `src/inc/LibraryIncludes.h` (+9 -9) 📝 `src/inc/test/CommonState.hpp` (+7 -36) 📝 `src/inc/til/point.h` (+2 -0) 📝 `src/inc/til/rle.h` (+9 -0) 📝 `src/inc/til/unicode.h` (+24 -0) 📝 `src/terminal/adapter/adaptDispatch.cpp` (+34 -38) 📝 `src/til/ut_til/RunLengthEncodingTests.cpp` (+1 -1) 📝 `tools/ConsoleTypes.natvis` (+4 -23) </details> ### 📄 Description This adds PR adds a couple foundational functions and classes to make our TextBuffer more performant and allow us to improve our Unicode correctness in the future, by getting rid of our dependence on `OutputCellIterator`. In the future we can then replace the simple UTF-16 code point iterator with a proper grapheme cluster iterator. While my focus is technically on Unicode correctness, the ~4x VT throughput increase in OpenConsole is pretty nice too. This PR adds: * A new, simpler ROW iterator (unused in this PR) * Cursor movement functions (`NavigateToPrevious`, `NavigateToNext`) They're based on functions that align the cursor to the start/end of the _current_ cell, so such functions can be added as well. * `ReplaceText` to write a raw string of text with the possibility to specify a right margin. * `CopyRangeFrom` will allow us to make reflow much faster, as it's able to bulk-copy already measured strings without re-measuring them. Related to #8000 ## Validation Steps Performed * enwik8.txt, zhwik8.txt, emoji-test.txt, all work with proper wide glyph reflow at the end of a row ✅ * This produces "a 咪" where only "a" has a white background: ```sh printf '\e7こん\e8\x1b[107ma\x1b[m\n' ``` * This produces "abん": ```sh stdbuf -o0 printf '\x1b7こん\x1b8a'; printf 'b\n' ``` * This produces "xy" at the end of the line: ```sh stdbuf -o0 printf '\e[999C\bこ\bx'; printf 'y\n' ``` * This produces red whitespace followed by "こ " in the default background color at the end of the line, and "ん" on the next line: ```sh printf '\e[41m\e[K\e[m\e[999C\e[2Dこん\n' ``` --- <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:39:39 +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#30262