[PR #2038] [MERGED] Refactor TextBuffer::GenHTML #24775

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/2038
Author: @mcpiroman
Created: 7/19/2019
Status: Merged
Merged: 8/6/2019
Merged by: @DHowett-MSFT

Base: dev/cazamor/html-copyHead: improve-html-copy


📝 Commits (6)

📊 Changes

4 files changed (+130 additions, -192 deletions)

View changed files

📝 src/buffer/out/textBuffer.cpp (+124 -187)
📝 src/buffer/out/textBuffer.hpp (+3 -2)
📝 src/cascadia/TerminalControl/TermControl.cpp (+2 -2)
📝 src/interactivity/win32/Clipboard.cpp (+1 -1)

📄 Description

Summary of the Pull Request

Modernizes style of code in TextBuffer::GenHTML and significantly simplifies structure of produced HTML. There is sill scope for improvement (customization in particular) but that's another story.

References

PR Checklist

Detailed Description of the Pull Request / Additional comments

  • Changed string to ostringstream for string building.
  • Changed 'sprintf_s` to c++ stream formatting.
  • Changed \r\n to <BR> in produced HTML.
  • Used already implemented function for UTF16->UTF8 conversion.
  • Now there is flat and minimalised list of <span>s with fg and bg color.
    Previous structure was.. weird. Each row was child span of previous row and there were empty spans with black color attributes in place of \r\n at end of the row. And all of this seemed unintended.
  • HTML text was unescaped, and it still is, becouse Word doesn't work with HTML entities, like &lt;. But it seems to accept the invalid HTML with > from prompts. So if there is no text like <someTextThatNowBecomesATag>, it should work.

Problems/questions:

  • So what to do with HTML escaping?
  • Is try still needed?
  • Bg color past last character in row is incorrect (actually it looks correct most of time as it doesn't change. But run e.g. mc to see it). Neither I and the function's author seemed to know how to fix this, becouse they (me at least) don't quite feel like HTML.
  • The width of pasted text is infinite but it should be either terminal's size or copied text's size. And it again looks like HTML thing.
  • If selection doesn't start at first character, this fact is ignored (the text is pasted as if it was the first character). No good, right?

🔄 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/2038 **Author:** [@mcpiroman](https://github.com/mcpiroman) **Created:** 7/19/2019 **Status:** ✅ Merged **Merged:** 8/6/2019 **Merged by:** [@DHowett-MSFT](https://github.com/DHowett-MSFT) **Base:** `dev/cazamor/html-copy` ← **Head:** `improve-html-copy` --- ### 📝 Commits (6) - [`4eeb916`](https://github.com/microsoft/terminal/commit/4eeb916ff187d49b27931c523c14870dd3640389) Refactor TextBuffer::GenHTML - [`93c1fdc`](https://github.com/microsoft/terminal/commit/93c1fdccc00d7c30934f9e7b5e80ecb1cddbc4f4) PR changes - [`4957ce2`](https://github.com/microsoft/terminal/commit/4957ce25264784d6872c81ece845d7c4d3d8a7ee) Rename not-const var - [`91ee8a9`](https://github.com/microsoft/terminal/commit/91ee8a9a9d0f76abbd829f0f6e8b7658bbd16369) PR changes - [`5f8d706`](https://github.com/microsoft/terminal/commit/5f8d706ca749b616d44008a7959cf7e3dd7af9ba) ops this shouldn't be here - [`e39d7f4`](https://github.com/microsoft/terminal/commit/e39d7f43c1328b9c052210fe60fa7abf8cc0ec7d) Remove unnecessary include ### 📊 Changes **4 files changed** (+130 additions, -192 deletions) <details> <summary>View changed files</summary> 📝 `src/buffer/out/textBuffer.cpp` (+124 -187) 📝 `src/buffer/out/textBuffer.hpp` (+3 -2) 📝 `src/cascadia/TerminalControl/TermControl.cpp` (+2 -2) 📝 `src/interactivity/win32/Clipboard.cpp` (+1 -1) </details> ### 📄 Description <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request Modernizes style of code in `TextBuffer::GenHTML` and significantly simplifies structure of produced HTML. There is sill scope for improvement (customization in particular) but that's another story. <!-- Other than the issue solved, is this relevant to any other issues/existing PRs? --> ## References <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [X] Closes #1846 * [X] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [ ] Tests added/passed * [ ] Requires documentation to be updated * [X] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments - Changed `string` to `ostringstream` for string building. - Changed 'sprintf_s` to c++ stream formatting. - Changed `\r\n` to `<BR>` in produced HTML. - Used already implemented function for UTF16->UTF8 conversion. - Now there is flat and minimalised list of `<span>`s with fg and bg color. Previous structure was.. weird. Each row was child span of previous row and there were empty spans with black color attributes in place of `\r\n` at end of the row. And all of this seemed unintended. - HTML text was unescaped, and it still is, becouse Word doesn't work with HTML entities, like `&lt;`. But it seems to accept the invalid HTML with `>` from prompts. So if there is no text like `<someTextThatNowBecomesATag>`, it should work. Problems/questions: - So what to do with HTML escaping? - Is `try` still needed? - Bg color past last character in row is incorrect (actually it looks correct most of time as it doesn't change. But run e.g. `mc` to see it). Neither I and the function's author seemed to know how to fix this, becouse they (me at least) don't quite feel like HTML. - The width of pasted text is infinite but it should be either terminal's size or copied text's size. And it again looks like HTML thing. - If selection doesn't start at first character, this fact is ignored (the text is pasted as if it was the first character). No good, right? <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> --- <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:05:17 +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#24775