2019-05-03 00:29:04 +02:00
|
|
|
/*++
|
|
|
|
Copyright (c) Microsoft Corporation
|
|
|
|
Licensed under the MIT license.
|
|
|
|
--*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#define FG_ATTRS (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY)
|
|
|
|
#define BG_ATTRS (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY)
|
2019-06-11 22:27:09 +02:00
|
|
|
#define META_ATTRS (COMMON_LVB_LEADING_BYTE | COMMON_LVB_TRAILING_BYTE | COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_GRID_LVERTICAL | COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_REVERSE_VIDEO | COMMON_LVB_UNDERSCORE)
|
2019-05-03 00:29:04 +02:00
|
|
|
|
Add support for passing through extended text attributes, like… (#2917)
## Summary of the Pull Request
Adds support for Italics, Blinking, Invisible, CrossedOut text, THROUGH CONPTY. This does **NOT** add support for those styles to conhost or the terminal.
We will store these "Extended Text Attributes" in a `TextAttribute`. When we go to render a line, we'll see if the state has changed from our previous state, and if so, we'll appropriately toggle that state with VT. Boldness has been moved from a `bool` to a single bit in these flags.
Technically, now that these are stored in the buffer, we only need to make changes to the renderers to be able to support them. That's not being done as a part of this PR however.
## References
See also #2915 and #2916, which are some follow-up tasks from this fix. I thought them too risky for 20H1.
## PR Checklist
* [x] Closes #2554
* [x] I work here
* [x] Tests added/passed
* [n/a] Requires documentation to be updated
<hr>
* store text with extended attributes too
* Plumb attributes through all the renderers
* parse extended attrs, though we're not renderering them right
* Render these states correctly
* Add a very extensive test
* Cleanup for PR
* a block of PR feedback
* add 512 test cases
* Fix the build
* Fix @carlos-zamora's suggestions
* @miniksa's PR feedback
2019-10-04 22:53:54 +02:00
|
|
|
enum class ExtendedAttributes : BYTE
|
|
|
|
{
|
|
|
|
Normal = 0x00,
|
|
|
|
Bold = 0x01,
|
|
|
|
Italics = 0x02,
|
|
|
|
Blinking = 0x04,
|
|
|
|
Invisible = 0x08,
|
|
|
|
CrossedOut = 0x10,
|
2020-08-03 14:49:25 +02:00
|
|
|
Underlined = 0x20,
|
Add support for the "doubly underlined" graphic rendition attribute (#7223)
This PR adds support for the ANSI _doubly underlined_ graphic rendition
attribute, which is enabled by the `SGR 21` escape sequence.
There was already an `ExtendedAttributes::DoublyUnderlined` flag in the
`TextAttribute` class, but I needed to add `SetDoublyUnderlined` and
`IsDoublyUnderlined` methods to access that flag, and update the
`SetGraphicsRendition` methods of the two dispatchers to set the
attribute on receipt of the `SGR 21` sequence. I also had to update the
existing `SGR 24` handler to reset _DoublyUnderlined_ in addition to
_Underlined_, since they share the same reset sequence.
For the rendering, I've added a new grid line type, which essentially
just draws an additional line with the same thickness as the regular
underline, but slightly below it - I found a gap of around 0.05 "em"
between the lines looked best. If there isn't enough space in the cell
for that gap, the second line will be clamped to overlap the first, so
you then just get a thicker line. If there isn't even enough space below
for a thicker line, we move the offset _above_ the first line, but just
enough to make it thicker.
The only other complication was the update of the `Xterm256Engine` in
the VT renderer. As mentioned above, the two underline attributes share
the same reset sequence, so to forward that state over conpty we require
a slightly more complicated process than with most other attributes
(similar to _Bold_ and _Faint_). We first check whether either underline
attribute needs to be turned off to send the reset sequence, and then
check individually if each of them needs to be turned back on again.
## Validation Steps Performed
For testing, I've extended the existing attribute tests in
`AdapterTest`, `VTRendererTest`, and `ScreenBufferTests`, to make sure
we're covering both the _Underlined_ and _DoublyUnderlined_ attributes.
I've also manually tested the `SGR 21` sequence in conhost and Windows
Terminal, with a variety of fonts and font sizes, to make sure the
rendering was reasonably distinguishable from a single underline.
Closes #2916
2020-08-10 19:06:16 +02:00
|
|
|
DoublyUnderlined = 0x40,
|
Add support for the "faint" graphic rendition attribute (#6873)
## Summary of the Pull Request
This PR adds support for the `SGR 2` escape sequence, which enables the
ANSI _faint_ graphic rendition attribute. When a character is output
with this attribute set, it uses a dimmer version of the active
foreground color.
## PR Checklist
* [x] Closes #6703
* [x] CLA signed.
* [x] Tests added/passed
* [ ] Documentation updated.
* [ ] Schema updated.
* [x] I've discussed this with core contributors already. Issue number where discussion took place: #6703
## Detailed Description of the Pull Request / Additional comments
There was already an `ExtendedAttributes::Faint` flag in the
`TextAttribute` class, but I needed to add `SetFaint` and `IsFaint`
methods to access that flag, and update the `SetGraphicsRendition`
methods of the two dispatchers to set the attribute on receipt of the
`SGR 2` sequence. I also had to update the existing `SGR 22` handler to
reset _Faint_ in addition to _Bold_, since they share the same reset
sequence. For that reason, I thought it a good idea to change the name
of the `SGR 22` enum to `NotBoldOrFaint`.
For the purpose of rendering, I've updated the
`TextAttribute::CalculateRgbColors` method to return a dimmer version of
the foreground color when the _Faint_ attribute is set. This is simply
achieved by dividing each color component by two, which produces a
reasonable effect without being too complicated. Note that the _Faint_
effect is applied before _Reverse Video_, so if the output it reversed,
it's the background that will be faint.
The only other complication was the update of the `Xterm256Engine` in
the VT renderer. As mentioned above, _Bold_ and _Faint_ share the same
reset sequence, so to forward that state over conpty we have to go
through a slightly more complicated process than with other attributes.
We first check whether either attribute needs to be turned off to send
the reset sequence, and then check if the individual attributes need to
be turned on again.
## Validation
I've extended the existing SGR unit tests to cover the new attribute in
the `AdapterTest`, the `ScreenBufferTests`, and the `VtRendererTest`,
and added a test to confirm the color calculations when _Faint_ is set
in the `TextAttributeTests`.
I've also done a bunch of manual testing with all the different VT color
types and confirmed that our output is comparable to most other
terminals.
2020-07-13 19:44:09 +02:00
|
|
|
Faint = 0x80,
|
Add support for passing through extended text attributes, like… (#2917)
## Summary of the Pull Request
Adds support for Italics, Blinking, Invisible, CrossedOut text, THROUGH CONPTY. This does **NOT** add support for those styles to conhost or the terminal.
We will store these "Extended Text Attributes" in a `TextAttribute`. When we go to render a line, we'll see if the state has changed from our previous state, and if so, we'll appropriately toggle that state with VT. Boldness has been moved from a `bool` to a single bit in these flags.
Technically, now that these are stored in the buffer, we only need to make changes to the renderers to be able to support them. That's not being done as a part of this PR however.
## References
See also #2915 and #2916, which are some follow-up tasks from this fix. I thought them too risky for 20H1.
## PR Checklist
* [x] Closes #2554
* [x] I work here
* [x] Tests added/passed
* [n/a] Requires documentation to be updated
<hr>
* store text with extended attributes too
* Plumb attributes through all the renderers
* parse extended attrs, though we're not renderering them right
* Render these states correctly
* Add a very extensive test
* Cleanup for PR
* a block of PR feedback
* add 512 test cases
* Fix the build
* Fix @carlos-zamora's suggestions
* @miniksa's PR feedback
2019-10-04 22:53:54 +02:00
|
|
|
};
|
|
|
|
DEFINE_ENUM_FLAG_OPERATORS(ExtendedAttributes);
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
WORD XtermToWindowsIndex(const size_t index) noexcept;
|
|
|
|
WORD Xterm256ToWindowsIndex(const size_t index) noexcept;
|
|
|
|
WORD XtermToLegacy(const size_t xtermForeground, const size_t xtermBackground);
|
|
|
|
|
2021-03-29 18:03:16 +02:00
|
|
|
constexpr WORD WINDOWS_RED_ATTR = FOREGROUND_RED;
|
|
|
|
constexpr WORD WINDOWS_GREEN_ATTR = FOREGROUND_GREEN;
|
|
|
|
constexpr WORD WINDOWS_BLUE_ATTR = FOREGROUND_BLUE;
|
|
|
|
constexpr WORD WINDOWS_BRIGHT_ATTR = FOREGROUND_INTENSITY;
|
|
|
|
|
|
|
|
constexpr WORD XTERM_RED_ATTR = 0x01;
|
|
|
|
constexpr WORD XTERM_GREEN_ATTR = 0x02;
|
|
|
|
constexpr WORD XTERM_BLUE_ATTR = 0x04;
|
|
|
|
constexpr WORD XTERM_BRIGHT_ATTR = 0x08;
|
2019-05-03 00:29:04 +02:00
|
|
|
|
|
|
|
enum class CursorType : unsigned int
|
|
|
|
{
|
|
|
|
Legacy = 0x0, // uses the cursor's height value to range from underscore-like to full box
|
|
|
|
VerticalBar = 0x1, // A single vertical line, '|'
|
|
|
|
Underscore = 0x2, // a single horizontal underscore, smaller that the min height legacy cursor.
|
|
|
|
EmptyBox = 0x3, // Just the outline of a full box
|
2021-01-20 20:36:07 +01:00
|
|
|
FullBox = 0x4, // a full box, similar to legacy with height=100%
|
|
|
|
DoubleUnderscore = 0x5 // a double horizontal underscore
|
2019-05-03 00:29:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Valid COLORREFs are of the pattern 0x00bbggrr. -1 works as an invalid color,
|
|
|
|
// as the highest byte of a valid color is always 0.
|
|
|
|
constexpr COLORREF INVALID_COLOR = 0xffffffff;
|
|
|
|
|
|
|
|
constexpr WORD COLOR_TABLE_SIZE = 16;
|
|
|
|
constexpr WORD XTERM_COLOR_TABLE_SIZE = 256;
|