19 Commits

Author SHA1 Message Date
Leonard Hecker
5ddf429688 wip 2025-09-02 19:47:21 +02:00
Dustin L. Howett
696dac2c6a
wpf: force builtin glyphs (#18906)
They're much prettier, but some users may not be 100% happy.
2025-05-13 18:18:16 -05:00
Dustin L. Howett
c64a9d2a32
wpf: allow OSC 52 to write the clipboard (#18905)
We never hooked up this callback!

This allows a CLI application to emit text directly to the clipboard.
2025-05-13 18:18:05 -05:00
Dustin L. Howett
06f736bebe
wpf: use the new TSF implementation (#18861)
This fixes two issues in the WPF terminal control:
- The emoji picker and other IME candidate windows didn't show up in the
right place
- Submitting an emoji via the emoji picker would result in two win32
input mode events with a VK of 65535 and the surrogate pair halves.

I am not sure I did the right thing with the thread TSF handle...
2025-05-02 18:30:52 -05:00
Leonard Hecker
70f85a4a35
Fix a shutdown race condition in ControlCore (#18632)
I found multiple issues while investigating this:
* Render thread shutdown is racy, because it doesn't actually stop the
render thread.
* Lifetime management in `ControlCore` failed to account for the
circular dependency of render thread --> renderer --> render data -->
terminal --> renderer --> render thread. Fixed by reordering the
`ControlCore` members to ensure their correct destruction.
* Ensured that the connection setter calls close on the previous
connection.

(Hopefully) Closes #18598

## Validation Steps Performed
* Can't repro the original failure 
* Opening and closing tabs as fast as possible doesn't crash anymore 
* Detaching and reattaching a tab producing continuous output 
2025-03-14 15:06:01 -07:00
Danny Weinberg
282670a092
Allow copying with ANSI escape code control sequences (#17059)
## Summary of the Pull Request

This extends the copy command to be able to include control sequences,
for use in tools that subsequently know how to parse and display that.

## References and Relevant Issues

https://github.com/microsoft/terminal/issues/15703

## Detailed Description of the Pull Request / Additional comments

At a high level, this:
- Expands the `CopyTextArgs` to have a `withControlSequences` bool.
- Plumbs that bool down through many layers to where we actuall get
  data out of the text buffer.
- Modifies the existing `TextBuffer::Serialize` to be more generic
  and renames it to `TextBuffer::ChunkedSerialize`.
- Uses the new `ChunkedSerialize` to generate the data for the copy
  request.

## Validation Steps Performed

To test this I've manually:
- Generated some styled terminal contents, copied it with the control
  sequences, pasted it into a file, `cat`ed the file and seen that it
  looks the same.
- Set `"firstWindowPreference": "persistedWindowLayout"` and
  validated that the contents of windows are saved and
  restored with styling intact.

I also checked that `Invoke-OpenConsoleTests` passed.

## PR Checklist
- [x] Closes #15703
- [ ] Tests added/passed
- [x] Documentation updated
- If checked, please file a pull request on [our docs
repo](https://github.com/MicrosoftDocs/terminal) and link it here:
https://github.com/MicrosoftDocs/terminal/pull/756
- [x] Schema updated (if necessary)
2024-11-20 17:03:04 +01:00
Leonard Hecker
cd1742454c
Use floating DIPs throughout the stack (#18027)
I sure hope I didn't break anything!
While `til::math` was a good idea its convenience led us to use it
in the only place where it absolutely must not be used: The UI code.
So, this PR replaces all those `til::point`s, etc., with floats.
Now we use DIPs consistently throughout all layers of the UI code,
except for the UIA area (that would've required too many changes).

## Validation Steps Performed
Launch, looks good, no obvious defects, UIA positioning seems ok. 
2024-11-15 04:26:10 -08:00
James Holderness
5e8e10fdc0
Add support for resetting the color scheme with RIS (#17879)
## Summary of the Pull Request

This improves our `RIS` (hard reset) implementation, so it now also
resets any changes that are made to the color table and color aliases,
which is one of the things it's supposed to be doing.

## References and Relevant Issues

This is also a small step towards implementing the `OSC` sequences that
reset individual color table entries (issue #3719).

## Detailed Description of the Pull Request / Additional comments

The way this works is by having a second copy of the color table and
alias indices to hold the default values in the `RenderSettings` class.
This default set is initially populated at startup with the user's
chosen color scheme, but can also potentially be updated if the user
changes their settings while a session is already in progress.

When we receive an `RIS` request, we just copy the default values back
over the active settings, and refresh the renderer.

## Validation Steps Performed

I've manually tested both OpenConsole and Windows Terminal by changing
my color scheme programmatically, and then confirming that the original
colors are restored when an `RIS` sequence is received.

I've also added some basic unit tests that check both the color aliases
and color table are restored by `RIS`.

## PR Checklist
- [x] Tests added/passed
2024-09-16 13:59:12 -05:00
Dustin L. Howett
cbb4a0a01c
Allow OSC 17 to set the selection background color (#17742)
This pull request adds support for setting and querying the selection
color with `OSC 17`.

To make this possible, I had to move selection color down into the color
table where it always belonged. This lets us get rid of the special
`SetSelectionColor` method from the surface of AtlasEngine, and reunites
selection colors with the rest of the special colors.
2024-08-22 12:58:11 -05:00
Dustin L. Howett
faf21acbc7
atlas: draw selection colors as background/foreground instead of alpha overlay (#17725)
With the merge of #17638, selections are now accumulated early in the
rendering process. This allows Atlas, which currently makes decisions
about cell foreground/background at the time of text rendering,
awareness of the selection ranges *before* text rendering begins.

As a result, we can now paint the selection into the background and
foreground bitmaps. We no longer need to overlay a rectangle, or series
of rectangles, on top of the rendering surface and alpha blend the
selection color onto the final image.

As a reminder, "alpha selection" was always a stopgap because we didn't
have durable per-cell foreground and background customization in the
original DxEngine.

Selection foregrounds are not customizable, and will be chosen using the
same color distancing algorithm as the cursor. We can make them
customizable "easily" (once we figure out the schema for it) for #3580.

`ATLAS_DEBUG_SHOW_DIRTY` was using the `Selection` shading type to draw
colored regions. I didn't want to break that, so I elected to rename the
`Selection` shading type to `FilledRect` and keep its value. It helps
that the shader didn't have any special treatment for
`SHADING_TYPE_SELECTION`.

This fixes the entire category of issues created by selection being an
80%-opacity white rectangle. However, given that it changes the imputed
colors of the text it will reveal `SGR 8` concealed/hidden characters.

Refs #17355
Refs #14859
Refs #11181
Refs #8716
Refs #4971
Closes #3561
2024-08-19 14:54:18 +00:00
Leonard Hecker
c9e200734e
Improve Viewport and Viewport::WalkInBounds (#17143)
This removes all of the 2D iteration machinery. Imagine the text buffer
as a `Cell[w][h]` grid. Clearly, this is identical to a `Cell[w*h]`
array, which shows that copying between overlapping ranges only needs
either forward or backward copying, and not left/right/top/down.

With `WalkDir` removed, `WalkInBounds` can be rewritten with basic
arithmetic which allows `pos` to be an exclusive end coordinate.
2024-07-02 15:48:56 +00:00
Leonard Hecker
99061ee272
Use float instead of double by default (#17100)
While `double` is probably generally preferable for UI code,
our application is essentially a complex wrapper wrapper around
DWrite, D2D and D3D, all of which use `float` exclusively.

Of course it also uses XAML, but that one uses `float` for roughly
1/3rd of its API functions, so I'm not sure what it prefers.
Additionally, it's mostly a coincidence that we use WinUI/XAML for
Windows Terminal whereas DWrite/D2D/D3D are effectively essential.
This is demonstrated by the fact that we have a `HwndTerminal`,
while there's no alternative to e.g. D3D on Windows.

The goal of this PR is that DIP based calculations never end up
mixing `float` and `double`. This PR also changes opacity-related
values to `float` because I felt like that fits the theme.
2024-04-23 00:07:00 +00:00
Leonard Hecker
20b0bed46d
Reduce cost of cursor invalidation (#15500)
Performance of printing enwik8.txt at the following block sizes:
4KiB (printf): 53MB/s -> 58MB/s
128KiB (cat): 170MB/s -> 235MB/s

This commit is imperfect. Support for more than one rendering
engine was "hacked" into `Renderer` and is not quite correct.
As such, this commit cannot fix cursor invalidation correctly either,
and while some bugs are fixed (engines may see highly inconsistent
TextBuffer and Cursor states), it introduces others (an error in the
first engine may result in the second engine not executing).
Neither of those are good and the underlying issue remains to be fixed.

## Validation Steps Performed
* Seems ok? 
2024-04-10 18:51:02 +00:00
Leonard Hecker
a67a13288c
AtlasEngine: Make Direct2D/3D and Present1 configurable (#16939)
This implements `SetForceFullRepaintRendering` and adds a new
`SetGraphicsAPI` function. The former toggles `Present1` on and off
and the latter allows users to explicitly request Direct2D/3D.

On top of these changes I did a minor cleanup of the interface,
because now that DxRenderer is gone we don't need all that anymore.

Closes #14254
Closes #16747

## Validation Steps Performed
* Toggling Direct2D on/off changes colored ligature support 
* Toggling Present1 on/off can be observed in a debugger 
* Toggling WARP on/off changes GPU metrics 

---------

Co-authored-by: Dustin L. Howett <duhowett@microsoft.com>
2024-03-26 21:31:24 +00:00
Dustin L. Howett
d2bd18735e
Fix a number of minor issues that Clang flagged (again! again!) (#16863)
* `[[nodiscard]]` and `[[maybe_unused]]` must come before `virtual` and
`static` qualifiers
* MSVC and Clang disagree on how `gsl::suppress` should look;
fortunately, GSL provides a macro to paper over the difference
* Clang throws "pessimizing move" warnings when you `std::move` a
temporary, as it makes copy elision impossible
* The fuzzing logic was using an unspecified template expansion
`CFuzzLogic<>` before the type had been declared
* LibraryResources was emitting most of the `.util` section with
read-write permissions and some of it with read-only

Refs #15952
2024-03-18 09:15:35 -05:00
Leonard Hecker
bf25595961
Remove DxEngine (#16278)
With AtlasEngine being fairly stable at this point and being enabled
by default in the 1.19 branch, this changeset removes DxEngine.

## Validation Steps Performed
* WT builds and runs 
* WpfTestNetCore 
* Saving the config removes the `useAtlasEngine` key 
2024-02-21 23:50:59 +00:00
Tushar Singh
a3ac337d88
Refactor TextBuffer::GenHTML/RTF to read the buffer directly (#16377)
`TextBuffer::GenHTML` and `TextBuffer::GenRTF` now read directly from
the TextBuffer.

- Since we're reading from the buffer, we can now read _all_ the
attributes saved in the buffer. Formatted copy now copies most (if not
all) font/color attributes in the requested format (RTF/HTML).
- Use `TextBuffer::CopyRequest` to pass all copy-related options into
text generation functions as one unit.
- Helper function `TextBuffer::CopyRequest::FromConfig()` generates a
copy request based on Selection mode and user configuration.
- Both formatted text generation functions now use `std::string` and
`fmt::format_to` to generate the required strings. Previously, we were
using `std::ostringstream` which is not recommended due to its potential
overhead.
- Reading attributes from `ROW`'s attribute RLE simplified the logic as
we don't have to track attribute change between the text.
- On the caller side, we do not have to rebuild the plain text string
from the vector of strings anymore. `TextBuffer::GetPlainText()` returns
the entire text as one `std::string`.
- Removed `TextBuffer::TextAndColors`.
- Removed `TextBuffer::GetText()`. `TextBuffer::GetPlainText()` took its
place.

This PR also fixes two bugs in the formatted copy:

- We were applying line breaks after each selected row, even though the
row could have been a Wrapped row. This caused the wrapped rows to break
when they shouldn't.
- We mishandled Unicode text (\uN) within the RTF copy. Every next
character that uses a surrogate pair or high codepoint was missing in
the copied text when pasted to MSWord. The command `\uc4` should have
been `\uc1`, which is used to tell how many fallback characters are used
for each Unicode codepoint (\u). We always use one `?` character as the
fallback.

Closes #16191

**References and Relevant Issues**

- #16270

**Validation Steps Performed**

- Casual copy-pasting from Terminal or OpenConsole to word editors works
as before.
- Verified HTML copy by copying the generated HTML string and running it
through an HTML viewer.
[Sample](https://codepen.io/tusharvickey/pen/wvNXbVN)
- Verified RTF copy by copy-pasting the generated RTF string into
MSWord.
- SingleLine mode works (<kbd>Shift</kbd>+ copy)
- BlockSelection mode works (<kbd>Alt</kbd> selection)
2024-01-29 22:20:33 +00:00
Leonard Hecker
71a1a97a9a
Fix deadlocks due to holding locks across WriteFile calls (#16224)
This fixes a number of bugs introduced in 4370da9, all of which are of
the same kind: Holding the terminal lock across `WriteFile` calls into
the ConPTY pipe. This is problematic, because the pipe has a tiny buffer
size of just 4KiB and ConPTY may respond on its output pipe, before the
entire buffer given to `WriteFile` has been emptied. When the ConPTY
output thread then tries to acquire the terminal lock to begin parsing
the VT output, we get ourselves a proper deadlock (cross process too!).

The solution is to tease `Terminal` further apart into code that is
thread-safe and code that isn't. Functions like `SendKeyEvent` so far
have mixed them into one, because when they get called by `ControlCore`
they both, processed the data (not thread-safe as it accesses VT state)
and also sent that data back into `ControlCore` through a callback
which then indirectly called into the `ConptyConnection` which calls
`WriteFile`. Instead, we now return the data that needs to be sent from
these functions, and `ControlCore` is free to release the lock and
then call into the connection, which may then block indefinitely.

## Validation Steps Performed
* Start nvim in WSL
* Press `i` to enter the regular Insert mode
* Paste 1MB of text
* Doesn't deadlock 
2023-11-08 10:28:07 -06:00
Dustin L. Howett
059f7701f2
Merge PublicTerminalCore into TermControl (#15992)
This pull request moves HwndTerminal into Microsoft.Terminal.Control.Lib
and removes PublicTerminalCore completely.

Microsoft.Terminal.Control.dll now exports the C API from HwndTerminal.

This adds ~100kb to Microsoft.Terminal.Control.dll and ~1400kb to the
WPF package (per architecture) but with the coming interactivity
platform merge it's going to benefit us big time.
2023-09-20 15:21:55 +00:00