Commit graph

1209 commits

Author SHA1 Message Date
Dustin L. Howett (MSFT) 86685079ec
build: move oss required to build conhost out of dep/ (#5451)
This change is necessary as the dep/ folder is not synced into the
Windows source tree.

I've also added a build rule producing a lib for {fmt}.

This will be required for our next OS ingestion.
2020-04-21 14:43:09 -07:00
Josh Soref bc6ea11233
ci: spelling: update to 0.0.15a; update whitelist (#5413)
* Cleaning up the whitelist a bit.
  * The magic to exclude repeated characters worked 👍 
  * Every successful run on master now logs its suggested cleanup, e.g. for 5740e197c2 has https://github.com/microsoft/terminal/runs/596271627#step:4:37 
* ⚠️ This check-spelling 0.0.15a+ tolerates Windows line endings in the `whitelist.txt` file (another project I touched had some `.gitconfig` magic which required supporting them).
  This means that if someone edits the file w/ something that likes Windows line endings, the file will successfully convert (instead of it being ignored and check-spelling complaining about everything). Most likely anyone else who then edits the file will use something that will maintain the line endings.
2020-04-21 14:07:04 -07:00
Mike Griese 6995d0b2dc
doc: add a note about running wt in the current instance (#5448) 2020-04-21 13:45:18 -07:00
Carlos Zamora 8a976c0d23
Change Windows Powershell default scheme to Campbell (#5432)
The "Campbell Powershell" color scheme does not have a high enough color contrast
ratio. Campbell does, so we're changing it there.

Closes (only upon validation) #5393.
2020-04-21 10:19:54 -07:00
Carlos Zamora e3e57081a2
UIA: Prevent crash from invalid UTR endpoint comparison (#5399)
## Summary of the Pull Request
This is a quick-and-easy solution to #5309. If the ITextRangeProvider API allows us to take in two UiaTextRanges, we need to verify that they are both valid.

With this PR, we make sure they both fit in the current TextBuffer. If not, we return `E_FAIL`. Though this doesn't prove that both UiaTextRanges are from the same TextBuffer, at the very least we don't crash and in cases where we can't make a valid comparison, we return an HRESULT failure.

## References
#5406 - This should be the proper solution to this problem. Each UiaTextRange needs to be aware of which TextBuffer it came from.

## PR Checklist
* [X] Closes #5309

## Validation Steps Performed
1. generate enough output to cause the terminal to scroll
2. execute `nano` to make us go into the alternate buffer
This previously crashed, now NVDA seems to detect that there was an error and keeps moving along.
2020-04-21 16:45:17 +00:00
Carlos Zamora e271599bf4
Add copyFormatting setting to all settings json files (#5404)
## Summary of the Pull Request
Added `copyFormatting` to defaults json files and userDefaults.

## PR Checklist
* [X] Closes #5403
2020-04-20 23:49:12 +00:00
Dustin L. Howett (MSFT) 152b399e90
Don't duplicate spaces from potentially-wrapped EOL-deferred lines (#5398)
The logic here, regarding deleting the spaces and just instantly adding
them bad, is incredibly suspect. Given that we're close to 0.11, I don't
think I can change it.

I've added a TODO with an issue number to figure out the right logic
here.

Fixes #5386.

## PR Checklist
* [x] Closes #5386
* [x] CLA signed
* [x] Tests added/passed
* [ ] Requires documentation to be updated
* [x] I'm horrified.

## Validation Steps Performed
Tests, manual validation of the scenario in 5386 and a repro program.
2020-04-20 21:45:44 +00:00
Mike Griese 56259ea005
Add a git submodules sanity check step to the build (#5424)
This commit adds a specific error message to the build that tells people
to restore git submodules if they forgot to read the README.

#5416 was the straw that broke the camel's back.
2020-04-20 11:11:36 -07:00
Dustin L. Howett (MSFT) 5740e197c2
wpf: only dismiss selection for real chars, not modifiers (#5388)
Selection would act up when you were using shift to ignore VT mouse
mode: we would get hundreds of WM_KEYDOWN for VK_SHIFT and dismiss the
selection every time.

I took the opportunity to move the actual responsibility for key event
dispatch into HwndTerminal. In the future, I'd like to make more of the
TerminalXxx calls just call impl methods on HwndTerminal.
2020-04-17 11:28:56 -07:00
Oisin Grehan 38e7cb0742
Add WT_PROFILE_ID to the environment of the spawned process (#4852)
This commit adds a `WT_PROFILE_ID` environment variable, which contains
the guid of the active profile.

It also teaches ConptyConnection to take an environment map on creation.

We had to do a little manual jiggery with the WSLENV environment
variable as passed by the creator.

* [x] CLA signed
* [ ] Tests added/passed
* [ ] Requires documentation to be updated
* [x] I've discussed this with core contributors already.

Ran terminal, validated vars and translated paths under windows and WSL. 

References #4566 (this PR originally introduced WT_SETTINGS/DEFAULTS)
Closes #3589
2020-04-17 17:15:20 +00:00
Dustin L. Howett (MSFT) bceeb4523e
Fix a deadlock and a bounding rects issue in UIA (#5385)
The scroll locking rework that landed with the DxRenderer's partial
invalidation change introduced a deadlock. UIA locks the buffer for
reading before asking it to scroll (which now requires a write lock.)

Scrolling is probably _okay_ to have a little bit of torn state that
might arise from us unlocking the read lock early before triggering the
write lock down the line.

While investigating this, I also noticed that our bounding rects stopped
being viewport-relative (and were instead buffer-relative.) That
regressed with the switch to `GetTextRects` in #4991  

## PR Checklist
* [ ] Closes (issues noticed in investigating the DPI changes)
* [x] CLA signed.
* [ ] Tests added/passed
* [ ] Requires documentation to be updated
* [x] Core contributor badge

## Validation Steps Performed
Manual pass with inspect.exe
2020-04-17 17:09:58 +00:00
Carlos Zamora f1fe4c6ccd
Add SS3 cursor key encoding to ConPty (#5383)
## Summary of the Pull Request
Adds SS3 cursor encoding for cursor keys and home/end button. Reverts a portion of #4913 that checks for VT Input Mode.

## PR Checklist
* [X] Closes #4873

## Validation Steps Performed
1. Open pwsh
2. run `wsl`
3. execute `printf "\e[?1h"`
4. verify keys work
5. exit back to pwsh
6. verify keys work still (didn't previously)

Also verified that those keys work in vim when connected to my Raspberry Pi over SSH.
2020-04-17 16:14:38 +00:00
Dustin L. Howett (MSFT) f04b7aae87
wpf: add support for VT mouse mode (#5375)
## Summary of the Pull Request

This pull request ports the VT mouse code from TermControl to WpfTerminalControl. Our WPF control is a lot closer to Win32 than to Xaml, so our mouse event handler looks _nothing_ like the one that we got from Xaml. We can pass events through almost directly, because the window message handling in the mouse input code actually came from _conhost_. It's awesome.

Neither TermControl nor conhost pass hover events through when the control isn't focused, so I wired up focus events to make sure we acted the same.

Just like Terminal and conhost, mouse events are suppressed when <kbd>Shift</kbd> is held.

## Validation Steps Performed
Tested with MC, and tested by manually engaging SGR events in an Echo terminal.

![image](https://user-images.githubusercontent.com/14316954/79417901-2f976a00-7f68-11ea-97e9-c053cbed3878.png)
2020-04-17 02:05:47 +00:00
Dustin L. Howett (MSFT) a6b2e7f612
wpf: port selection changes from TermControl, add multi-click selection (#5374)
## Summary of the Pull Request

This pull request ports #5096 to WpfTerminalControl, bringing it in line with the selection mechanics in Terminal. It also introduces double- and triple-click selection and makes sure we clear the selection when we resize.

Please read #5096 for more details.

## Detailed Description of the Pull Request / Additional comments

This code is, largely, copy-and-pasted from TermControl with some updates to use `std::chrono` and `til::point`. I love `til::point`. A lot.

## Validation Steps Performed
Lots of manual selection.
2020-04-17 01:10:29 +00:00
Dustin L. Howett (MSFT) 7f886620b3
wpf: fix two crashes and some fallout from the new key event handler (#5373)
## Summary of the Pull Request

This pull request fixes a crash on scrolling down (overflow exception cramming the signed short upper WORD of the wParam into an actual signed short on x64) and a crash on key input caused by improper use of `Marshal.ReadByte` on an integer (instead of a memory address).

## Detailed Description of the Pull Request / Additional comments

## Validation Steps Performed
Manually did those things on x64.
2020-04-17 01:10:14 +00:00
Dustin L. Howett (MSFT) c186c7d683
Rework error handling and state flow in the Azure connection (#5356)
This commit fixes a number of problems and code quality/health issues
with the AzureConnection.

This is a general tidying-up of the azure connection. It improves error
logging (like: it actually emits error logs...) and retry logic and the
state machine and it audits the exit points of the state machine for
exceptions and removes the HRESULT returns (so they either succeed and
transition to a new state or throw an exception or are going down
anyway).

There's also a change in here that changes how we display tenants. It
adds the "default domain" to the name, so that instead of seeing this:

Conhost (aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa)
Default Directory (bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb)

you see this

Conhost (conhost.onmicrosoft.com)
Default Directory (dustinhowett.onmicrosoft.com)

Changes:

* rework tenant/tenant storage and fix display names

  Switch to the 2020 tenant API.

  Instead of passing around four loose variables, create a Tenant class
  and use that for packing/unpacking into/out of json (and the windows
  credential store, where we "cleverly" used json for the tenant info
  there too).
  
  When displaying a tenant, use its display name if there is one, the
  unknown resource string if there isn't, and the default domain if
  there is one and the ID if there isn't.
  
  Fixes #5325.

* use {fmt} for formatting request bodies
* remove dead strings
* rework/rename Request/HeaderHelper to
  Send(Authenticated)ReqReturningJson
* rewrite polling to use std::chrono
* remove HR returns from state machine
* rename state handlers from _XHelper to _RunXState
* cleanup namespaces, prefix user input with >, remove namespaces
* Rework error handling
  - _RequestHelper no longer eats exceptions.
  - Delete the "no internet" error message.
  - Wrap exceptions coming out of Azure API in a well-known type.
  - Catch by type.
  - Extract error codes for known failures (keep polling, invalid
    grant).
  - When we get an Invalid Grant, dispose of the cached refresh token
    and force the user to log in again.
  - Catch all printable exceptions and print them.
  - Remove the NoConnect state completely -- just bail out when an
    exception hits the toplevel of the output thread.
  - Move 3x logic into _RefreshTokens and pop exceptions out of it.
  - Begin abstracting into AzureClient

Fixes #5325 (by addressing its chief complaint).
Fixes #4803 (by triggering auth flow again if the token expires).
Improves diagnosability for #4575.
2020-04-16 17:32:52 -07:00
Leon Liang fe3f528827
Show a double width cursor for double width characters (#5319)
# Summary of the Pull Request
This PR will allow the cursor to be double width when on top of a double width character. This required changing `IsCursorDoubleWidth` to check whether the glyph the cursor's on top of is double width. This code is exactly the same as the original PR that addressed this issue in #2932. That one got reverted at some point due to the crashes related to it, but due to a combination of Terminal having come further since that PR and other changes to address use-after-frees, some of the crashes may/may not be relevant now. The ones that seemed to be relevant/repro-able, I attempt to address in this PR.

The `IsCursorDoubleWidth` check would fail during the `TextBuffer::Reflow` call inside of `Terminal::UserResize` occasionally, particularly when `newCursor.EndDeferDrawing()` is called. This is because when we tell the newCursor to `EndDefer`, the renderer will attempt to redraw the cursor. As part of this redraw, it'll ask if `IsCursorDoubleWidth`, and if the renderer managed to ask this before `UserResize` swapped out the old buffer with the new one from `Reflow`, the renderer will be asking the old buffer if its out-of-bounds cursor is double width. This was pretty easily repro'd using `cmatrix -u0` and resizing the window like a madman.

As a solution, I've moved the Start/End DeferDrawing calls out of `Reflow` and into `UserResize`. This way, I can "clamp" the portion of the code where the newBuffer is getting created and reflowed and swapped into the Terminal buffer, and only allow the renderer to draw once the swap is done. This also means that ConHost's `ResizeWithReflow` needed to change slightly.

In addition, I've added a WriteLock to `SetCursorOn`. It was mentioned as a fix for a crash in #2965 (although I can't repro), and I also figured it would be good to try to emulate where ConHost locks with regards to Cursor operations, and this seemed to be one that we were missing.

## PR Checklist
* [x] Closes #2713
* [x] CLA signed
* [x] Tests added/passed

## Validation Steps Performed
Manual validation that the cursor is indeed chonky, added a test case to check that we are correctly saying that the cursor is double width (not too sure if I put it in the right place). Also open to other test case ideas and thoughts on what else I should be careful for since I am quite nervous about what other crashes might occur.
2020-04-15 19:23:06 +00:00
Mike Griese dc43524eb2
Emit lines wrapped due to spaces at the end correctly (#5294)
## Summary of the Pull Request

When WSL vim prints the initial empty buffer (the one that's just a bunch of '\~'s), it prints this by doing the following:
* Print '\~' followed by enough spaces to clear the line
* Use CUP (`^[[H`) to move the cursor to the start of the next line
* repeat until the buffer is full

When we'd get the line of "\~     "... in conhost, we'd mark that line as wrapped. 

Logically, it doesn't really make any sense that when we follow that up by moving the cursor, the line is wrapped. However, this is just how conhost is right now. 
This wasn't ever a problem in just conhost before, because we really didn't care if lines in the alt buffer were "wrapped" or not. Plus, when vim would get resized, it would just reprint it's own buffer anyways. Nor was this a problem in conpty before this year (2020). We've only just recently added logic to conpty to try and preserve wrapped lines. 

Initially, I tried fixing this by breaking the line manually when the cursor was moved. This seemed to work great, except for the win32 vim.exe. Vim.exe doesn't emit a newline or a CUP to get to the next line. It just _goes for it_ and keeps printing. So there's _no way_ for us to know the line broke, because they're essentially just printing one long line, assuming we'll automatically move the cursor.

So instead, I'm making sure to emit the proper number of spaces at the end of a line when the line is wrapped. We won't do any funny business in that scenario and try to optimize for them, we'll _just print the spaces_.

## References

* #5181 - This change regressed this
* #4415 - Actually implemented wrapped lines in conpty

## PR Checklist
* [x] Closes #5291
* [x] I work here
* [x] Tests added/passed
* [n/a] Requires documentation to be updated

## Validation Steps Performed
* Wrote a unittest first and foremost
* Checked vtpipeterm to make sure vim still works
* checked Terminal to make sure vim still works
2020-04-15 15:52:11 +00:00
Dustin L. Howett (MSFT) 37e62dabd5
Fix localizability issues in Windows Terminal (#5339)
Loc issues are given to us through the internal bug tracker.

* Lock some strings, or parts of strings, that should not be localized.
* Switch to positional format parameters
* Remove the forced newlines in the warning resources; insert them at
  runtime

Fixes MSFT:25936156.
2020-04-14 20:48:46 +00:00
James Holderness 348f46866a
Update the virtual bottom location if the cursor moves below it (#5317)
If an application writes to the screen while not in VT mode, and the
user has scrolled forward in the screen buffer, the _virtual bottom_
location is not updated to take that new content into account. As a
result, the viewport can later jump back to the previous _virtual
bottom_, making the content disappear off screen. This PR attempts to
fix that issue by updating the _virtual bottom_ location whenever the
cursor moves below that point.

## PR Checklist
* [x] CLA signed. 
* [x] Tests added/passed

## Detailed Description of the Pull Request / Additional comments

This simply adds a condition in the
`SCREEN_INFORMATION::SetCursorPosition` to check if the new _Y_
coordinate is below the current _virtual bottom_, and if so, updates the
_virtual bottom_ to that new value.

I considered trying to make it only update when something is actually
written to the screen, but this seemed like a cleaner solution, and is
less likely to miss out on a needed update.

## Validation Steps Performed

I've manually tested the case described in issue #5302, and confirmed
that it now works as expected. I've also added a unit test that checks
the virtual bottom is updated correctly under similar conditions.

Closes #5302
2020-04-14 13:20:30 -07:00
Carlos Zamora 9dd5f6e8b9
Remove singleLine copy from Shift+Click, CopyOnSelect (#5346)
This fixes an issue where a shift+click selection with `copyOnSelect`
enabled would result in copying the content as a single line.

## Detailed Description of the Pull Request / Additional comments
I've been thinking a lot about this issue and how it relates to the
copy/paste discussions we've been having over the past few weeks.
Considering that the majority of users want regular copy, it makes sense
to default to that in this case too.

If a user wants to perform a special form of copy, it makes sense that
they should use their custom keybinding to accomplish that. This kind of
behavior aligns with that kind of philosophy.

## Validation Steps Performed

The following scenarios were tested with `copyOnSelect` enabled.
| scenario                                | behavior                      |
|-----------------------------------------|-------------------------------|
| Perform a shift+click selection         | content copied w/ newlines    |
| right-click                             | clipboard paste               |
| copy keybinding (`singleLine` disabled) | content copied w/ newlines    |
| copy keybinding (`singleLine` enabled)  | content copied as single line |

Closes #4737
2020-04-14 13:19:22 -07:00
Mike Griese d46eead61b
specs: draft spec for adding profiles to the Windows jumplist (#5350)
_This is literally just #1357, but moved to the `drafts/` folder_. Since
@dsafa doesn't have the time to finish this on their own, we'll take it
from here for 2.0 ☺️

## Summary of the Pull Request
Adds a spec describing jumplist integration and adding profiles to the jumplist. Includes details about previous investigations into adding the jumplist.

## PR Checklist
* [x] Specs #576 
* [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA
* [n/a] Tests added/passed
* [x] 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: #576 

## Detailed Description of the Pull Request / Additional comments
Details in the spec.

## Validation Steps Performed
N/A

Co-authored-by: Brandon Chong <brndnchong@gmail.com>
2020-04-14 13:17:15 -07:00
Dustin L. Howett (MSFT) e61968ca87
Add support for renderer backoff, don't FAIL_FAST on 3x failures, add UI (#5353)
## Summary of the Pull Request
Renderer: Add support for backoff and auto-disable on failed retry

This commit introduces a backoff (150ms * number of tries) to the
renderer's retry logic (introduced in #2830). It also changes the
FAIL_FAST to a less globally-harmful render thread disable, so that we
stop blowing up any application hosting a terminal when the graphics
driver goes away.

In addition, it adds a callback that a Renderer consumer can use to
determine when the renderer _has_ failed, and a public method to kick it
back into life.

Fixes #5340.

This PR also wires up TermControl so that it shows some UI when the renderer tastes clay.

![image](https://user-images.githubusercontent.com/14316954/79266118-f073f680-7e4b-11ea-8b96-5588a13aff3b.png)

![image](https://user-images.githubusercontent.com/14316954/79266125-f36ee700-7e4b-11ea-9314-4280e9149461.png)

## PR Checklist
* [x] Closes #5340
* [x] cla
* [ ] Tests added/passed
* [ ] Requires documentation to be updated
* [x] I've discussed this with core contributors already.

## Validation Steps Performed

I tested this by dropping the number of retries to 1 and forcing a TDR while doing `wsl cmatrix -u0`. It picked up exactly where it left off.

As a bonus, you can actually still type into the terminal when it's graphically suspended (and `exit` still works.). The block is _entirely graphical_.
2020-04-14 20:11:47 +00:00
Dustin Howett 22e2774c21 Add spelling issues from {fmt} to the allowlist/dictionary 2020-04-14 13:05:38 -07:00
Dustin L. Howett 114e462669
Import fmtlib/fmt@6.2.0, a C++20-style format library (#5336)
We received a request from our localization team to switch from
printf-style format strings (%s, %u) to format strings with positional
argument support. I've been hoping for a long time to take a dependency
on C++20's std::format, but we're just not somewhere we can do that.
Enter fmt. fmt is _exactly_ the library we need.

Minor comparison:

std::wstring_view world = /* ... */;
auto str{ wil::str_printf<std::wstring>(L"hello %.*s",
	   gsl::narrow_cast<size_t>(world.size()),
	   world.data()) };

---

auto str{ fmt::format(L"hello {0}", world) };

If you really want to use the print specifiers:

auto str{ fmt::printf(L"hello %s", world) };

It's got optional compile-time checking for format strings and is
MIT-licensed. Eventually, we should be able to replace fmt:: with std::
and end up pretty much where we left off.
What more could you ask for?
2020-04-14 13:04:23 -07:00
Josh Soref 05119e2faf
spelling: COLOREREF -> COLORREF (#5352)
Spell check passed on my fork :-)

I saw this when I was looking at someone else's PR and realized that it's just a typo.
2020-04-14 12:30:51 -07:00
Rafael Kitover ea61aa3bfc
Add the Tango color schemes for Terminal and ColorTool (#5305)
The Tango color scheme is part of the Tango Desktop Project, which was
released to the public domain in 2009.

More information is available at http://tango-project.org/.

This commit adds the "Tango Dark" and "Tango Light" color scheme
presets.

Closes #5281

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
2020-04-14 10:47:02 -07:00
Mike Griese 3927c68a00
doc: Fix the typos I introduced in #2193 (#5343) 2020-04-13 13:50:02 -07:00
Michael Niksa 79684bf821
Render row-by-row instead of invalidating entire screen (#5185)
## Summary of the Pull Request
Adjusts DirectX renderer to use `til::bitmap` to track invalidation
regions. Uses special modification to invalidate a row-at-a-time to
ensure ligatures and NxM glyphs continue to work.

## References
Likely helps #1064

## PR Checklist
* [x] Closes #778
* [x] I work here.
* [x] Manual testing performed. See Performance traces in #778.
* [x] Automated tests for `til` changes.
* [x] Am core contributor. And discussed with @DHowett-MSFT.

## Detailed Description of the Pull Request / Additional comments
- Applies `til::bitmap` as the new invalidation scheme inside the
  DirectX renderer and updates all entrypoints for collecting
  invalidation data to coalesce into this structure.
- Semi-permanently routes all invalidations through a helper method
  `_InvalidateRectangle` that will expand any invalidation to cover the
  entire line. This ensures that ligatures and NxM glyphs will continue
  to render appropriately while still allowing us to dramatically reduce
  the number of lines drawn overall. In the future, we may come up with
  a tighter solution than line-by-line invalidation and can modify this
  helper method appropriately at that later date to further scope the
  invalid region.
- Ensures that the `experimental.retroTerminalEffects` feature continues
  to invalidate the entire display on start of frame as the shader is
  applied at the end of the frame composition and will stack on itself
  in an amusing fashion when we only redraw part of the display.
- Moves many member variables inside the DirectX renderer into the new
  `til::size`, `til::point`, and `til::rectangle` methods to facilitate
  easier management and mathematical operations. Consequently adds
  `try/catch` blocks around many of the already-existing `noexcept`
  methods to deal with mathematical or casting failures now detected by
  using the support classes.
- Corrects `TerminalCore` redraw triggers to appropriately communicate
  scrolling circumstances to the renderer so it can optimize the draw
  regions appropriately.
- Fixes an issue in the base `Renderer` that was causing overlapping
  scroll regions due to behavior of `Viewport::TrimToViewport` modifying
  the local. This fix is "good enough" for now and should go away when
  `Viewport` is fully migrated to `til::rectangle`.
- Adds multiplication and division operators to `til::rectangle` and
  supporting tests. These operates will help scale back and forth
  between a cell-based rectangle and a pixel-based rectangle. They take
  special care to ensure that a pixel rectangle being divided downward
  back to cells will expand (with the ceiling division methods) to cover
  a full cell when even one pixel inside the cell is touched (as is how
  a redraw would have to occur).
- Blocks off trace logging of invalid regions if no one is listening to
  optimize performance.
- Restores full usage of `IDXGISwapChain1::Present1` to accurately and
  fully communicate dirty and scroll regions to the underlying DirectX
  framework. This additional information allows the framework to
  optimize drawing between frames by eliminating data transfer of
  regions that aren't modified and shuffling frames in place. See
  [Remarks](https://docs.microsoft.com/en-us/windows/win32/api/dxgi1_2/nf-dxgi1_2-idxgiswapchain1-present1#remarks)
  for more details.
- Updates `til::bitmap` set methods to use more optimized versions of
  the setters on the `dynamic_bitset<>` that can bulk fill bits as the
  existing algorithm was noticeably slow after applying the
  "expand-to-row" helper to the DirectX renderer invalidation.
- All `til` import hierarchy is now handled in the parent `til.h` file
  and not in the child files to prevent circular imports from happening.
  We don't expect the import of any individual library file, only the
  base one. So this should be OK for now.

## Validation Steps Performed
- Ran `cmatrix`, `cmatrix -u0`, and `cacafire` after changes were made.
- Made a bunch of ligatures with `Cascadia Code` in the Terminal
  before/after the changes and confirmed they still ligate.
- Ran `dir` in Powershell and fixed the scrolling issues
- Clicked all over the place and dragged to make sure selection works.
- Checked retro terminal effect manually with Powershell.
2020-04-13 20:09:02 +00:00
Mike Griese ffbdfe32ac
Add a spec for the Command Palette (#2193)
* Add a spec for the Command Palette

  specs #2046.

* Apply suggestions from code review

Co-Authored-By: Carlos Zamora <carlos.zamora@microsoft.com>

* * Add note from Carlos about UIA
* Add a note about nested commands

* fix Michael's comments

* Move to `doc/specs/`

* Apply suggestions from code review

Co-Authored-By: Dustin L. Howett (MSFT) <duhowett@microsoft.com>

* Add updates from Dustin

  esp. considering keybindings args, localization

* add notes about expanding profiles, localization

* move this spec to the drafts folder

Co-authored-by: Carlos Zamora <carlos.zamora@microsoft.com>
Co-authored-by: Dustin L. Howett (MSFT) <duhowett@microsoft.com>
2020-04-13 14:31:58 -05:00
Carlos Zamora ea1bb2ed93
Add 'copyFormatting' global setting (#5299)
## Summary of the Pull Request
Implements `copyFormatting` as a global setting. When enabled, formatting such as font and foreground/background colors are copied to the clipboard on _all_ copy operations.

Also updates the schema and docs.

## References
#5212 - Spec for Formatted Copying
#4191 - Setting to enable/disable formatted copy

#5263 - PR prematurely merged without approval of #5212 

This feature will also have an impact on these yet-to-be-implemented features:
- #5262 - copyFormatting Keybinding Arg for Copy
- #1553 - Pointer Bindings
- #4191 - add array support for `copyFormatting`


## Detailed Description of the Pull Request
We already check if the hstring passed into the clipboard is empty before setting it. So the majority of the changes are actually just adding the global setting in.

## Validation Steps Performed
| `copyFormatting` | Mouse Copy | Keyboard Copy |
|--|--|--|
| not set (`false`) | ✔ | ✔ |
| `true` | ✔ | ✔ |
| `false` | ✔ | ✔ |
2020-04-09 23:32:38 +00:00
Kayla Cinnamon 08df4fc27a
doc: add a spec for the change to formatted copying (#5212)
This is the spec that goes into what we do with HTML copy once we set the
default copy behavior to plain text.

Specs #4191 

Co-authored-by: Carlos Zamora <carlos.zamora@microsoft.com>
Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
Co-authored-by: Leon Liang <57155886+leonMSFT@users.noreply.github.com>
2020-04-09 16:30:19 -07:00
Mike Griese 6f0f245dd0
Don't wait for a connection to finish when a control is closed (#5303)
## Summary of the Pull Request

When a pane is closed by a connection, we want to wait until the connection is actually `Closed` before we fire the actual `Closed` event. If the connection didn't close gracefully, there are scenarios where we want to print a message to the screen.

However, when a pane is closed by the UI, we don't really care to wait for the connection to be completely closed. We can just do it whenever. So I've moved that call to be on a background thread.

## PR Checklist
* [x] Closes #1996
* [x] I work here
* [ ] Tests added/passed
* [n/a] Requires documentation to be updated

## Detailed Description of the Pull Request / Additional comments
Previously we'd wait for the connection to close synchronously when closing tabs or panes. For misbehaving applications like `ssh.exe`, that could result in the `Close` needing to `WaitForSingleObject` _on the UI thread_. If the user closed the tab / pane either with a keybinding or with some other UI element, they don't really care to see the error message anymore. They just want the pane closed. So there's no need to wait for the actual connection to close - the app can just continue on with whatever it was doing.

## Validation Steps Performed
Messed around with closing tabs, panes, tabs with many panes, the entire window. Did this with keybindings, or by clicking on the 'x' on the tab, the 'x' on the window, or using middle-click.

I'm always scared of things like this, so there's a 50% chance this makes things horribly worse.
2020-04-09 23:27:56 +00:00
Carlos Zamora c65de31172
Update default settings.json experience (#5217)
## Summary of the Pull Request
Add comments and settings to settings.json for discoverability.

## PR Checklist
* [X] Closes #5187 
* [X] Closes #5188 
* [X] Closes #3058
2020-04-09 23:21:22 +00:00
Carlos Zamora 2bd1e398bd
Add default values to defaults.json (#5231)
## Summary of the Pull Request
This updates defaults.json to include the default values for all global and profile settings. Most default keybinding args are added too. This also updates a few outdated items found in the docs.

## PR Checklist
* [X] Closes #5189 

## Validation Steps Performed
After making the changes, I made sure all of the settings are deserialized by debugging and stepping through the `LayerJson` code.
- [X] Global Settings

I was mainly looking for two things:
- the key/value pair is found and read
- the value did not change before/after the pair was read
2020-04-09 23:13:57 +00:00
Dustin L. Howett (MSFT) a09989749a
Fall back to TerminalApp.dll's version when we're unpackaged (#5274)
This pull request makes sure we still get a usable (for troubleshooting purposes) version number in the about dialog and settings file when the user is running unpackaged.

This introduces a magic LCID constant (0x0409).B y default, Package ES emits
version resource information that says we're localized to ... language zero.
It also emits a language-coded version block for 0x0409 (en-US).

These two things cannot both be true. Collapse the wave function by hardcoding
0x0409.
2020-04-09 15:59:21 -07:00
James Holderness 2d09dfd48b
Add support for the DSR-OS operating status report (#5300)
This adds support for the VT escape sequence that requests the
terminal's operating status. There is no attempt to actually verify the
status of the app, though. We always return a response indicating a good
operating condition (the same as most terminal emulators).

## PR Checklist
* [x] CLA signed.
* [x] Tests added/passed

## Detailed Description of the Pull Request / Additional comments

This required an update to the `OutputStateMachineEngine` to accept the
`DSR-OS` type, since it only dispatches types that it recognises (I
think that's unnecessary, but that's an issue for another day).

The actual processing of the request is handled in the `AdaptDispatch`
class, where it simply responds with a hard coded sequence (`CSI 0 n`),
indicating a good operating condition.

## Validation Steps Performed

I've added unit tests to confirm that the request is dispatched
correctly, and the appropriate response is returned. I've also manually
confirmed that the test of the _Device Status Report_ in _Vttest_ is now
succeeding.

Closes #5052
2020-04-09 13:11:37 -07:00
Dustin L. Howett (MSFT) 7936605cc9
Control: make sure we actually have a dispatcher in 100ms (#5292)
This fixes a silly regression introduced by 1299a839b. We would crash
when the connection updated the cursor as it was being torn down.
2020-04-09 12:08:06 -07:00
Dustin L. Howett (MSFT) edf79b281a
Revert "Add 'copyFormatting' global setting (#5263)" (#5298)
This reverts commit c55d9cd62d.
It was merged with its corresponding specification unmerged.
2020-04-09 11:13:21 -07:00
Carlos Zamora c55d9cd62d
Add 'copyFormatting' global setting (#5263)
## Summary of the Pull Request
Implements `copyFormatting` as a global setting. When enabled, formatting such as font and foreground/background colors are copied to the clipboard on _all_ copy operations.

Also updates the schema and docs.

## References
#5212 - Spec for Formatted Copying
#4191 - Setting to enable/disable formatted copy

This feature will also have an impact on these yet-to-be-implemented features:
- #5262 - copyFormatting Keybinding Arg for Copy
- #1553 - Pointer Bindings


## PR Checklist
* [X] Closes #4191

## Detailed Description of the Pull Request / Additional comments
We already check if the hstring passed into the clipboard is empty before setting it. So the majority of the changes are actually just adding the global setting in.

## Validation Steps Performed
| `copyFormatting` | Mouse Copy | Keyboard Copy |
|--|--|--|
| not set (`false`) | ✔ | ✔ |
| `true` | ✔ | ✔ |
| `false` | ✔ | ✔ |
2020-04-09 18:03:32 +00:00
Kayla Cinnamon 191b0d288a
doc: update list of team members in README (#5296) 2020-04-09 10:38:12 -07:00
Dustin L. Howett (MSFT) 1299a839bd
Muffle updates to the cursor position to 1/~100ms (#5289)
This stops us from dispatching back-to-back terminal cursor position
updates to the TSF control before it has a chance to get back to us.

Fixes #5288.
2020-04-08 17:20:51 -07:00
Mike Griese 6fabc4abb7
Fix copying wrapped lines by implementing better scrolling (#5181)
Now that the Terminal is doing a better job of actually marking which
lines were and were not wrapped, we're not always copying lines as
"wrapped" when they should be. We're more correctly marking lines as not
wrapped, when previously we'd leave them marked wrapped.

The real problem is here in the `ScrollFrame` method - we'd manually
newline the cursor to make the terminal's viewport shift down to a new
line. If we had to scroll the viewport for a _wrapped_ line, this would
cause the Terminal to mark that line as broken, because conpty would
emit an extra `\n` that didn't actually exist.

This more correctly implements `ScrollFrame`. Now, well move where we
"thought" the cursor was, so when we get to the next `PaintBufferLine`,
if the cursor needs to newline for the next line, it'll newline, but if
we're in the middle of a wrapped line, we'll just keep printing the
wrapped line.

A couple follow up bugs were found to be caused by the same bad logic.
See #5039 and #5161 for more details on the investigations there.

## References

* #4741 RwR, which probably made this worse
* #5122, which I branched off of 
* #1245, #357 - a pair of other conpty wrapped lines bugs
* #5228 - A followup issue for this PR

## PR Checklist
* [x] Closes #5113
* [x] Closes #5180 (by fixing DECRST 25)
* [x] Closes #5039
* [x] Closes #5161 (by ensuring we only `removeSpaces` on the actual
  bottom line)
* [x] I work here
* [x] Tests added/passed
* [n/a] Requires documentation to be updated

## Validation Steps Performed

* Checked the cases from #1245, #357 to validate that they still work
* Added more and more tests for these scenarios, and then I added MORE
  tests
* The entire team played with this in selfhost builds
2020-04-09 00:06:25 +00:00
Dustin L. Howett (MSFT) 5622f230a8
Control: Start the connection outside of lock (#5286)
When the connection printed text immediately, synchronously, as part of
Start() it would cause terminal to deadlock. We should start the
connection outside of lock.

The ConptyConnection would do this when it failed to launch something
(trivial repro: `wt -- xyz`).

The TelnetConnection would do this all the time, because local loopback
telnet is fast and easy.
2020-04-08 13:55:20 -07:00
Dustin L. Howett (MSFT) 761bee80c0
Localize the profile name for cmd, change it to Command Prompt (#5287)
This commit introduces another template replacement for the user's
default settings, COMMAND_PROMPT_LOCALIZED_NAME, which will be replaced
with the contents of the CommandPromptDisplayName resource.

By default, that will be "Command Prompt." This name change will apply
only for new users, and only on first launch. Changes in the system
locale after first launch will not impact the name of the profile.

If the user _removes_ the name from their command prompt profile, its
name will revert irrecoverably to "Command Prompt". They will not be
given a chance to regenerate a localized name.

Fixes #4476.
2020-04-08 13:41:58 -07:00
Josh Soref 26778440b3
ci: spelling: update to 0.0.14a (#5270) 2020-04-07 14:58:12 -07:00
Dustin L. Howett (MSFT) 7335232cda
ci/spelling: add ecma to the allowlist (#5275) 2020-04-07 14:39:21 -07:00
Carlos Zamora 7c7db79782
Rename 'requestedTheme' to 'theme' (#5265)
## Summary of the Pull Request

Renames the `requestedTheme` global setting to `theme`. Propagates updates to...
- schema
- doc
- defaults.json
- universal-defaults.json
 
## PR Checklist
* [X] Closes #5264 

## Validation Steps Performed
| `theme` | Success? |
|--|--|
| `system` | ✔ |
| `light` | ✔ |
| `dark` | ✔ |

But we really know that `dark` is the one we care about here 😉
2020-04-07 19:14:06 +00:00
Leonard Hecker a9c9714295
Delegate all character input to the character event handler (#4192)
My basic idea was that `WM_CHAR` is just the better `WM_KEYDOWN`.
The latter fails to properly support common dead key sequences like in
#3516.

As such I added some logic to `Terminal::SendKeyEvent` to make it return
false if the pressed key represents a printable character.
This causes us to receive a character event with a (hopefully) correctly
composed code unit, which then gets sent to `Terminal::SendCharEvent`.
`Terminal::SendCharEvent` in turn had to be modified to support
potentially pressed modifier keys, since `Terminal::SendKeyEvent` isn't
doing that for us anymore.
Lastly `TerminalInput` had to be modified heavily to support character
events with modifier key states. In order to do so I merged its
`HandleKey` and `HandleChar` methods into a single one, that now handles
both cases.
Since key events will now contain character data and character events
key codes the decision logic in `TerminalInput::HandleKey` had to be
rewritten.

## PR Checklist
* [x] CLA signed
* [x] Tests added/passed
* [x] I've discussed this with core contributors already.

## Validation Steps Performed

* See #3516.
* I don't have any keyboard that generates surrogate characters. Due to
  this I modified `TermControl::_SendPastedTextToConnection` to send the
  data to `_terminal->SendCharEvent()` instead. I then pasted the test
  string ""𐐌𐐜𐐬" and ensured that the new `TerminalInput::_SendChar`
  method still correctly assembles surrogate pairs.

Closes #3516
Closes #3554 (obsoleted by this PR)
Potentially impacts #391, which sounds like a duplicate of #3516
2020-04-07 19:09:28 +00:00
Dustin L. Howett (MSFT) 52d6c03e64
Patch the default profile and version into the settings template (#5232)
This pull request introduces unexpanded variables (`%DEFAULT_PROFILE%`,
`%VERSION%` and `%PRODUCT%`) to the user settings template and code to
expand them.

While doing this, I ran into a couple things that needed to widen from
accepting strings to accepting string views. I also had to move
application name and version detection up to AppLogic and expose the
AppLogic singleton.

The dynamic profile generation logic had to be moved to before we inject
the templated variables, as the new default profile depends on the
generated dynamic profiles.

References #5189, #5217 (because it has a dependency on `VERSION` and
`PRODUCT`).

## PR Checklist
* [x] Closes #2721 
* [x] CLA signed
* [x] Tests added/passed
* [ ] Requires documentation to be updated
* [x] I've discussed this with core contributors already

## Validation Steps Performed
Deleted my settings and watched them regenerate.
2020-04-07 11:35:05 -07:00