Commit graph

15 commits

Author SHA1 Message Date
Dustin Howett e591d29000 Migrate OSS up to f9b97c488 2021-11-09 13:39:28 -06:00
James Holderness b604117421
Standardize the color table order (#11602)
## Summary of the Pull Request

In the original implementation, we used two different orderings for the color tables. The WT color table used ANSI order, while the conhost color table used a Windows-specific order. This PR standardizes on the ANSI color order everywhere, so the usage of indexed colors is consistent across both parts of the code base, which will hopefully allow more of the code to be shared one day.

## References

This is another small step towards de-duplicating `AdaptDispatch` and `TerminalDispatch` for issue #3849, and is essentially a followup to the SGR dispatch refactoring in PR #6728.

## PR Checklist
* [x] Closes #11461
* [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: #11461

## Detailed Description of the Pull Request / Additional comments

Conhost still needs to deal with legacy attributes using Windows color order, so those values now need to be transposed to ANSI colors order when creating a `TextAttribute` object. This is done with a simple mapping table, which also handles the translation of the default color entries, so it's actually slightly faster than the original code.

And when converting `TextAttribute` values back to legacy console attributes, we were already using a mapping table to handle the narrowing of 256-color values down to 16 colors, so we just needed to adjust that table to account for the translation from ANSI to Windows, and then could make use of the same table for both 256-color and 16-color values.

There are also a few places in conhost that read from or write to the color tables, and those now need to transpose the index values. I've addressed this by creating separate `SetLegacyColorTableEntry` and `GetLegacyColorTableEntry` methods in the `Settings` class which take care of the mapping, so it's now clearer in which cases the code is dealing with legacy values, and which are ANSI values.

These methods are used in the `SetConsoleScreenBufferInfoEx` and `GetConsoleScreenBufferInfoEx` APIs, as well as a few place where color preferences are handled (the registry, shortcut links, and the properties dialog), none of which are particularly sensitive to performance. However, we also use the legacy table when looking up the default colors for rendering (which happens a lot), so I've refactored that code so the default color calculations now only occur once per frame.

The plus side of all of this is that the VT code doesn't need to do the index translation anymore, so we can finally get rid of all the calls to `XTermToWindowsIndex`, and we no longer need a separate color table initialization method for conhost, so I was able to merge a number of color initialization methods into one. We also no longer need to translate from legacy values to ANSI when generating VT sequences for conpty.

The one exception to that is the 16-color VT renderer, which uses the `TextColor::GetLegacyIndex` method to approximate 16-color equivalents for RGB and 256-color values. Since that method returns a legacy index, it still needs to be translated to ANSI before it can be used in a VT sequence. But this should be no worse than it was before.

One more special case is conhost's secret _Color Selection_ feature. That uses `Ctrl`+Number and `Alt`+Number key sequences to highlight parts of the buffer, and the mapping from number to color is based on the Windows color order. So that mapping now needs to be transposed, but that's also not performance sensitive.

The only thing that I haven't bothered to update is the trace logging code in the `Telemetry` class, which logs the first 16 entries in the color table. Those entries are now going to be in a different order, but I didn't think that would be of great concern to anyone.

## Validation Steps Performed

A lot of unit tests needed to be updated to use ANSI color constants when setting indexed colors, where before they might have been expecting values in Windows order. But this replaced a wild mix of different constants, sometimes having to use bit shifting, as well as values mapped with `XTermToWindowsIndex`, so I think the tests are a whole lot clearer now. Only a few cases have been left with literal numbers where that seemed more appropriate.

In addition to getting the unit tests working, I've also manually tested the behaviour of all the console APIs which I thought could be affected by these changes, and confirmed that they produced the same results in the new code as they did in the original implementation.

This includes:
- `WriteConsoleOutput`
- `ReadConsoleOutput`
- `SetConsoleTextAttribute` with `WriteConsoleOutputCharacter`
- `FillConsoleOutputAttribute` and `FillConsoleOutputCharacter` 
- `ScrollConsoleScreenBuffer`
- `GetConsoleScreenBufferInfo`
- `GetConsoleScreenBufferInfoEx`
- `SetConsoleScreenBufferInfoEx`

I've also manually tested changing colors via the console properties menu, the registry, and shortcut links, including setting default colors and popup colors. And I've tested that the "Quirks Mode" is still working as expected in PowerShell.

In terms of performance, I wrote a little test app that filled a 80x9999 buffer with random color combinations using `WriteConsoleOutput`, which I figured was likely to be the most performance sensitive call, and I think it now actually performs slightly better than the original implementation.

I've also tested similar code - just filling the visible window - with SGR VT sequences of various types, and the performance seems about the same as it was before.
2021-11-04 22:13:22 +00:00
Dustin Howett 26f4b0eacb Merged PR 6269653: Slim down conhost's dependency on shcore
An internal change CommandLineToArgVW to an apiset.

Retrieved from https://microsoft.visualstudio.com os.2020 OS official/rs_wdx_dxp_windev a71b943e06c009085d6a2bb886dd50c2d0d2c276

Related work items: MSFT-32178383
2021-07-19 19:51:47 +00:00
Dan Thompson e2005ca5d7 Merged PR 6176782: [Git2Git] Get rid of dead build macros/#defines FE_IME, W32_SB, etc.
Retrieved from https://microsoft.visualstudio.com os.2020 OS official/rs_wdx_dxp_windev 40df712b33a40e76aeeac87f823bbb028d2e3972

Related work items: MSFT-32007459
2021-06-21 10:50:52 -07:00
Dustin Howett 7241fa29c6 Merged PR 5445070: [Git2Git] Update the Windows build for some shell changes
Retrieved from https://microsoft.visualstudio.com os.2020 OS official/rs_onecore_dep_uxp 91dff13f6953441afe9e28bfe3da9d5bff27bb05

Related: MSFT-26196390

Related work items: #26196390
2020-12-16 01:32:35 +00:00
Dustin Howett f49ae2451d Merged PR 4988918: Reflect OS changes for LKG10
Reverts "Merged PR 4670666: Workaround for LKG10 internal linker error"

Related work items: MSFT:25439646, MSFT:26598503
2020-07-30 22:55:57 +00:00
Dustin Howett 878ed57db6 Merged PR 4947060: Migrate OS delayload changes
[Git2Git] Git Train: Merge of building/rs_onecore_dep_uxp/200720-1445 into official/rs_onecore_dep_uxp
Retrieved from https://microsoft.visualstudio.com os.2020 OS official/rs_onecore_dep_uxp 5e1509a00f1acdefe1e6392468ffc9ae44dc89cb

Related work items: MSFT:25731998
2020-07-22 23:29:15 +00:00
Michael Niksa 92812bf316 Merged PR 4645239: [Git2Git] Merged PR 4644345: conhost: disable the DX renderer in inbox builds
[Git2Git] Merged PR 4644345: conhost: disable the DX renderer in inbox builds

We're going to be taking on some changes to the Dx renderer that are at
the very least annoying and at the very most inconsequential to the
inbox console. This commit removes support for the DX renderer from the
inbox console.

SizeBench reports that ConRenderDx contributes 55.1kb to the conhost
image (as its third largest constituent library), so this should net us
a couple pleasant WPG improvements down the line.

Related work items: #26291552 Retrieved from https://microsoft.visualstudio.com os OS official/rs_onecore_dep_uxp 6e36786d447b7975298ba31ccd77c5c649fbfbe6

Related work items: #26291552
2020-05-05 23:03:07 +00:00
Michael Niksa 252c7d36a4 Merged PR 4560408: [Git2Git] LKG9 optimizer workaround
[Git2Git] Git Train: Merge of building/rs_onecore_dep_uxp/200414-1630 into official/rs_onecore_dep_uxp Retrieved from https://microsoft.visualstudio.com os OS official/rs_onecore_dep_uxp 90031afa8114b7d95e3993573fc8449a1524a7fd

Related work items: #25439646
2020-04-21 17:44:56 +00:00
Michael Niksa 51cf02c6f9 Merged PR 4182306: [Git2Git] Merged PR 4182266: conhost: don't use D3DCompiler on inside-windows builds (and delete the shaders)
[Git2Git] Merged PR 4182266: conhost: don't use D3DCompiler on inside-windows builds (and delete the shaders)

Related work items: #24424432, #24424534, #24543695 Retrieved from https://microsoft.visualstudio.com os OS official/rs_onecore_dep_uxp b5d1859452a94e446a3be3f97eb638e13e26496e

Related work items: #24424432, #24424534, #24543695
2020-01-23 00:42:56 +00:00
Michael Niksa abfca60097 Merged PR 4130317: [Git2Git] Merged PR 4127538: [Git2Git] Migrate github changes up to dccb2979
This pull request also includes build break fixes for things that do not build in the OSS repo
and disables the retro terminal effect in conhost.

Retrieved from https://microsoft.visualstudio.com os OS official/rs_onecore_dep_uxp f10445678e59197c1ae2ee29d8f009c9607c4e5d

Related work items: #24387718
2019-12-17 18:17:26 +00:00
Kaiyu Wang ebdcfbd940
Migrate Search module as a shared component for Terminal Search (#3279)
* Make search a shared component for conhost and terminal

* Remove inclusion of deprecated interface file

* Code review changes, remove text buffer modification in Terminal

* remove unreferenced objects to fix build errors

* Fix test failure, guarantee uiaData object is correctly initialized in Search

* minor comment typo fix and format fix

* minor PR comments change

* ColorSeclection directly throw and return

* remove coordAnchor initialization

* minor method signature change
2019-11-14 14:36:41 -08:00
Michael Niksa 86c9e586fe inbox: merge rs_onecore_dep_uxp b4fc3a535 2019-09-26 11:44:54 -07:00
Dustin L. Howett (MSFT) ecfaa76a89
inbox: merge refactoring payload from FI
`official/rs_onecore_dep_acioss 6fa4fbe485365ed72be2f557621fe58d4fc75197`
2019-06-11 17:01:26 -07:00
Dustin Howett d4d59fa339 Initial release of the Windows Terminal source code
This commit introduces all of the Windows Terminal and Console Host source,
under the MIT license.
2019-05-02 15:29:04 -07:00