2019-05-03 00:29:04 +02:00
|
|
|
// Copyright (c) Microsoft Corporation.
|
|
|
|
// Licensed under the MIT license.
|
|
|
|
#pragma once
|
2019-05-23 19:44:27 +02:00
|
|
|
|
|
|
|
#include "../../terminal/adapter/DispatchTypes.hpp"
|
2021-10-26 23:12:22 +02:00
|
|
|
#include "../../terminal/input/terminalInput.hpp"
|
Refactor TerminalDispatch (graphics) to match AdaptDispatch (#6728)
This is essentially a rewrite of the
`TerminalDispatch::SetGraphicsRendition` method, bringing it into closer
alignment with the `AdaptDispatch` implementation, simplifying the
`ITerminalApi` interface, and making the code easier to extend. It adds
support for a number of attributes which weren't previously implemented.
REFERENCES
* This is a mirror of the `AdaptDispatch` refactoring in PR #5758.
* The closer alignment with `AdaptDispatch` is a small step towards
solving issue #3849.
* The newly supported attributes should help a little with issues #5461
(italics) and #6205 (strike-through).
DETAILS
I've literally copied and pasted the `SetGraphicsRendition`
implementation from `AdaptDispatch` into `TerminalDispatch`, with only
few minor changes:
* The `SetTextAttribute` and `GetTextAttribute` calls are slightly
different in the `TerminalDispatch` version, since they don't return a
pointless `success` value, and in the case of the getter, the
`TextAttribute` is returned directly instead of by reference.
Ultimately I'd like to move the `AdaptDispatch` code towards that way
of doing things too, but I'd like to deal with that later as part of a
wider refactoring of the `ConGetSet` interface.
* The `SetIndexedForeground256` and `SetIndexedBackground256` calls
required the color indices to be remapped in the `AdaptDispatch`
implementation, because the conhost color table is in a different
order to the XTerm standard. `TerminalDispatch` doesn't have that
problem, so doesn't require the mapping.
* The index color constants used in the 16-color `SetIndexedForeground`
and `SetIndexedBackground` calls are also slightly different for the
same reason.
VALIDATION
I cherry-picked this code on top of the #6506 and #6698 PRs, since
that's only way to really get the different color formats passed-through
to the terminal. I then ran a bunch of manual tests with various color
coverage scripts that I have, and confirmed that all the different color
formats were being rendered as expected.
Closes #6725
2020-07-01 20:13:42 +02:00
|
|
|
#include "../../buffer/out/TextAttribute.hpp"
|
2021-04-16 18:26:28 +02:00
|
|
|
#include "../../types/inc/Viewport.hpp"
|
2019-05-23 19:44:27 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
namespace Microsoft::Terminal::Core
|
|
|
|
{
|
|
|
|
class ITerminalApi
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~ITerminalApi() {}
|
2019-10-11 23:02:09 +02:00
|
|
|
ITerminalApi(const ITerminalApi&) = default;
|
|
|
|
ITerminalApi(ITerminalApi&&) = default;
|
|
|
|
ITerminalApi& operator=(const ITerminalApi&) = default;
|
|
|
|
ITerminalApi& operator=(ITerminalApi&&) = default;
|
|
|
|
|
2020-01-03 19:44:27 +01:00
|
|
|
virtual bool PrintString(std::wstring_view string) noexcept = 0;
|
|
|
|
virtual bool ExecuteChar(wchar_t wch) noexcept = 0;
|
2019-05-03 00:29:04 +02:00
|
|
|
|
Refactor TerminalDispatch (graphics) to match AdaptDispatch (#6728)
This is essentially a rewrite of the
`TerminalDispatch::SetGraphicsRendition` method, bringing it into closer
alignment with the `AdaptDispatch` implementation, simplifying the
`ITerminalApi` interface, and making the code easier to extend. It adds
support for a number of attributes which weren't previously implemented.
REFERENCES
* This is a mirror of the `AdaptDispatch` refactoring in PR #5758.
* The closer alignment with `AdaptDispatch` is a small step towards
solving issue #3849.
* The newly supported attributes should help a little with issues #5461
(italics) and #6205 (strike-through).
DETAILS
I've literally copied and pasted the `SetGraphicsRendition`
implementation from `AdaptDispatch` into `TerminalDispatch`, with only
few minor changes:
* The `SetTextAttribute` and `GetTextAttribute` calls are slightly
different in the `TerminalDispatch` version, since they don't return a
pointless `success` value, and in the case of the getter, the
`TextAttribute` is returned directly instead of by reference.
Ultimately I'd like to move the `AdaptDispatch` code towards that way
of doing things too, but I'd like to deal with that later as part of a
wider refactoring of the `ConGetSet` interface.
* The `SetIndexedForeground256` and `SetIndexedBackground256` calls
required the color indices to be remapped in the `AdaptDispatch`
implementation, because the conhost color table is in a different
order to the XTerm standard. `TerminalDispatch` doesn't have that
problem, so doesn't require the mapping.
* The index color constants used in the 16-color `SetIndexedForeground`
and `SetIndexedBackground` calls are also slightly different for the
same reason.
VALIDATION
I cherry-picked this code on top of the #6506 and #6698 PRs, since
that's only way to really get the different color formats passed-through
to the terminal. I then ran a bunch of manual tests with various color
coverage scripts that I have, and confirmed that all the different color
formats were being rendered as expected.
Closes #6725
2020-07-01 20:13:42 +02:00
|
|
|
virtual TextAttribute GetTextAttributes() const noexcept = 0;
|
|
|
|
virtual void SetTextAttributes(const TextAttribute& attrs) noexcept = 0;
|
2019-05-03 00:29:04 +02:00
|
|
|
|
2021-04-16 18:26:28 +02:00
|
|
|
virtual Microsoft::Console::Types::Viewport GetBufferSize() noexcept = 0;
|
2020-01-03 19:44:27 +01:00
|
|
|
virtual bool SetCursorPosition(short x, short y) noexcept = 0;
|
|
|
|
virtual COORD GetCursorPosition() noexcept = 0;
|
2020-03-13 18:39:42 +01:00
|
|
|
virtual bool SetCursorVisibility(const bool visible) noexcept = 0;
|
Remove unneeded VT-specific control character handling (#4289)
## Summary of the Pull Request
This PR removes all of the VT-specific functionality from the `WriteCharsLegacy` function that dealt with control characters, since those controls are now handled in the state machine when in VT mode. It also removes most of the control character handling from the `Terminal::_WriteBuffer` method for the same reason.
## References
This is a followup to PR #4171
## PR Checklist
* [x] Closes #3971
* [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA
* [ ] Tests added/passed
* [ ] 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: https://github.com/microsoft/terminal/issues/780#issuecomment-570287435
## Detailed Description of the Pull Request / Additional comments
There are four changes to the `WriteCharsLegacy` implementation:
1. The `TAB` character had special case handling in VT mode which is now no longer required. This fixes a bug in the Python REPL editor (when run from a cmd shell in Windows Terminal), which would prevent you tabbing past the end of the line. It also fixes #3971.
2. Following on from point 1, the `WC_NONDESTRUCTIVE_TAB` flag could also now be removed. It only ever applied in VT mode, in which case the `TAB` character isn't handled in `WriteCharsLegacy`, so there isn't a need for a non-destructive version.
3. There used to be special case handling for a `BS` character at the beginning of the line when in VT mode, and that is also no longer required. This fixes an edge-case bug which would prevent a glyph being output for code point 8 when `ENABLE_PROCESSED_OUTPUT` was disabled.
4. There was quite a lot of special case handling for control characters in the "end-of-line wrap" implementation, which is no longer required. This fixes a bug which would prevent "low ASCII" characters from wrapping when output at the end of a line.
Then in the `Terminal::_WriteBuffer` implementation, I've simply removed all control character handling, except for `LF`. The Terminal is always in VT mode, so the control characters are always handled by the state machine. The exception for the `LF` character is simply because it doesn't have a proper implementation yet, so it still passes the character through to `_WriteBuffer`. That will get cleaned up eventually, but I thought that could wait for a later PR.
Finally, with the removal of the VT mode handling in `WriteCharsLegacy`, there was no longer a need for the `SCREEN_INFORMATION::InVTMode` method to be publicly accessible. That has now been made private.
## Validation Steps Performed
I've only tested manually, making sure the conhost and Windows Terminal still basically work, and confirming that the above-mentioned bugs are fixed by these changes.
2020-01-29 20:18:46 +01:00
|
|
|
virtual bool CursorLineFeed(const bool withReturn) noexcept = 0;
|
2020-03-13 18:39:42 +01:00
|
|
|
virtual bool EnableCursorBlinking(const bool enable) noexcept = 0;
|
2019-05-03 00:29:04 +02:00
|
|
|
|
2020-01-03 19:44:27 +01:00
|
|
|
virtual bool DeleteCharacter(const size_t count) noexcept = 0;
|
|
|
|
virtual bool InsertCharacter(const size_t count) noexcept = 0;
|
|
|
|
virtual bool EraseCharacters(const size_t numChars) noexcept = 0;
|
|
|
|
virtual bool EraseInLine(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::EraseType eraseType) noexcept = 0;
|
|
|
|
virtual bool EraseInDisplay(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::EraseType eraseType) noexcept = 0;
|
2019-05-03 00:29:04 +02:00
|
|
|
|
2020-10-01 03:00:06 +02:00
|
|
|
virtual bool WarningBell() noexcept = 0;
|
2020-01-03 19:44:27 +01:00
|
|
|
virtual bool SetWindowTitle(std::wstring_view title) noexcept = 0;
|
2019-05-03 00:29:04 +02:00
|
|
|
|
Consolidate the color palette APIs (#11784)
This PR merges the default colors and cursor color into the main color
table, enabling us to simplify the `ConGetSet` and `ITerminalApi`
interfaces, with just two methods required for getting and setting any
form of color palette entry.
The is a follow-up to the color table standardization in #11602, and a
another small step towards de-duplicating `AdaptDispatch` and
`TerminalDispatch` for issue #3849. It should also make it easier to
support color queries (#3718) and a configurable bold color (#5682) in
the future.
On the conhost side, default colors could originally be either indexed
positions in the 16-color table, or separate standalone RGB values. With
the new system, the default colors will always be in the color table, so
we just need to track their index positions.
To make this work, those positions need to be calculated at startup
based on the loaded registry/shortcut settings, and updated when
settings are changed (this is handled in
`CalculateDefaultColorIndices`). But the plus side is that it's now much
easier to lookup the default color values for rendering.
For now the default colors in Windows Terminal use hardcoded positions,
because it doesn't need indexed default colors like conhost. But in the
future I'd like to extend the index handling to both terminals, so we
can eventually support the VT525 indexed color operations.
As for the cursor color, that was previously stored in the `Cursor`
class, which meant that it needed to be copied around in various places
where cursors were being instantiated. Now that it's managed separately
in the color table, a lot of that code is no longer required.
## Validation
Some of the unit test initialization code needed to be updated to setup
the color table and default index values as required for the new system.
There were also some adjustments needed to account for API changes, in
particular for methods that now take index values for the default colors
in place of COLORREFs. But for the most part, the essential behavior of
the tests remains unchanged.
I've also run a variety of manual tests looking at the legacy console
APIs as well as the various VT color sequences, and checking that
everything works as expected when color schemes are changed, both in
Windows Terminal and conhost, and in the latter case with both indexed
colors and RGB values.
Closes #11768
2021-11-23 19:28:55 +01:00
|
|
|
virtual COLORREF GetColorTableEntry(const size_t tableIndex) const noexcept = 0;
|
|
|
|
virtual bool SetColorTableEntry(const size_t tableIndex, const COLORREF color) noexcept = 0;
|
2019-05-23 19:44:27 +02:00
|
|
|
|
2020-01-03 19:44:27 +01:00
|
|
|
virtual bool SetCursorStyle(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::CursorStyle cursorStyle) noexcept = 0;
|
2019-10-11 23:02:09 +02:00
|
|
|
|
2021-10-26 23:12:22 +02:00
|
|
|
virtual bool SetInputMode(const ::Microsoft::Console::VirtualTerminal::TerminalInput::Mode mode, const bool enabled) noexcept = 0;
|
|
|
|
|
2020-07-09 13:25:30 +02:00
|
|
|
virtual bool SetScreenMode(const bool reverseMode) noexcept = 0;
|
2021-01-22 06:11:11 +01:00
|
|
|
virtual bool EnableXtermBracketedPasteMode(const bool enabled) noexcept = 0;
|
|
|
|
virtual bool IsXtermBracketedPasteModeEnabled() const = 0;
|
2020-03-13 01:44:28 +01:00
|
|
|
|
|
|
|
virtual bool IsVtInputEnabled() const = 0;
|
|
|
|
|
2020-06-30 03:55:40 +02:00
|
|
|
virtual bool CopyToClipboard(std::wstring_view content) noexcept = 0;
|
|
|
|
|
2020-09-03 19:52:39 +02:00
|
|
|
virtual bool AddHyperlink(std::wstring_view uri, std::wstring_view params) noexcept = 0;
|
|
|
|
virtual bool EndHyperlink() noexcept = 0;
|
|
|
|
|
2021-05-05 20:12:55 +02:00
|
|
|
virtual bool SetTaskbarProgress(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::TaskbarState state, const size_t progress) noexcept = 0;
|
2020-11-18 23:24:11 +01:00
|
|
|
|
2021-01-11 19:01:38 +01:00
|
|
|
virtual bool SetWorkingDirectory(std::wstring_view uri) noexcept = 0;
|
|
|
|
virtual std::wstring_view GetWorkingDirectory() noexcept = 0;
|
|
|
|
|
2021-02-18 03:31:52 +01:00
|
|
|
virtual bool PushGraphicsRendition(const ::Microsoft::Console::VirtualTerminal::VTParameters options) noexcept = 0;
|
|
|
|
virtual bool PopGraphicsRendition() noexcept = 0;
|
|
|
|
|
2019-10-11 23:02:09 +02:00
|
|
|
protected:
|
|
|
|
ITerminalApi() = default;
|
2019-05-03 00:29:04 +02:00
|
|
|
};
|
|
|
|
}
|