Skip to content

Commit

Permalink
Add a SetStandardErase method to the TextAttribute class to simplify …
Browse files Browse the repository at this point in the history
…the operations that need that attribute state.
  • Loading branch information
j4james committed Dec 10, 2019
1 parent 3099d1a commit 786cc36
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 26 deletions.
9 changes: 9 additions & 0 deletions src/buffer/out/TextAttribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,12 @@ bool TextAttribute::BackgroundIsDefault() const noexcept
{
return _background.IsDefault();
}

// Routine Description:
// - Resets the meta and extended attributes, which is what the VT standard
// requires for most erasing and filling operations.
void TextAttribute::SetStandardErase() noexcept
{
SetExtendedAttributes(ExtendedAttributes::Normal);
SetMetaAttributes(0);
}
2 changes: 2 additions & 0 deletions src/buffer/out/TextAttribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ class TextAttribute final
bool ForegroundIsDefault() const noexcept;
bool BackgroundIsDefault() const noexcept;

void SetStandardErase() noexcept;

constexpr bool IsRgb() const noexcept
{
return _foreground.IsRgb() || _background.IsRgb();
Expand Down
3 changes: 1 addition & 2 deletions src/buffer/out/textBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,7 @@ bool TextBuffer::IncrementCircularBuffer(const bool inVtMode)
{
// The VT standard requires that the new row is initialized with
// the current background color, but with no meta attributes set.
fillAttributes.SetExtendedAttributes(ExtendedAttributes::Normal);
fillAttributes.SetMetaAttributes(0);
fillAttributes.SetStandardErase();
}
const bool fSuccess = _storage.at(_firstRow).Reset(fillAttributes);
if (fSuccess)
Expand Down
3 changes: 1 addition & 2 deletions src/host/_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ using Microsoft::Console::VirtualTerminal::StateMachine;
// The VT standard requires the lines revealed when scrolling are filled
// with the current background color, but with no meta attributes set.
auto fillAttributes = screenInfo.GetAttributes();
fillAttributes.SetExtendedAttributes(ExtendedAttributes::Normal);
fillAttributes.SetMetaAttributes(0);
fillAttributes.SetStandardErase();

const auto relativeMargins = screenInfo.GetRelativeScrollMargins();
auto viewport = screenInfo.GetViewport();
Expand Down
6 changes: 2 additions & 4 deletions src/host/getset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2275,8 +2275,7 @@ void DoSrvPrivateMoveToBottom(SCREEN_INFORMATION& screenInfo)
if (standardFillAttrs)
{
fillAttrs = screenInfo.GetAttributes();
fillAttrs.SetExtendedAttributes(ExtendedAttributes::Normal);
fillAttrs.SetMetaAttributes(0);
fillAttrs.SetStandardErase();
}

const auto fillData = OutputCellIterator{ fillChar, fillAttrs, fillLength };
Expand Down Expand Up @@ -2323,8 +2322,7 @@ void DoSrvPrivateMoveToBottom(SCREEN_INFORMATION& screenInfo)
if (standardFillAttrs)
{
fillAttrs = screenInfo.GetAttributes();
fillAttrs.SetExtendedAttributes(ExtendedAttributes::Normal);
fillAttrs.SetMetaAttributes(0);
fillAttrs.SetStandardErase();
}

ScrollRegion(screenInfo,
Expand Down
9 changes: 3 additions & 6 deletions src/host/screenInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2038,8 +2038,7 @@ const SCREEN_INFORMATION& SCREEN_INFORMATION::GetMainBuffer() const
// The buffer needs to be initialized with the standard erase attributes,
// i.e. the current background color, but with no meta attributes set.
auto initAttributes = GetAttributes();
initAttributes.SetExtendedAttributes(ExtendedAttributes::Normal);
initAttributes.SetMetaAttributes(0);
initAttributes.SetStandardErase();

NTSTATUS Status = SCREEN_INFORMATION::CreateInstance(WindowSize,
existingFont,
Expand Down Expand Up @@ -2510,8 +2509,7 @@ void SCREEN_INFORMATION::SetViewport(const Viewport& newViewport,
// Update all the rows in the current viewport with the standard erase attributes,
// i.e. the current background color, but with no meta attributes set.
auto fillAttributes = GetAttributes();
fillAttributes.SetExtendedAttributes(ExtendedAttributes::Normal);
fillAttributes.SetMetaAttributes(0);
fillAttributes.SetStandardErase();
auto fillPosition = COORD{ 0, _viewport.Top() };
auto fillLength = gsl::narrow_cast<size_t>(_viewport.Height() * GetBufferSize().Width());
auto fillData = OutputCellIterator{ fillAttributes, fillLength };
Expand Down Expand Up @@ -2833,8 +2831,7 @@ void SCREEN_INFORMATION::InitializeCursorRowAttributes()
// The VT standard requires that the new row is initialized with
// the current background color, but with no meta attributes set.
auto fillAttributes = GetAttributes();
fillAttributes.SetExtendedAttributes(ExtendedAttributes::Normal);
fillAttributes.SetMetaAttributes(0);
fillAttributes.SetStandardErase();
row.GetAttrRow().SetAttrToEnd(0, fillAttributes);
}
}
Expand Down
18 changes: 6 additions & 12 deletions src/host/ut_host/ScreenBufferTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1345,8 +1345,7 @@ void ScreenBufferTests::VtNewlinePastViewport()
si.SetAttributes(fillAttr);
// But note that the meta attributes are expected to be cleared.
auto expectedFillAttr = fillAttr;
expectedFillAttr.SetExtendedAttributes(ExtendedAttributes::Normal);
expectedFillAttr.SetMetaAttributes(0);
expectedFillAttr.SetStandardErase();

seq = L"\n";
stateMachine.ProcessString(seq);
Expand Down Expand Up @@ -1425,8 +1424,7 @@ void ScreenBufferTests::VtNewlinePastEndOfBuffer()
si.SetAttributes(fillAttr);
// But note that the meta attributes are expected to be cleared.
auto expectedFillAttr = fillAttr;
expectedFillAttr.SetExtendedAttributes(ExtendedAttributes::Normal);
expectedFillAttr.SetMetaAttributes(0);
expectedFillAttr.SetStandardErase();

seq = L"\n";
stateMachine.ProcessString(seq);
Expand Down Expand Up @@ -3367,8 +3365,7 @@ void ScreenBufferTests::ScrollOperations()
si.SetAttributes(fillAttr);
// But note that the meta attributes are expected to be cleared.
auto expectedFillAttr = fillAttr;
expectedFillAttr.SetExtendedAttributes(ExtendedAttributes::Normal);
expectedFillAttr.SetMetaAttributes(0);
expectedFillAttr.SetStandardErase();

// Place the cursor in the center.
auto cursorPos = COORD{ bufferWidth / 2, (viewportStart + viewportEnd) / 2 };
Expand Down Expand Up @@ -3488,8 +3485,7 @@ void ScreenBufferTests::InsertChars()
si.SetAttributes(fillAttr);
// But note that the meta attributes are expected to be cleared.
auto expectedFillAttr = fillAttr;
expectedFillAttr.SetExtendedAttributes(ExtendedAttributes::Normal);
expectedFillAttr.SetMetaAttributes(0);
expectedFillAttr.SetStandardErase();

// Insert 5 spaces at the cursor position.
// Before: QQQQQQQQQQABCDEFGHIJKLMNOPQRSTQQQQQQQQQQ
Expand Down Expand Up @@ -3648,8 +3644,7 @@ void ScreenBufferTests::DeleteChars()
si.SetAttributes(fillAttr);
// But note that the meta attributes are expected to be cleared.
auto expectedFillAttr = fillAttr;
expectedFillAttr.SetExtendedAttributes(ExtendedAttributes::Normal);
expectedFillAttr.SetMetaAttributes(0);
expectedFillAttr.SetStandardErase();

// Delete 5 characters at the cursor position.
// Before: QQQQQQQQQQABCDEFGHIJKLMNOPQRSTQQQQQQQQQQ
Expand Down Expand Up @@ -3880,8 +3875,7 @@ void ScreenBufferTests::EraseTests()
si.SetAttributes(fillAttr);
// But note that the meta attributes are expected to be cleared.
auto expectedFillAttr = fillAttr;
expectedFillAttr.SetExtendedAttributes(ExtendedAttributes::Normal);
expectedFillAttr.SetMetaAttributes(0);
expectedFillAttr.SetStandardErase();

// Place the cursor in the center.
const short centerX = bufferWidth / 2;
Expand Down

0 comments on commit 786cc36

Please sign in to comment.