Skip to content
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

WIP: Expose current TextAttributes from the underlying console API. #2032

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion src/host/getset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1651,7 +1651,7 @@ void DoSrvSetCursorColor(SCREEN_INFORMATION& screenInfo,
// - pwAttributes - Pointer to space that will receive color attributes data
// Return Value:
// - STATUS_SUCCESS if we succeeded or STATUS_INVALID_PARAMETER for bad params (nullptr).
[[nodiscard]] NTSTATUS DoSrvPrivateGetConsoleScreenBufferAttributes(_In_ const SCREEN_INFORMATION& screenInfo, _Out_ WORD* const pwAttributes)
[[nodiscard]] NTSTATUS DoSrvPrivateGetConsoleScreenBufferLegacyAttributes(_In_ const SCREEN_INFORMATION& screenInfo, _Out_ WORD* const pwAttributes)
{
NTSTATUS Status = STATUS_SUCCESS;

Expand All @@ -1668,6 +1668,12 @@ void DoSrvSetCursorColor(SCREEN_INFORMATION& screenInfo,
return Status;
}

void DoSrvPrivateGetConsoleScreenBufferAttributes(_In_ const SCREEN_INFORMATION& screenInfo, TextAttribute& attributes)
{
attributes = screenInfo.GetActiveBuffer().GetAttributes();
}


// Routine Description:
// - A private API call for forcing the renderer to repaint the screen. If the
// input screen buffer is not the active one, then just do nothing. We only
Expand Down
6 changes: 4 additions & 2 deletions src/host/getset.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Revision History:

#pragma once
#include "../inc/conattrs.hpp"
#include "../buffer/out/TextAttribute.hpp"
class SCREEN_INFORMATION;

void DoSrvPrivateSetLegacyAttributes(SCREEN_INFORMATION& screenInfo,
Expand Down Expand Up @@ -67,8 +68,9 @@ void DoSrvSetCursorStyle(SCREEN_INFORMATION& screenInfo,
void DoSrvSetCursorColor(SCREEN_INFORMATION& screenInfo,
const COLORREF cursorColor);

[[nodiscard]] NTSTATUS DoSrvPrivateGetConsoleScreenBufferAttributes(const SCREEN_INFORMATION& screenInfo,
_Out_ WORD* const pwAttributes);
[[nodiscard]] NTSTATUS DoSrvPrivateGetConsoleScreenBufferLegacyAttributes(const SCREEN_INFORMATION& screenInfo,
_Out_ WORD* const pwAttributes);
void DoSrvPrivateGetConsoleScreenBufferAttributes(_In_ const SCREEN_INFORMATION& screenInfo, TextAttribute& attributes);

void DoSrvPrivateRefreshWindow(const SCREEN_INFORMATION& screenInfo);

Expand Down
16 changes: 14 additions & 2 deletions src/host/outputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,9 +629,21 @@ BOOL ConhostInternalGetSet::SetCursorStyle(const CursorType cursorType)
// - pwAttributes - Pointer to space to receive color attributes data
// Return Value:
// - TRUE if successful. FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateGetConsoleScreenBufferAttributes(_Out_ WORD* const pwAttributes)
BOOL ConhostInternalGetSet::PrivateGetConsoleScreenBufferLegacyAttributes(_Out_ WORD* const pwAttributes)
{
return NT_SUCCESS(DoSrvPrivateGetConsoleScreenBufferAttributes(_io.GetActiveOutputBuffer(), pwAttributes));
return NT_SUCCESS(DoSrvPrivateGetConsoleScreenBufferLegacyAttributes(_io.GetActiveOutputBuffer(), pwAttributes));
}

// Routine Description:
// - Retrieves the default color attributes information for the active screen buffer.
// - This function is used to optimize SGR calls in lieu of calling GetConsoleScreenBufferInfoEx.
// Arguments:
// - pAttributes - Pointer to space to receive color attributes data
// Return Value:
// - TRUE if successful. FALSE otherwise.
void ConhostInternalGetSet::PrivateGetConsoleScreenBufferAttributes(_Out_ TextAttribute& attributes)
{
DoSrvPrivateGetConsoleScreenBufferAttributes(_io.GetActiveOutputBuffer(), attributes);
}

// Routine Description:
Expand Down
3 changes: 2 additions & 1 deletion src/host/outputStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ class ConhostInternalGetSet final : public Microsoft::Console::VirtualTerminal::
BOOL PrivateEnableAlternateScroll(const bool fEnabled) override;
BOOL PrivateEraseAll() override;

BOOL PrivateGetConsoleScreenBufferAttributes(_Out_ WORD* const pwAttributes) override;
BOOL PrivateGetConsoleScreenBufferLegacyAttributes(_Out_ WORD* const pwAttributes) override;
void PrivateGetConsoleScreenBufferAttributes(_Out_ TextAttribute& attributes) override;

BOOL PrivatePrependConsoleInput(_Inout_ std::deque<std::unique_ptr<IInputEvent>>& events,
_Out_ size_t& eventsWritten) override;
Expand Down
2 changes: 1 addition & 1 deletion src/terminal/adapter/adaptDispatchGraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ bool AdaptDispatch::SetGraphicsRendition(_In_reads_(cOptions) const DispatchType
// because it has to fill the Largest Window Size by asking the OS and wastes time memcpying colors and other data
// we do not need to resolve this Set Graphics Rendition request.
WORD attr;
bool fSuccess = !!_conApi->PrivateGetConsoleScreenBufferAttributes(&attr);
bool fSuccess = !!_conApi->PrivateGetConsoleScreenBufferLegacyAttributes(&attr);

if (fSuccess)
{
Expand Down
4 changes: 3 additions & 1 deletion src/terminal/adapter/conGetSet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Author(s):

#include "..\..\types\inc\IInputEvent.hpp"
#include "..\..\inc\conattrs.hpp"
#include "..\..\buffer\out\TextAttribute.hpp"

#include <deque>
#include <memory>
Expand Down Expand Up @@ -87,7 +88,8 @@ namespace Microsoft::Console::VirtualTerminal
virtual BOOL PrivateEraseAll() = 0;
virtual BOOL SetCursorStyle(const CursorType cursorType) = 0;
virtual BOOL SetCursorColor(const COLORREF cursorColor) = 0;
virtual BOOL PrivateGetConsoleScreenBufferAttributes(_Out_ WORD* const pwAttributes) = 0;
virtual BOOL PrivateGetConsoleScreenBufferLegacyAttributes(_Out_ WORD* const pwAttributes) = 0;
virtual void PrivateGetConsoleScreenBufferAttributes(_Out_ TextAttribute& attributes) = 0;
zadjii-msft marked this conversation as resolved.
Show resolved Hide resolved
virtual BOOL PrivatePrependConsoleInput(_Inout_ std::deque<std::unique_ptr<IInputEvent>>& events,
_Out_ size_t& eventsWritten) = 0;
virtual BOOL PrivateWriteConsoleControlInput(_In_ KeyEvent key) = 0;
Expand Down
22 changes: 15 additions & 7 deletions src/terminal/adapter/ut_adapter/adapterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,16 +689,24 @@ class TestGetSet final : public ConGetSet
return _fSetCursorColorResult;
}

BOOL PrivateGetConsoleScreenBufferAttributes(_Out_ WORD* const pwAttributes) override
BOOL PrivateGetConsoleScreenBufferLegacyAttributes(_Out_ WORD* const pwAttributes) override
{
Log::Comment(L"PrivateGetConsoleScreenBufferAttributes MOCK returning data...");
Log::Comment(L"PrivateGetConsoleScreenBufferLegacyAttributes MOCK returning data...");

if (pwAttributes != nullptr && _fPrivateGetConsoleScreenBufferAttributesResult)
if (pwAttributes != nullptr && _fPrivateGetConsoleScreenBufferLegacyAttributesResult)
{
*pwAttributes = _wAttribute;
}

return _fPrivateGetConsoleScreenBufferAttributesResult;
return _fPrivateGetConsoleScreenBufferLegacyAttributesResult;
}

void PrivateGetConsoleScreenBufferAttributes(_Out_ TextAttribute& attributes) override
{
Log::Comment(L"PrivateGetConsoleScreenBufferAttributes MOCK returning data...");

// TODO
attributes = TextAttribute();
}

BOOL PrivateRefreshWindow() override
Expand Down Expand Up @@ -871,7 +879,7 @@ class TestGetSet final : public ConGetSet
_fPrivateWriteConsoleControlInputResult = TRUE;
_fScrollConsoleScreenBufferWResult = TRUE;
_fSetConsoleWindowInfoResult = TRUE;
_fPrivateGetConsoleScreenBufferAttributesResult = TRUE;
_fPrivateGetConsoleScreenBufferLegacyAttributesResult = TRUE;
_fMoveToBottomResult = true;

_PrepCharsBuffer(wch, wAttr);
Expand Down Expand Up @@ -1394,7 +1402,7 @@ class TestGetSet final : public ConGetSet
BOOL _fSetConsoleXtermTextAttributeResult = false;
BOOL _fSetConsoleRGBTextAttributeResult = false;
BOOL _fPrivateSetLegacyAttributesResult = false;
BOOL _fPrivateGetConsoleScreenBufferAttributesResult = false;
BOOL _fPrivateGetConsoleScreenBufferLegacyAttributesResult = false;
BOOL _fSetCursorStyleResult = false;
CursorType _ExpectedCursorStyle;
BOOL _fSetCursorColorResult = false;
Expand Down Expand Up @@ -2505,7 +2513,7 @@ class AdapterTest
Log::Comment(L"Test 2: Gracefully fail when getting buffer information fails.");

_testGetSet->PrepData();
_testGetSet->_fPrivateGetConsoleScreenBufferAttributesResult = FALSE;
_testGetSet->_fPrivateGetConsoleScreenBufferLegacyAttributesResult = FALSE;

VERIFY_IS_FALSE(_pDispatch->SetGraphicsRendition(rgOptions, cOptions));

Expand Down