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

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

Original Pull Request: https://github.com/microsoft/terminal/pull/14821

State: closed
Merged: Yes


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'
    
**Original Pull Request:** https://github.com/microsoft/terminal/pull/14821 **State:** closed **Merged:** Yes --- 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' ```
claunia added the pull-request label 2026-01-31 09:39:40 +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#30267