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

Add bold, italic, and underline for copyFormatting #16193

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/buffer/out/TextAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ bool TextAttribute::IsItalic() const noexcept
return WI_IsFlagSet(_attrs, CharacterAttributes::Italics);
}

bool TextAttribute::IsBold() const noexcept
{
return WI_IsFlagSet(_attrs, CharacterAttributes::Bold);
}
Comment on lines +291 to +294
Copy link
Collaborator

Choose a reason for hiding this comment

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

This addition is unnecessary. The "bold" state can already be determined by the IsIntense method. But in terms of what we put in the HTML output, it should probably only be triggering a bold font if the IntenseIsBold mode is also set.


bool TextAttribute::IsBlinking() const noexcept
{
return WI_IsFlagSet(_attrs, CharacterAttributes::Blinking);
Expand Down
1 change: 1 addition & 0 deletions src/buffer/out/TextAttribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class TextAttribute final
bool IsFaint() const noexcept;
bool IsItalic() const noexcept;
bool IsBlinking() const noexcept;
bool IsBold() const noexcept;
bool IsInvisible() const noexcept;
bool IsCrossedOut() const noexcept;
bool IsUnderlined() const noexcept;
Expand Down
10 changes: 10 additions & 0 deletions src/buffer/out/textBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2063,6 +2063,7 @@ std::string TextBuffer::GenHTML(const TextAndColor& rows,
auto hasWrittenAnyText = false;
std::optional<COLORREF> fgColor = std::nullopt;
std::optional<COLORREF> bkColor = std::nullopt;
TextAttribute textProps;
for (size_t row = 0; row < rows.text.size(); row++)
{
size_t startOffset = 0;
Expand Down Expand Up @@ -2137,6 +2138,15 @@ std::string TextBuffer::GenHTML(const TextAndColor& rows,
htmlBuilder << "background-color:";
htmlBuilder << Utils::ColorToHexString(bkColor.value());
htmlBuilder << ";";
htmlBuilder << "text-decoration:";
htmlBuilder << textProps.IsUnderlined();
htmlBuilder << ";";
htmlBuilder << "font-weight:";
htmlBuilder << textProps.IsBold();
htmlBuilder << ";";
htmlBuilder << "font-style:";
htmlBuilder << textProps.IsItalic();
htmlBuilder << ";";
Copy link
Member

Choose a reason for hiding this comment

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

I'm somewhat doubtful that this works correctly, because these 3 CSS properties don't accept true/false as their arguments.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also note that the textProps variable doesn't seem to be filled in with anything, and we'd need to be tracking the changes to these styles, the same way we're tracking changes to the colors, so we're only writing out a new span when necessary.

htmlBuilder << "\">";
}

Expand Down
1 change: 1 addition & 0 deletions src/inc/conattrs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum class CharacterAttributes : uint16_t
Normal = 0x00,
Intense = 0x01,
Italics = 0x02,
Bold = 0x03,
Blinking = 0x04,
Invisible = 0x08,
CrossedOut = 0x10,
Expand Down
Loading