Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor TextBuffer::GenHTML #2038

Merged

Conversation

mcpiroman
Copy link
Contributor

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

  • Closes Modernize TextBuffer's GenHTML() function #1846
  • CLA signed. If not, go over here and sign the CLA
  • Tests added/passed
  • Requires documentation to be updated
  • 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

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?

Copy link
Member

@carlos-zamora carlos-zamora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks much nicer and easier to comprehend! Thank you so much! Left a few comments throughout.

src/buffer/out/textBuffer.cpp Outdated Show resolved Hide resolved
src/buffer/out/textBuffer.cpp Show resolved Hide resolved
src/buffer/out/textBuffer.cpp Show resolved Hide resolved
src/buffer/out/textBuffer.cpp Show resolved Hide resolved
src/buffer/out/textBuffer.cpp Outdated Show resolved Hide resolved
src/buffer/out/textBuffer.cpp Show resolved Hide resolved
Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to echo Carlos's request to file some issues for the todo's left in the code, but otherwise this looks substantially better than it was before. Good work!

src/buffer/out/textBuffer.cpp Outdated Show resolved Hide resolved
src/buffer/out/textBuffer.cpp Outdated Show resolved Hide resolved
src/buffer/out/textBuffer.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@DHowett-MSFT DHowett-MSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry! I meant to mark "Request Changes" for the CSS issue. Otherwise it looks good!

@ghost ghost added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jul 26, 2019
@ghost ghost removed the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Jul 26, 2019
src/buffer/out/textBuffer.cpp Outdated Show resolved Hide resolved
@miniksa
Copy link
Member

miniksa commented Aug 6, 2019

@DHowett-MSFT, is there anything else you want to see here? I think the CSS thing was resolved and this is otherwise good to merge.

@miniksa miniksa added the Needs-Attention The core contributors need to come back around and look at this ASAP. label Aug 6, 2019
Copy link
Contributor

@DHowett-MSFT DHowett-MSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@DHowett-MSFT DHowett-MSFT merged commit fa89e53 into microsoft:dev/cazamor/html-copy Aug 6, 2019
ghost pushed a commit that referenced this pull request Aug 19, 2019
* Move Clipboard::GenHTML to TextBuffer (add params)
Refactor RetrieveSelectedTextFromBuffer
Modify CopyToClipboardEventArgs to include HTML data

* minor code format fix

* PR Changes
NOTE: refactoring text buffer code is a separate task. New issue to be created.

* Refactor TextBuffer::GenHTML (#2038)

Fixes #1846.

* nit change

* x86 build fix

* nit changes
@ghost
Copy link

ghost commented Aug 27, 2019

🎉Windows Terminal Preview v0.4.2382.0 has been released which incorporates this pull request.:tada:

Handy links:

@mcpiroman mcpiroman deleted the improve-html-copy branch September 16, 2019 15:20
@mcpiroman mcpiroman mentioned this pull request Sep 16, 2019
5 tasks
ghost pushed a commit that referenced this pull request Jan 14, 2020
## Summary of the Pull Request

When `GenHTML` or `GenRTF` encountered an empty line, they assumed that `CR` is the last character of the row and wrote it, even though in general `CR` and `LF` just break the line and instead of them either `<BR>` in HTML or `\line` in RTF is written. Don't know how I missed that in #2038.

Another question is whether the `TextAndColor` structure which these methods receive and which is generated by `TextBuffer::GetTextForClipboard` should really contain `\r\n` at the end of each row. I think it'd be cleaner if it didn't esp. that afaik these last 2 characters don't have associated valid color information.

## References

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
* [X] Closes #4187
* [X] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA
* [ ] Tests added/passed - there aren't any related tests, right?
* [ ] Requires documentation to be updated
* [ ] 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: #4147 

<!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
Copied various terminal states and verified the generated HTML.
DHowett-MSFT pushed a commit that referenced this pull request Jan 24, 2020
## Summary of the Pull Request

When `GenHTML` or `GenRTF` encountered an empty line, they assumed that `CR` is the last character of the row and wrote it, even though in general `CR` and `LF` just break the line and instead of them either `<BR>` in HTML or `\line` in RTF is written. Don't know how I missed that in #2038.

Another question is whether the `TextAndColor` structure which these methods receive and which is generated by `TextBuffer::GetTextForClipboard` should really contain `\r\n` at the end of each row. I think it'd be cleaner if it didn't esp. that afaik these last 2 characters don't have associated valid color information.

## References

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
* [X] Closes #4187
* [X] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA
* [ ] Tests added/passed - there aren't any related tests, right?
* [ ] Requires documentation to be updated
* [ ] 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: #4147

<!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
Copied various terminal states and verified the generated HTML.

(cherry picked from commit 1ca2912)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Attention The core contributors need to come back around and look at this ASAP.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants