Skip to content

Use VT for COOKED_READ_DATA #17445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
bbbe20f
Move colorbrewer into its own proper header
lhecker Jun 19, 2024
b0cc432
Use VT for COOKED_READ_DATA
lhecker Jun 19, 2024
e08ebbe
Fix GetVirtualViewport, Fix popup alignment
lhecker Jun 20, 2024
88ef5f4
Address feedback
lhecker Jun 20, 2024
413991e
Address feedback, Fix scrolling bug
lhecker Jun 21, 2024
8688a50
Merge remote-tracking branch 'origin/main' into dev/lhecker/14000-vt-…
lhecker Jun 21, 2024
32a1249
Fix several issues with control character visualizers
lhecker Jun 25, 2024
4471e98
Fix ambiguous chars, Improve F7+F9 UX
lhecker Jun 25, 2024
0e63bd0
Merge remote-tracking branch 'origin/main' into dev/lhecker/14000-vt-…
lhecker Jun 25, 2024
8f39b49
Overkill initialData impl, but hopefully not kill
lhecker Jun 25, 2024
b6e4046
Fix break not breaking, Fix column not columning
lhecker Jun 25, 2024
671f371
C++ cast
lhecker Jun 25, 2024
e5b8f5b
Fix cursor position after reflow
lhecker Jul 1, 2024
567260e
Fix prompt boundaries after wrapping
lhecker Jul 1, 2024
4cda975
Fix _viewport size after shrinking
lhecker Jul 1, 2024
398d795
More robust bodgy reflow hacks
lhecker Jul 2, 2024
2fe302c
Merge remote-tracking branch 'origin/main' into dev/lhecker/14000-vt-…
lhecker Jul 9, 2024
a63b806
Address feedback, Add comments, Update formatAttributes
lhecker Jul 9, 2024
8116d5b
Address j4james' feedback from the other PR
lhecker Jul 9, 2024
1f5dc90
Fix buffer invalidation
lhecker Jul 9, 2024
8c7cf58
Oh, right, we support graphemes
lhecker Jul 9, 2024
b3f11d5
Fix formatAttributes
lhecker Jul 9, 2024
08f3bac
Forgot to finish this
lhecker Jul 9, 2024
dc8ac1d
Improve comments, resize_and_overwrite is terrible
lhecker Jul 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,27 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```

## ColorBrewer
**Source**: [https://colorbrewer2.org/](https://colorbrewer2.org/)

### License

```
Apache-Style Software License for ColorBrewer software and ColorBrewer Color Schemes

Copyright (c) 2002 Cynthia Brewer, Mark Harrower, and The Pennsylvania State University.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
```

# Microsoft Open Source

This product also incorporates source code from other Microsoft open source projects, all licensed under the MIT license.
Expand Down
13 changes: 0 additions & 13 deletions src/buffer/out/cursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Cursor::Cursor(const ULONG ulSize, TextBuffer& parentBuffer) noexcept :
_fBlinkingAllowed(true),
_fDelay(false),
_fIsConversionArea(false),
_fIsPopupShown(false),
_fDelayedEolWrap(false),
_fDeferCursorRedraw(false),
_fHaveDeferredCursorRedraw(false),
Expand Down Expand Up @@ -66,11 +65,6 @@ bool Cursor::IsConversionArea() const noexcept
return _fIsConversionArea;
}

bool Cursor::IsPopupShown() const noexcept
{
return _fIsPopupShown;
}

bool Cursor::GetDelay() const noexcept
{
return _fDelay;
Expand Down Expand Up @@ -126,13 +120,6 @@ void Cursor::SetIsConversionArea(const bool fIsConversionArea) noexcept
_RedrawCursorAlways();
}

void Cursor::SetIsPopupShown(const bool fIsPopupShown) noexcept
{
// Functionally the same as "Hide cursor"
_fIsPopupShown = fIsPopupShown;
_RedrawCursorAlways();
}

void Cursor::SetDelay(const bool fDelay) noexcept
{
_fDelay = fDelay;
Expand Down
3 changes: 0 additions & 3 deletions src/buffer/out/cursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class Cursor final
bool IsBlinkingAllowed() const noexcept;
bool IsDouble() const noexcept;
bool IsConversionArea() const noexcept;
bool IsPopupShown() const noexcept;
bool GetDelay() const noexcept;
ULONG GetSize() const noexcept;
til::point GetPosition() const noexcept;
Expand All @@ -61,7 +60,6 @@ class Cursor final
void SetBlinkingAllowed(const bool fIsOn) noexcept;
void SetIsDouble(const bool fIsDouble) noexcept;
void SetIsConversionArea(const bool fIsConversionArea) noexcept;
void SetIsPopupShown(const bool fIsPopupShown) noexcept;
void SetDelay(const bool fDelay) noexcept;
void SetSize(const ULONG ulSize) noexcept;
void SetStyle(const ULONG ulSize, const CursorType type) noexcept;
Expand Down Expand Up @@ -99,7 +97,6 @@ class Cursor final
bool _fBlinkingAllowed; //Whether or not the cursor is allowed to blink at all. only set through VT (^[[?12h/l)
bool _fDelay; // don't blink scursor on next timer message
bool _fIsConversionArea; // is attached to a conversion area so it doesn't actually need to display the cursor.
bool _fIsPopupShown; // if a popup is being shown, turn off, stop blinking.

bool _fDelayedEolWrap; // don't wrap at EOL till the next char comes in.
til::point _coordDelayedAt; // coordinate the EOL wrap was delayed at.
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalCore/terminalrenderdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ til::point Terminal::GetCursorPosition() const noexcept
bool Terminal::IsCursorVisible() const noexcept
{
const auto& cursor = _activeBuffer().GetCursor();
return cursor.IsVisible() && !cursor.IsPopupShown();
return cursor.IsVisible();
}

bool Terminal::IsCursorOn() const noexcept
Expand Down
42 changes: 42 additions & 0 deletions src/host/VtIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,3 +497,45 @@ bool VtIo::IsResizeQuirkEnabled() const
}
return S_OK;
}

static size_t formatAttributes(char (&buffer)[16], WORD attributes) noexcept
{
const uint8_t rv = WI_IsFlagSet(attributes, COMMON_LVB_REVERSE_VIDEO) ? 7 : 27;
uint8_t fg = 39;
uint8_t bg = 49;

// `attributes` of exactly `FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED`
// are often used to indicate the default colors in Windows Console applications.
// Thus, we translate them to 39/49 (default foreground/background).
if ((attributes & (FG_ATTRS | BG_ATTRS)) != (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED))
{
// The Console API represents colors in BGR order, but VT represents them in RGB order.
// This LUT transposes them. This is for foreground colors. Add +10 to get the background ones.
static const uint8_t lut[] = { 30, 34, 32, 36, 31, 35, 33, 37, 90, 94, 92, 96, 91, 95, 93, 97 };
fg = lut[attributes & 0xf];
bg = lut[(attributes >> 4) & 0xf] + 10;
}

return fmt::format_to(&buffer[0], FMT_COMPILE("\x1b[{};{};{}m"), rv, fg, bg) - &buffer[0];
}

void VtIo::FormatAttributes(std::string& target, WORD attributes)
{
char buf[16];
const auto len = formatAttributes(buf, attributes);
target.append(buf, len);
}

void VtIo::FormatAttributes(std::wstring& target, WORD attributes)
{
char buf[16];
const auto len = formatAttributes(buf, attributes);

wchar_t bufW[16];
for (size_t i = 0; i < len; i++)
{
bufW[i] = buf[i];
}

target.append(bufW, len);
}
3 changes: 3 additions & 0 deletions src/host/VtIo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ namespace Microsoft::Console::VirtualTerminal
class VtIo
{
public:
static void FormatAttributes(std::string& target, WORD attributes);
static void FormatAttributes(std::wstring& target, WORD attributes);

VtIo();

[[nodiscard]] HRESULT Initialize(const ConsoleArguments* const pArgs);
Expand Down
5 changes: 5 additions & 0 deletions src/host/_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ void WriteCharsLegacy(SCREEN_INFORMATION& screenInfo, const std::wstring_view& t
}
}

void WriteCharsVT(SCREEN_INFORMATION& screenInfo, const std::wstring_view& str)
{
screenInfo.GetStateMachine().ProcessString(str);
}

// Routine Description:
// - Takes the given text and inserts it into the given screen buffer.
// Note:
Expand Down
1 change: 1 addition & 0 deletions src/host/_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Revision History:
#include "writeData.hpp"

void WriteCharsLegacy(SCREEN_INFORMATION& screenInfo, const std::wstring_view& str, til::CoordType* psScrollY);
void WriteCharsVT(SCREEN_INFORMATION& screenInfo, const std::wstring_view& str);

// NOTE: console lock must be held when calling this routine
// String has been translated to unicode at this point.
Expand Down
Loading
Loading