Reflowing ConPTY: Add programmatic reflow & plain-text render #21458

Open
opened 2026-01-31 07:45:22 +00:00 by claunia · 0 comments
Owner

Originally created by @Unit2795 on GitHub (Apr 1, 2024).

Originally assigned to: @lhecker on GitHub.

Description of the new feature/enhancement

Synopsis:

  1. Expose ConPTY's reflow capability as a separate function to allow programmatic reflow of text containing VT sequences.
  2. A function to output plain text as it would appear in the console from text containing VT sequences could be useful for applications that cannot interpret VT sequences.

Both of these already seem to be part of the library but are not documented or exposed publicly.

Description

Reflow

Applications may maintain their own buffer/scrollback history that is larger than the buffer size of ConPTY. Issuing ResizePseudoConsole alone may not be adequate in this case (or if reflow output is disabled using PSEUDOCONSOLE_RESIZE_QUIRK). A function where you provide text containing VT sequences along with from/to character grid dimensions and receive the reflowed output would be useful. TextBuffer::Reflow may already suffice?

  • Not many premade libraries exist for this. Some candidates I found:
  • If you don’t also resize ConPTY, you’ll need to perform this reflow calculation on each output from ConPTY

Plain-text Render

Much like ReadConsoleOutputCharacter where you can read the characters in a console. A function where you supply text containing VT sequences, have it rendered, and receive the plain-text output as it would appear in the console would be useful for display in situations where plain text is the only option.

Use-cases

  1. ConPTY output is being displayed in multiple terminals of differing size or is being displayed a while after it has been produced (such as for replays or history).
  2. ConPTY output is being utilized/displayed by something that cannot interpret VT sequences; such as in email, pattern/regex matching, dialogs, txt files, etc.

Proposed technical implementation details (optional)

Possible Solutions:

  1. Add a function that exposes the reflow capability of ConPTY. Taking an input string containing VT sequences, an original terminal size, and a desired terminal size; and outputting the reflowed text. Though since the buffer may be larger than the desired size (such as a scrollback history with thousands of lines) some special precautions may need to be taken?

    • Example Pseudocode:

      ReflowConsoleText(inputText, fromSize, toSize)
      ReflowConsoleText("\x1b[48;1HHELLOWORLD", {x=80,y=24}, {x=120,y=30})
      
  2. Add a function that renders text containing VT sequences into plain text:

    • Example Pseudocode:

      PlainConsoleText(inputText, size)
      PlainConsoleText("\x1b[48;1HHELLOWORLD", {x=120,y=30})
      // Output: "HELLOWORLD"
      

Related

Originally created by @Unit2795 on GitHub (Apr 1, 2024). Originally assigned to: @lhecker on GitHub. # Description of the new feature/enhancement ## Synopsis: 1. Expose ConPTY's reflow capability as a separate function to allow programmatic reflow of text containing VT sequences. 2. A function to output plain text as it would appear in the console from text containing VT sequences could be useful for applications that cannot interpret VT sequences. Both of these already seem to be part of the library but are not documented or exposed publicly. - https://github.com/microsoft/terminal/blob/de7f931228312996a8b586e5348d5dda46610b84/src/buffer/out/textBuffer.cpp#L2527 - https://github.com/microsoft/terminal/blob/de7f931228312996a8b586e5348d5dda46610b84/src/buffer/out/textBuffer.cpp#L2053 ## Description ### Reflow Applications may maintain their own buffer/scrollback history that is larger than the buffer size of ConPTY. Issuing [ResizePseudoConsole](https://learn.microsoft.com/en-us/windows/console/resizepseudoconsole) alone may not be adequate in this case (or if reflow output is disabled using `PSEUDOCONSOLE_RESIZE_QUIRK`). A function where you provide text containing VT sequences along with from/to character grid dimensions and receive the reflowed output would be useful. [`TextBuffer::Reflow`](https://github.com/microsoft/terminal/blob/de7f931228312996a8b586e5348d5dda46610b84/src/buffer/out/textBuffer.cpp#L2527) may already suffice? - Not many premade libraries exist for this. Some candidates I found: - https://github.com/darrenstarr/VtNetCore - If you don’t also resize ConPTY, you’ll need to perform this reflow calculation on each output from ConPTY ### Plain-text Render Much like [ReadConsoleOutputCharacter](https://learn.microsoft.com/en-us/windows/console/readconsoleoutputcharacter) where you can read the characters in a console. A function where you supply text containing VT sequences, have it rendered, and receive the plain-text output as it would appear in the console would be useful for display in situations where plain text is the only option. ## Use-cases 1. ConPTY output is being displayed in multiple terminals of differing size or is being displayed a while after it has been produced (such as for replays or history). 2. ConPTY output is being utilized/displayed by something that cannot interpret VT sequences; such as in email, pattern/regex matching, dialogs, txt files, etc. # Proposed technical implementation details (optional) Possible Solutions: 1. Add a function that exposes the reflow capability of ConPTY. Taking an input string containing VT sequences, an original terminal size, and a desired terminal size; and outputting the reflowed text. Though since the buffer may be larger than the desired size (such as a scrollback history with thousands of lines) some special precautions may need to be taken? - Example Pseudocode: ``` ReflowConsoleText(inputText, fromSize, toSize) ReflowConsoleText("\x1b[48;1HHELLOWORLD", {x=80,y=24}, {x=120,y=30}) ``` 2. Add a function that renders text containing VT sequences into plain text: - Example Pseudocode: ``` PlainConsoleText(inputText, size) PlainConsoleText("\x1b[48;1HHELLOWORLD", {x=120,y=30}) // Output: "HELLOWORLD" ``` # Related - https://github.com/microsoft/terminal/issues/16911
claunia added the Issue-FeatureNeeds-TriageNeeds-Tag-Fix labels 2026-01-31 07:45:22 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#21458