Make the terminal parser/adapter and related classes use modern… (#3956)

## Summary of the Pull Request
Refactors parsing/adapting libraries and consumers to use safer and/or more consistent mechanisms for passing information.

## PR Checklist
* [x] I work here
* [x] Tests still pass
* [x] Am a core contributor.

## Detailed Description of the Pull Request / Additional comments
This is in support of hopefully turning audit mode on to more projects. If I turned it on, it would immediately complain about certain classes of issues like pointer and size, pointer math, etc. The changes in this refactoring will eliminate those off the top.

Additionally, this has caught a bunch of comments all over the VT classes that weren't updated to match the parameters lists.

Additionally, this has caught a handful of member variables on classes that were completely unused (and now gone).

Additionally, I'm killing almost all hungarian and shortening variable names. I'm only really leaving 'p' for pointers.

Additionally, this is vaguely in support of a future where we can have "infinite scrollback" in that I'm moving things to size_t across the board. I know it's a bit of a memory cost, but all the casting and moving between types is error prone and unfun to save a couple bytes.

## Validation Steps Performed
- [x] build it
- [x] run all the tests
- [x] everyone looked real hard at it
This commit is contained in:
Michael Niksa 2019-12-19 14:12:53 -08:00 committed by GitHub
parent 2e26c3e0c9
commit 6f667f48ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
52 changed files with 4087 additions and 4450 deletions

View file

@ -15,7 +15,7 @@ namespace Microsoft::Terminal::Core
ITerminalApi& operator=(const ITerminalApi&) = default;
ITerminalApi& operator=(ITerminalApi&&) = default;
virtual bool PrintString(std::wstring_view stringView) = 0;
virtual bool PrintString(std::wstring_view string) = 0;
virtual bool ExecuteChar(wchar_t wch) = 0;
virtual bool SetTextToDefaults(bool foreground, bool background) = 0;
@ -29,20 +29,20 @@ namespace Microsoft::Terminal::Core
virtual bool SetCursorPosition(short x, short y) = 0;
virtual COORD GetCursorPosition() = 0;
virtual bool DeleteCharacter(const unsigned int uiCount) = 0;
virtual bool InsertCharacter(const unsigned int uiCount) = 0;
virtual bool EraseCharacters(const unsigned int numChars) = 0;
virtual bool DeleteCharacter(const size_t count) = 0;
virtual bool InsertCharacter(const size_t count) = 0;
virtual bool EraseCharacters(const size_t numChars) = 0;
virtual bool EraseInLine(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::EraseType eraseType) = 0;
virtual bool EraseInDisplay(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::EraseType eraseType) = 0;
virtual bool SetWindowTitle(std::wstring_view title) = 0;
virtual bool SetColorTableEntry(const size_t tableIndex, const DWORD dwColor) = 0;
virtual bool SetColorTableEntry(const size_t tableIndex, const DWORD color) = 0;
virtual bool SetCursorStyle(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::CursorStyle cursorStyle) = 0;
virtual bool SetDefaultForeground(const DWORD dwColor) = 0;
virtual bool SetDefaultBackground(const DWORD dwColor) = 0;
virtual bool SetDefaultForeground(const DWORD color) = 0;
virtual bool SetDefaultBackground(const DWORD color) = 0;
protected:
ITerminalApi() = default;

View file

@ -50,7 +50,10 @@ Terminal::Terminal() :
_selectionAnchor{ 0, 0 },
_endSelectionPosition{ 0, 0 }
{
_stateMachine = std::make_unique<StateMachine>(new OutputStateMachineEngine(new TerminalDispatch(*this)));
auto dispatch = std::make_unique<TerminalDispatch>(*this);
auto engine = std::make_unique<OutputStateMachineEngine>(std::move(dispatch));
_stateMachine = std::make_unique<StateMachine>(std::move(engine));
auto passAlongInput = [&](std::deque<std::unique_ptr<IInputEvent>>& inEventsToWrite) {
if (!_pfnWriteInput)
@ -199,7 +202,7 @@ void Terminal::Write(std::wstring_view stringView)
{
auto lock = LockForWriting();
_stateMachine->ProcessString(stringView.data(), stringView.size());
_stateMachine->ProcessString(stringView);
}
// Method Description:

View file

@ -75,16 +75,16 @@ public:
bool ReverseText(bool reversed) override;
bool SetCursorPosition(short x, short y) override;
COORD GetCursorPosition() override;
bool DeleteCharacter(const unsigned int uiCount) override;
bool InsertCharacter(const unsigned int uiCount) override;
bool EraseCharacters(const unsigned int numChars) override;
bool DeleteCharacter(const size_t count) override;
bool InsertCharacter(const size_t count) override;
bool EraseCharacters(const size_t numChars) override;
bool EraseInLine(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::EraseType eraseType) override;
bool EraseInDisplay(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::EraseType eraseType) override;
bool SetWindowTitle(std::wstring_view title) override;
bool SetColorTableEntry(const size_t tableIndex, const COLORREF dwColor) override;
bool SetColorTableEntry(const size_t tableIndex, const COLORREF color) override;
bool SetCursorStyle(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::CursorStyle cursorStyle) override;
bool SetDefaultForeground(const COLORREF dwColor) override;
bool SetDefaultBackground(const COLORREF dwColor) override;
bool SetDefaultForeground(const COLORREF color) override;
bool SetDefaultBackground(const COLORREF color) override;
#pragma endregion
#pragma region ITerminalInput

View file

@ -128,19 +128,19 @@ COORD Terminal::GetCursorPosition()
}
// Method Description:
// - deletes uiCount characters starting from the cursor's current position
// - deletes count characters starting from the cursor's current position
// - it moves over the remaining text to 'replace' the deleted text
// - for example, if the buffer looks like this ('|' is the cursor): [abc|def]
// - calling DeleteCharacter(1) will change it to: [abc|ef],
// - i.e. the 'd' gets deleted and the 'ef' gets shifted over 1 space and **retain their previous text attributes**
// Arguments:
// - uiCount, the number of characters to delete
// - count, the number of characters to delete
// Return value:
// - true if succeeded, false otherwise
bool Terminal::DeleteCharacter(const unsigned int uiCount)
bool Terminal::DeleteCharacter(const size_t count)
{
SHORT dist;
if (!SUCCEEDED(UIntToShort(uiCount, &dist)))
if (!SUCCEEDED(SizeTToShort(count, &dist)))
{
return false;
}
@ -175,22 +175,22 @@ bool Terminal::DeleteCharacter(const unsigned int uiCount)
}
// Method Description:
// - Inserts uiCount spaces starting from the cursor's current position, moving over the existing text
// - Inserts count spaces starting from the cursor's current position, moving over the existing text
// - for example, if the buffer looks like this ('|' is the cursor): [abc|def]
// - calling InsertCharacter(1) will change it to: [abc| def],
// - i.e. the 'def' gets shifted over 1 space and **retain their previous text attributes**
// Arguments:
// - uiCount, the number of spaces to insert
// - count, the number of spaces to insert
// Return value:
// - true if succeeded, false otherwise
bool Terminal::InsertCharacter(const unsigned int uiCount)
bool Terminal::InsertCharacter(const size_t count)
{
// NOTE: the code below is _extremely_ similar to DeleteCharacter
// We will want to use this same logic and implement a helper function instead
// that does the 'move a region from here to there' operation
// TODO: Github issue #2163
SHORT dist;
if (!SUCCEEDED(UIntToShort(uiCount, &dist)))
if (!SUCCEEDED(SizeTToShort(count, &dist)))
{
return false;
}
@ -227,7 +227,7 @@ bool Terminal::InsertCharacter(const unsigned int uiCount)
return true;
}
bool Terminal::EraseCharacters(const unsigned int numChars)
bool Terminal::EraseCharacters(const size_t numChars)
{
const auto absoluteCursorPos = _buffer->GetCursor().GetPosition();
const auto viewport = _GetMutableViewport();
@ -374,17 +374,17 @@ bool Terminal::SetWindowTitle(std::wstring_view title)
// Method Description:
// - Updates the value in the colortable at index tableIndex to the new color
// dwColor. dwColor is a COLORREF, format 0x00BBGGRR.
// color. color is a COLORREF, format 0x00BBGGRR.
// Arguments:
// - tableIndex: the index of the color table to update.
// - dwColor: the new COLORREF to use as that color table value.
// - color: the new COLORREF to use as that color table value.
// Return Value:
// - true iff we successfully updated the color table entry.
bool Terminal::SetColorTableEntry(const size_t tableIndex, const COLORREF dwColor)
bool Terminal::SetColorTableEntry(const size_t tableIndex, const COLORREF color)
{
try
{
_colorTable.at(tableIndex) = dwColor;
_colorTable.at(tableIndex) = color;
// Repaint everything - the colors might have changed
_buffer->GetRenderTarget().TriggerRedrawAll();
@ -449,12 +449,12 @@ bool Terminal::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle)
// Method Description:
// - Updates the default foreground color from a COLORREF, format 0x00BBGGRR.
// Arguments:
// - dwColor: the new COLORREF to use as the default foreground color
// - color: the new COLORREF to use as the default foreground color
// Return Value:
// - true
bool Terminal::SetDefaultForeground(const COLORREF dwColor)
bool Terminal::SetDefaultForeground(const COLORREF color)
{
_defaultFg = dwColor;
_defaultFg = color;
// Repaint everything - the colors might have changed
_buffer->GetRenderTarget().TriggerRedrawAll();
@ -464,13 +464,13 @@ bool Terminal::SetDefaultForeground(const COLORREF dwColor)
// Method Description:
// - Updates the default background color from a COLORREF, format 0x00BBGGRR.
// Arguments:
// - dwColor: the new COLORREF to use as the default background color
// - color: the new COLORREF to use as the default background color
// Return Value:
// - true
bool Terminal::SetDefaultBackground(const COLORREF dwColor)
bool Terminal::SetDefaultBackground(const COLORREF color)
{
_defaultBg = dwColor;
_pfnBackgroundColorChanged(dwColor);
_defaultBg = color;
_pfnBackgroundColorChanged(color);
// Repaint everything - the colors might have changed
_buffer->GetRenderTarget().TriggerRedrawAll();

View file

@ -25,45 +25,45 @@ void TerminalDispatch::Print(const wchar_t wchPrintable)
_terminalApi.PrintString({ &wchPrintable, 1 });
}
void TerminalDispatch::PrintString(const wchar_t* const rgwch, const size_t cch)
void TerminalDispatch::PrintString(const std::wstring_view string)
{
_terminalApi.PrintString({ rgwch, cch });
_terminalApi.PrintString(string);
}
bool TerminalDispatch::CursorPosition(const unsigned int uiLine,
const unsigned int uiColumn)
bool TerminalDispatch::CursorPosition(const size_t line,
const size_t column)
{
const auto columnInBufferSpace = uiColumn - 1;
const auto lineInBufferSpace = uiLine - 1;
short x = static_cast<short>(uiColumn - 1);
short y = static_cast<short>(uiLine - 1);
const auto columnInBufferSpace = column - 1;
const auto lineInBufferSpace = line - 1;
short x = static_cast<short>(column - 1);
short y = static_cast<short>(line - 1);
return _terminalApi.SetCursorPosition(x, y);
}
bool TerminalDispatch::CursorForward(const unsigned int uiDistance)
bool TerminalDispatch::CursorForward(const size_t distance)
{
const auto cursorPos = _terminalApi.GetCursorPosition();
const COORD newCursorPos{ cursorPos.X + gsl::narrow<short>(uiDistance), cursorPos.Y };
const COORD newCursorPos{ cursorPos.X + gsl::narrow<short>(distance), cursorPos.Y };
return _terminalApi.SetCursorPosition(newCursorPos.X, newCursorPos.Y);
}
bool TerminalDispatch::CursorBackward(const unsigned int uiDistance)
bool TerminalDispatch::CursorBackward(const size_t distance)
{
const auto cursorPos = _terminalApi.GetCursorPosition();
const COORD newCursorPos{ cursorPos.X - gsl::narrow<short>(uiDistance), cursorPos.Y };
const COORD newCursorPos{ cursorPos.X - gsl::narrow<short>(distance), cursorPos.Y };
return _terminalApi.SetCursorPosition(newCursorPos.X, newCursorPos.Y);
}
bool TerminalDispatch::CursorUp(const unsigned int uiDistance)
bool TerminalDispatch::CursorUp(const size_t distance)
{
const auto cursorPos = _terminalApi.GetCursorPosition();
const COORD newCursorPos{ cursorPos.X, cursorPos.Y + gsl::narrow<short>(uiDistance) };
const COORD newCursorPos{ cursorPos.X, cursorPos.Y + gsl::narrow<short>(distance) };
return _terminalApi.SetCursorPosition(newCursorPos.X, newCursorPos.Y);
}
bool TerminalDispatch::EraseCharacters(const unsigned int uiNumChars)
bool TerminalDispatch::EraseCharacters(const size_t numChars)
{
return _terminalApi.EraseCharacters(uiNumChars);
return _terminalApi.EraseCharacters(numChars);
}
bool TerminalDispatch::SetWindowTitle(std::wstring_view title)
@ -75,13 +75,13 @@ bool TerminalDispatch::SetWindowTitle(std::wstring_view title)
// - Sets a single entry of the colortable to a new value
// Arguments:
// - tableIndex: The VT color table index
// - dwColor: The new RGB color value to use.
// - color: The new RGB color value to use.
// Return Value:
// True if handled successfully. False otherwise.
bool TerminalDispatch::SetColorTableEntry(const size_t tableIndex,
const DWORD dwColor)
const DWORD color)
{
return _terminalApi.SetColorTableEntry(tableIndex, dwColor);
return _terminalApi.SetColorTableEntry(tableIndex, color);
}
bool TerminalDispatch::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle)
@ -92,23 +92,23 @@ bool TerminalDispatch::SetCursorStyle(const DispatchTypes::CursorStyle cursorSty
// Method Description:
// - Sets the default foreground color to a new value
// Arguments:
// - dwColor: The new RGB color value to use, in 0x00BBGGRR form
// - color: The new RGB color value to use, in 0x00BBGGRR form
// Return Value:
// True if handled successfully. False otherwise.
bool TerminalDispatch::SetDefaultForeground(const DWORD dwColor)
bool TerminalDispatch::SetDefaultForeground(const DWORD color)
{
return _terminalApi.SetDefaultForeground(dwColor);
return _terminalApi.SetDefaultForeground(color);
}
// Method Description:
// - Sets the default background color to a new value
// Arguments:
// - dwColor: The new RGB color value to use, in 0x00BBGGRR form
// - color: The new RGB color value to use, in 0x00BBGGRR form
// Return Value:
// True if handled successfully. False otherwise.
bool TerminalDispatch::SetDefaultBackground(const DWORD dwColor)
bool TerminalDispatch::SetDefaultBackground(const DWORD color)
{
return _terminalApi.SetDefaultBackground(dwColor);
return _terminalApi.SetDefaultBackground(color);
}
// Method Description:
@ -123,25 +123,25 @@ bool TerminalDispatch::EraseInLine(const DispatchTypes::EraseType eraseType)
}
// Method Description:
// - Deletes uiCount number of characters starting from where the cursor is currently
// - Deletes count number of characters starting from where the cursor is currently
// Arguments:
// - uiCount, the number of characters to delete
// - count, the number of characters to delete
// Return Value:
// True if handled successfully. False otherwise.
bool TerminalDispatch::DeleteCharacter(const unsigned int uiCount)
bool TerminalDispatch::DeleteCharacter(const size_t count)
{
return _terminalApi.DeleteCharacter(uiCount);
return _terminalApi.DeleteCharacter(count);
}
// Method Description:
// - Adds uiCount number of spaces starting from where the cursor is currently
// - Adds count number of spaces starting from where the cursor is currently
// Arguments:
// - uiCount, the number of spaces to add
// - count, the number of spaces to add
// Return Value:
// True if handled successfully, false otherwise
bool TerminalDispatch::InsertCharacter(const unsigned int uiCount)
bool TerminalDispatch::InsertCharacter(const size_t count)
{
return _terminalApi.InsertCharacter(uiCount);
return _terminalApi.InsertCharacter(count);
}
// Method Description:

View file

@ -11,29 +11,28 @@ public:
virtual ~TerminalDispatch(){};
virtual void Execute(const wchar_t wchControl) override;
virtual void Print(const wchar_t wchPrintable) override;
virtual void PrintString(const wchar_t* const rgwch, const size_t cch) override;
virtual void PrintString(const std::wstring_view string) override;
bool SetGraphicsRendition(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::GraphicsOptions* const rgOptions,
const size_t cOptions) override;
bool SetGraphicsRendition(const std::basic_string_view<::Microsoft::Console::VirtualTerminal::DispatchTypes::GraphicsOptions> options) override;
virtual bool CursorPosition(const unsigned int uiLine,
const unsigned int uiColumn) override; // CUP
virtual bool CursorPosition(const size_t line,
const size_t column) override; // CUP
bool CursorForward(const unsigned int uiDistance) override;
bool CursorBackward(const unsigned int uiDistance) override;
bool CursorUp(const unsigned int uiDistance) override;
bool CursorForward(const size_t distance) override;
bool CursorBackward(const size_t distance) override;
bool CursorUp(const size_t distance) override;
bool EraseCharacters(const unsigned int uiNumChars) override;
bool EraseCharacters(const size_t numChars) override;
bool SetWindowTitle(std::wstring_view title) override;
bool SetColorTableEntry(const size_t tableIndex, const DWORD dwColor) override;
bool SetColorTableEntry(const size_t tableIndex, const DWORD color) override;
bool SetCursorStyle(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::CursorStyle cursorStyle) override;
bool SetDefaultForeground(const DWORD dwColor) override;
bool SetDefaultBackground(const DWORD dwColor) override;
bool SetDefaultForeground(const DWORD color) override;
bool SetDefaultBackground(const DWORD color) override;
bool EraseInLine(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::EraseType eraseType) override; // ED
bool DeleteCharacter(const unsigned int uiCount) override;
bool InsertCharacter(const unsigned int uiCount) override;
bool DeleteCharacter(const size_t count) override;
bool InsertCharacter(const size_t count) override;
bool EraseInDisplay(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::EraseType eraseType) override;
private:
@ -43,9 +42,8 @@ private:
static bool s_IsBoldColorOption(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::GraphicsOptions opt) noexcept;
static bool s_IsDefaultColorOption(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::GraphicsOptions opt) noexcept;
bool _SetRgbColorsHelper(_In_reads_(cOptions) const ::Microsoft::Console::VirtualTerminal::DispatchTypes::GraphicsOptions* const rgOptions,
const size_t cOptions,
_Out_ size_t* const pcOptionsConsumed);
bool _SetRgbColorsHelper(const std::basic_string_view<::Microsoft::Console::VirtualTerminal::DispatchTypes::GraphicsOptions> options,
size_t& optionsConsumed);
bool _SetBoldColorHelper(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::GraphicsOptions option);
bool _SetDefaultColorHelper(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::GraphicsOptions option);
void _SetGraphicsOptionHelper(const ::Microsoft::Console::VirtualTerminal::DispatchTypes::GraphicsOptions opt);

View file

@ -69,9 +69,8 @@ bool TerminalDispatch::s_IsDefaultColorOption(const DispatchTypes::GraphicsOptio
// RGB sequences then take 3 MORE params to designate the R, G, B parts of the color
// Xterm index will use the param that follows to use a color from the preset 256 color xterm color table.
// Arguments:
// - rgOptions - An array of options that will be used to generate the RGB color
// - cOptions - The count of options
// - pcOptionsConsumed - a pointer to place the number of options we consumed parsing this option.
// - options - An array of options that will be used to generate the RGB color
// - optionsConsumed - Returns the number of options we consumed parsing this option.
// Return Value:
// Returns true if we successfully parsed an extended color option from the options array.
// - This corresponds to the following number of options consumed (pcOptionsConsumed):
@ -79,20 +78,19 @@ bool TerminalDispatch::s_IsDefaultColorOption(const DispatchTypes::GraphicsOptio
// 2 - false, not enough options to parse.
// 3 - true, parsed an xterm index to a color
// 5 - true, parsed an RGB color.
bool TerminalDispatch::_SetRgbColorsHelper(_In_reads_(cOptions) const DispatchTypes::GraphicsOptions* const rgOptions,
const size_t cOptions,
_Out_ size_t* const pcOptionsConsumed)
bool TerminalDispatch::_SetRgbColorsHelper(const std::basic_string_view<DispatchTypes::GraphicsOptions> options,
size_t& optionsConsumed)
{
COLORREF color = 0;
bool isForeground = false;
bool fSuccess = false;
*pcOptionsConsumed = 1;
if (cOptions >= 2 && s_IsRgbColorOption(rgOptions[0]))
bool success = false;
optionsConsumed = 1;
if (options.size() >= 2 && s_IsRgbColorOption(options.front()))
{
*pcOptionsConsumed = 2;
DispatchTypes::GraphicsOptions extendedOpt = rgOptions[0];
DispatchTypes::GraphicsOptions typeOpt = rgOptions[1];
optionsConsumed = 2;
DispatchTypes::GraphicsOptions extendedOpt = options.at(0);
DispatchTypes::GraphicsOptions typeOpt = options.at(1);
if (extendedOpt == DispatchTypes::GraphicsOptions::ForegroundExtended)
{
@ -103,31 +101,32 @@ bool TerminalDispatch::_SetRgbColorsHelper(_In_reads_(cOptions) const DispatchTy
isForeground = false;
}
if (typeOpt == DispatchTypes::GraphicsOptions::RGBColorOrFaint && cOptions >= 5)
if (typeOpt == DispatchTypes::GraphicsOptions::RGBColorOrFaint && options.size() >= 5)
{
*pcOptionsConsumed = 5;
optionsConsumed = 5;
// ensure that each value fits in a byte
unsigned int red = rgOptions[2] > 255 ? 255 : rgOptions[2];
unsigned int green = rgOptions[3] > 255 ? 255 : rgOptions[3];
unsigned int blue = rgOptions[4] > 255 ? 255 : rgOptions[4];
const auto limit = (DispatchTypes::GraphicsOptions)255;
const auto red = std::min(options.at(2), limit);
const auto green = std::min(options.at(3), limit);
const auto blue = std::min(options.at(4), limit);
color = RGB(red, green, blue);
fSuccess = _terminalApi.SetTextRgbColor(color, isForeground);
success = _terminalApi.SetTextRgbColor(color, isForeground);
}
else if (typeOpt == DispatchTypes::GraphicsOptions::BlinkOrXterm256Index && cOptions >= 3)
else if (typeOpt == DispatchTypes::GraphicsOptions::BlinkOrXterm256Index && options.size() >= 3)
{
*pcOptionsConsumed = 3;
if (rgOptions[2] <= 255) // ensure that the provided index is on the table
optionsConsumed = 3;
if (options.at(2) <= 255) // ensure that the provided index is on the table
{
unsigned int tableIndex = rgOptions[2];
fSuccess = isForeground ?
_terminalApi.SetTextForegroundIndex((BYTE)tableIndex) :
_terminalApi.SetTextBackgroundIndex((BYTE)tableIndex);
unsigned int tableIndex = options.at(2);
success = isForeground ?
_terminalApi.SetTextForegroundIndex((BYTE)tableIndex) :
_terminalApi.SetTextBackgroundIndex((BYTE)tableIndex);
}
}
}
return fSuccess;
return success;
}
bool TerminalDispatch::_SetBoldColorHelper(const DispatchTypes::GraphicsOptions option)
@ -288,41 +287,40 @@ void TerminalDispatch::_SetGraphicsOptionHelper(const DispatchTypes::GraphicsOpt
}
}
bool TerminalDispatch::SetGraphicsRendition(const DispatchTypes::GraphicsOptions* const rgOptions,
const size_t cOptions)
bool TerminalDispatch::SetGraphicsRendition(const std::basic_string_view<DispatchTypes::GraphicsOptions> options)
{
bool fSuccess = false;
bool success = false;
// Run through the graphics options and apply them
for (size_t i = 0; i < cOptions; i++)
for (size_t i = 0; i < options.size(); i++)
{
DispatchTypes::GraphicsOptions opt = rgOptions[i];
DispatchTypes::GraphicsOptions opt = options.at(i);
if (s_IsDefaultColorOption(opt))
{
fSuccess = _SetDefaultColorHelper(opt);
success = _SetDefaultColorHelper(opt);
}
else if (s_IsBoldColorOption(opt))
{
fSuccess = _SetBoldColorHelper(rgOptions[i]);
success = _SetBoldColorHelper(opt);
}
else if (s_IsRgbColorOption(opt))
{
size_t cOptionsConsumed = 0;
size_t optionsConsumed = 0;
// _SetRgbColorsHelper will call the appropriate ConApi function
fSuccess = _SetRgbColorsHelper(&(rgOptions[i]), cOptions - i, &cOptionsConsumed);
success = _SetRgbColorsHelper(options.substr(i), optionsConsumed);
i += (cOptionsConsumed - 1); // cOptionsConsumed includes the opt we're currently on.
i += (optionsConsumed - 1); // optionsConsumed includes the opt we're currently on.
}
else
{
_SetGraphicsOptionHelper(opt);
// Make sure we un-bold
if (fSuccess && opt == DispatchTypes::GraphicsOptions::Off)
if (success && opt == DispatchTypes::GraphicsOptions::Off)
{
fSuccess = _SetBoldColorHelper(opt);
success = _SetBoldColorHelper(opt);
}
}
}
return fSuccess;
return success;
}

View file

@ -38,13 +38,12 @@ VtInputThread::VtInputThread(_In_ wil::unique_hfile hPipe,
CONSOLE_INFORMATION& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
auto pGetSet = std::make_unique<ConhostInternalGetSet>(gci);
THROW_IF_NULL_ALLOC(pGetSet.get());
auto engine = std::make_unique<InputStateMachineEngine>(new InteractDispatch(pGetSet.release()), inheritCursor);
THROW_IF_NULL_ALLOC(engine.get());
auto dispatch = std::make_unique<InteractDispatch>(std::move(pGetSet));
_pInputStateMachine = std::make_unique<StateMachine>(engine.release());
THROW_IF_NULL_ALLOC(_pInputStateMachine.get());
auto engine = std::make_unique<InputStateMachineEngine>(std::move(dispatch), inheritCursor);
_pInputStateMachine = std::make_unique<StateMachine>(std::move(engine));
}
// Method Description:
@ -77,7 +76,7 @@ VtInputThread::VtInputThread(_In_ wil::unique_hfile hPipe,
{
return S_FALSE;
}
_pInputStateMachine->ProcessString(pwsSequence.get(), cchSequence);
_pInputStateMachine->ProcessString({ pwsSequence.get(), cchSequence });
}
CATCH_RETURN();

View file

@ -968,7 +968,7 @@ constexpr unsigned int LOCAL_BUFFER_SIZE = 100;
StateMachine& machine = screenInfo.GetStateMachine();
size_t const cch = BufferSize / sizeof(WCHAR);
machine.ProcessString(pwchRealUnicode, cch);
machine.ProcessString({ pwchRealUnicode, cch });
*pcb += BufferSize;
}
}

View file

@ -1067,10 +1067,10 @@ void ApiRoutines::GetConsoleInputCodePageImpl(ULONG& codepage) noexcept
CATCH_LOG();
}
void DoSrvGetConsoleOutputCodePage(_Out_ unsigned int* const pCodePage)
void DoSrvGetConsoleOutputCodePage(unsigned int& codepage)
{
const CONSOLE_INFORMATION& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
*pCodePage = gci.OutputCP;
codepage = gci.OutputCP;
}
// Routine Description:
@ -1083,9 +1083,9 @@ void ApiRoutines::GetConsoleOutputCodePageImpl(ULONG& codepage) noexcept
{
LockConsole();
auto Unlock = wil::scope_exit([&] { UnlockConsole(); });
unsigned int uiCodepage;
DoSrvGetConsoleOutputCodePage(&uiCodepage);
codepage = uiCodepage;
unsigned int cp;
DoSrvGetConsoleOutputCodePage(cp);
codepage = cp;
}
CATCH_LOG();
}
@ -1322,25 +1322,25 @@ void DoSrvPrivateAllowCursorBlinking(SCREEN_INFORMATION& screenInfo, const bool
// untouched.
// Currently only accessible through the use of ANSI sequence DECSTBM
// Parameters:
// - psrScrollMargins - A rect who's Top and Bottom members will be used to set
// - scrollMargins - A rect who's Top and Bottom members will be used to set
// the new values of the top and bottom margins. If (0,0), then the margins
// will be disabled. NOTE: This is a rect in the case that we'll need the
// left and right margins in the future.
// Return value:
// - True if handled successfully. False otherwise.
[[nodiscard]] NTSTATUS DoSrvPrivateSetScrollingRegion(SCREEN_INFORMATION& screenInfo, const SMALL_RECT* const psrScrollMargins)
[[nodiscard]] NTSTATUS DoSrvPrivateSetScrollingRegion(SCREEN_INFORMATION& screenInfo, const SMALL_RECT& scrollMargins)
{
NTSTATUS Status = STATUS_SUCCESS;
if (psrScrollMargins->Top > psrScrollMargins->Bottom)
if (scrollMargins.Top > scrollMargins.Bottom)
{
Status = STATUS_INVALID_PARAMETER;
}
if (NT_SUCCESS(Status))
{
SMALL_RECT srScrollMargins = screenInfo.GetRelativeScrollMargins().ToInclusive();
srScrollMargins.Top = psrScrollMargins->Top;
srScrollMargins.Bottom = psrScrollMargins->Bottom;
srScrollMargins.Top = scrollMargins.Top;
srScrollMargins.Bottom = scrollMargins.Bottom;
screenInfo.GetActiveBuffer().SetScrollMargins(Viewport::FromInclusive(srScrollMargins));
}
@ -1690,24 +1690,14 @@ void DoSrvSetCursorColor(SCREEN_INFORMATION& screenInfo,
// of extra unnecessary data and takes a lot of extra processing time.
// Parameters
// - screenInfo - The screen buffer to retrieve default color attributes information from
// - pwAttributes - Pointer to space that will receive color attributes data
// - attributes - 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 DoSrvPrivateGetConsoleScreenBufferAttributes(const SCREEN_INFORMATION& screenInfo, WORD& attributes)
{
NTSTATUS Status = STATUS_SUCCESS;
attributes = screenInfo.GetActiveBuffer().GetAttributes().GetLegacyAttributes();
if (pwAttributes == nullptr)
{
Status = STATUS_INVALID_PARAMETER;
}
if (NT_SUCCESS(Status))
{
*pwAttributes = screenInfo.GetActiveBuffer().GetAttributes().GetLegacyAttributes();
}
return Status;
return STATUS_SUCCESS;
}
// Routine Description:
@ -2056,10 +2046,10 @@ void DoSrvPrivateRefreshWindow(_In_ const SCREEN_INFORMATION& screenInfo)
// - isPty: receives the bool indicating whether or not we're in pty mode.
// Return value:
// <none>
void DoSrvIsConsolePty(_Out_ bool* const pIsPty)
void DoSrvIsConsolePty(bool& isPty)
{
const CONSOLE_INFORMATION& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
*pIsPty = gci.IsInVtIoMode();
isPty = gci.IsInVtIoMode();
}
// Routine Description:
@ -2075,7 +2065,7 @@ void DoSrvPrivateSetDefaultTabStops()
// Parameters:
// - count - the number of lines to modify
// - insert - true if inserting lines, false if deleting lines
void DoSrvPrivateModifyLinesImpl(const unsigned int count, const bool insert)
void DoSrvPrivateModifyLinesImpl(const size_t count, const bool insert)
{
auto& screenInfo = ServiceLocator::LocateGlobals().getConsoleInformation().GetActiveOutputBuffer().GetActiveBuffer();
auto& textBuffer = screenInfo.GetTextBuffer();
@ -2123,7 +2113,7 @@ void DoSrvPrivateModifyLinesImpl(const unsigned int count, const bool insert)
// - a private API call for deleting lines in the active screen buffer.
// Parameters:
// - count - the number of lines to delete
void DoSrvPrivateDeleteLines(const unsigned int count)
void DoSrvPrivateDeleteLines(const size_t count)
{
DoSrvPrivateModifyLinesImpl(count, false);
}
@ -2132,7 +2122,7 @@ void DoSrvPrivateDeleteLines(const unsigned int count)
// - a private API call for inserting lines in the active screen buffer.
// Parameters:
// - count - the number of lines to insert
void DoSrvPrivateInsertLines(const unsigned int count)
void DoSrvPrivateInsertLines(const size_t count)
{
DoSrvPrivateModifyLinesImpl(count, true);
}

View file

@ -32,7 +32,7 @@ void DoSrvPrivateSetDefaultAttributes(SCREEN_INFORMATION& screenInfo, const bool
void DoSrvPrivateShowCursor(SCREEN_INFORMATION& screenInfo, const bool show) noexcept;
void DoSrvPrivateAllowCursorBlinking(SCREEN_INFORMATION& screenInfo, const bool fEnable);
[[nodiscard]] NTSTATUS DoSrvPrivateSetScrollingRegion(SCREEN_INFORMATION& screenInfo, const SMALL_RECT* const psrScrollMargins);
[[nodiscard]] NTSTATUS DoSrvPrivateSetScrollingRegion(SCREEN_INFORMATION& screenInfo, const SMALL_RECT& scrollMargins);
[[nodiscard]] NTSTATUS DoSrvPrivateReverseLineFeed(SCREEN_INFORMATION& screenInfo);
[[nodiscard]] HRESULT DoSrvMoveCursorVertically(SCREEN_INFORMATION& screenInfo, const short lines);
@ -71,19 +71,19 @@ void DoSrvSetCursorColor(SCREEN_INFORMATION& screenInfo,
const COLORREF cursorColor);
[[nodiscard]] NTSTATUS DoSrvPrivateGetConsoleScreenBufferAttributes(const SCREEN_INFORMATION& screenInfo,
_Out_ WORD* const pwAttributes);
WORD& attributes);
void DoSrvPrivateRefreshWindow(const SCREEN_INFORMATION& screenInfo);
void DoSrvGetConsoleOutputCodePage(_Out_ unsigned int* const pCodePage);
void DoSrvGetConsoleOutputCodePage(unsigned int& codepage);
[[nodiscard]] NTSTATUS DoSrvPrivateSuppressResizeRepaint();
void DoSrvIsConsolePty(_Out_ bool* const pIsPty);
void DoSrvIsConsolePty(bool& isPty);
void DoSrvPrivateSetDefaultTabStops();
void DoSrvPrivateDeleteLines(const unsigned int count);
void DoSrvPrivateInsertLines(const unsigned int count);
void DoSrvPrivateDeleteLines(const size_t count);
void DoSrvPrivateInsertLines(const size_t count);
void DoSrvPrivateMoveToBottom(SCREEN_INFORMATION& screenInfo);

View file

@ -36,12 +36,12 @@ void WriteBuffer::Print(const wchar_t wch)
// Routine Description:
// - Handles the print action from the state machine
// Arguments:
// - wch - The character to be printed.
// - string - The string to be printed.
// Return Value:
// - <none>
void WriteBuffer::PrintString(const wchar_t* const rgwch, const size_t cch)
void WriteBuffer::PrintString(const std::wstring_view string)
{
_DefaultStringCase(rgwch, cch);
_DefaultStringCase(string);
}
// Routine Description:
@ -63,25 +63,25 @@ void WriteBuffer::Execute(const wchar_t wch)
// - <none>
void WriteBuffer::_DefaultCase(const wchar_t wch)
{
_DefaultStringCase(const_cast<wchar_t*>(&wch), 1); // WriteCharsLegacy wants mutable chars, so we'll givve it mutable chars.
_DefaultStringCase({ &wch, 1 });
}
// Routine Description:
// - Default text editing/printing handler for all characters that were not routed elsewhere by other state machine intercepts.
// Arguments:
// - wch - The character to be processed by our default text editing/printing mechanisms.
// - string - The string to be processed by our default text editing/printing mechanisms.
// Return Value:
// - <none>
void WriteBuffer::_DefaultStringCase(_In_reads_(cch) const wchar_t* const rgwch, const size_t cch)
void WriteBuffer::_DefaultStringCase(const std::wstring_view string)
{
size_t dwNumBytes = cch * sizeof(wchar_t);
size_t dwNumBytes = string.size() * sizeof(wchar_t);
_io.GetActiveOutputBuffer().GetTextBuffer().GetCursor().SetIsOn(true);
_ntstatus = WriteCharsLegacy(_io.GetActiveOutputBuffer(),
rgwch,
rgwch,
rgwch,
string.data(),
string.data(),
string.data(),
&dwNumBytes,
nullptr,
_io.GetActiveOutputBuffer().GetTextBuffer().GetCursor().GetPosition().X,
@ -97,124 +97,124 @@ ConhostInternalGetSet::ConhostInternalGetSet(_In_ IIoProvider& io) :
// Routine Description:
// - Connects the GetConsoleScreenBufferInfoEx API call directly into our Driver Message servicing call inside Conhost.exe
// Arguments:
// - pConsoleScreenBufferInfoEx - Pointer to structure to hold screen buffer information like the public API call.
// - screenBufferInfo - Structure to hold screen buffer information like the public API call.
// Return Value:
// - TRUE if successful (see DoSrvGetConsoleScreenBufferInfo). FALSE otherwise.
BOOL ConhostInternalGetSet::GetConsoleScreenBufferInfoEx(_Out_ CONSOLE_SCREEN_BUFFER_INFOEX* const pConsoleScreenBufferInfoEx) const
// - true if successful (see DoSrvGetConsoleScreenBufferInfo). false otherwise.
bool ConhostInternalGetSet::GetConsoleScreenBufferInfoEx(CONSOLE_SCREEN_BUFFER_INFOEX& screenBufferInfo) const
{
ServiceLocator::LocateGlobals().api.GetConsoleScreenBufferInfoExImpl(_io.GetActiveOutputBuffer(), *pConsoleScreenBufferInfoEx);
return TRUE;
ServiceLocator::LocateGlobals().api.GetConsoleScreenBufferInfoExImpl(_io.GetActiveOutputBuffer(), screenBufferInfo);
return true;
}
// Routine Description:
// - Connects the SetConsoleScreenBufferInfoEx API call directly into our Driver Message servicing call inside Conhost.exe
// Arguments:
// - pConsoleScreenBufferInfoEx - Pointer to structure containing screen buffer information like the public API call.
// - screenBufferInfo - Structure containing screen buffer information like the public API call.
// Return Value:
// - TRUE if successful (see DoSrvSetConsoleScreenBufferInfo). FALSE otherwise.
BOOL ConhostInternalGetSet::SetConsoleScreenBufferInfoEx(const CONSOLE_SCREEN_BUFFER_INFOEX* const pConsoleScreenBufferInfoEx)
// - true if successful (see DoSrvSetConsoleScreenBufferInfo). false otherwise.
bool ConhostInternalGetSet::SetConsoleScreenBufferInfoEx(const CONSOLE_SCREEN_BUFFER_INFOEX& screenBufferInfo)
{
return SUCCEEDED(ServiceLocator::LocateGlobals().api.SetConsoleScreenBufferInfoExImpl(_io.GetActiveOutputBuffer(), *pConsoleScreenBufferInfoEx));
return SUCCEEDED(ServiceLocator::LocateGlobals().api.SetConsoleScreenBufferInfoExImpl(_io.GetActiveOutputBuffer(), screenBufferInfo));
}
// Routine Description:
// - Connects the SetConsoleCursorPosition API call directly into our Driver Message servicing call inside Conhost.exe
// Arguments:
// - coordCursorPosition - new cursor position to set like the public API call.
// - position - new cursor position to set like the public API call.
// Return Value:
// - TRUE if successful (see DoSrvSetConsoleCursorPosition). FALSE otherwise.
BOOL ConhostInternalGetSet::SetConsoleCursorPosition(const COORD coordCursorPosition)
// - true if successful (see DoSrvSetConsoleCursorPosition). false otherwise.
bool ConhostInternalGetSet::SetConsoleCursorPosition(const COORD position)
{
return SUCCEEDED(ServiceLocator::LocateGlobals().api.SetConsoleCursorPositionImpl(_io.GetActiveOutputBuffer(), coordCursorPosition));
return SUCCEEDED(ServiceLocator::LocateGlobals().api.SetConsoleCursorPositionImpl(_io.GetActiveOutputBuffer(), position));
}
// Routine Description:
// - Connects the GetConsoleCursorInfo API call directly into our Driver Message servicing call inside Conhost.exe
// Arguments:
// - pConsoleCursorInfo - Pointer to structure to receive console cursor rendering info
// - cursorInfo - Structure to receive console cursor rendering info
// Return Value:
// - TRUE if successful (see DoSrvGetConsoleCursorInfo). FALSE otherwise.
BOOL ConhostInternalGetSet::GetConsoleCursorInfo(_In_ CONSOLE_CURSOR_INFO* const pConsoleCursorInfo) const
// - true if successful (see DoSrvGetConsoleCursorInfo). false otherwise.
bool ConhostInternalGetSet::GetConsoleCursorInfo(CONSOLE_CURSOR_INFO& cursorInfo) const
{
bool bVisible;
DWORD dwSize;
bool visible;
DWORD size;
ServiceLocator::LocateGlobals().api.GetConsoleCursorInfoImpl(_io.GetActiveOutputBuffer(), dwSize, bVisible);
pConsoleCursorInfo->bVisible = bVisible;
pConsoleCursorInfo->dwSize = dwSize;
return TRUE;
ServiceLocator::LocateGlobals().api.GetConsoleCursorInfoImpl(_io.GetActiveOutputBuffer(), size, visible);
cursorInfo.bVisible = visible;
cursorInfo.dwSize = size;
return true;
}
// Routine Description:
// - Connects the SetConsoleCursorInfo API call directly into our Driver Message servicing call inside Conhost.exe
// Arguments:
// - pConsoleCursorInfo - Updated size/visibility information to modify the cursor rendering behavior.
// - cursorInfo - Updated size/visibility information to modify the cursor rendering behavior.
// Return Value:
// - TRUE if successful (see DoSrvSetConsoleCursorInfo). FALSE otherwise.
BOOL ConhostInternalGetSet::SetConsoleCursorInfo(const CONSOLE_CURSOR_INFO* const pConsoleCursorInfo)
// - true if successful (see DoSrvSetConsoleCursorInfo). false otherwise.
bool ConhostInternalGetSet::SetConsoleCursorInfo(const CONSOLE_CURSOR_INFO& cursorInfo)
{
const bool visible = !!pConsoleCursorInfo->bVisible;
return SUCCEEDED(ServiceLocator::LocateGlobals().api.SetConsoleCursorInfoImpl(_io.GetActiveOutputBuffer(), pConsoleCursorInfo->dwSize, visible));
const bool visible = !!cursorInfo.bVisible;
return SUCCEEDED(ServiceLocator::LocateGlobals().api.SetConsoleCursorInfoImpl(_io.GetActiveOutputBuffer(), cursorInfo.dwSize, visible));
}
// Routine Description:
// - Connects the SetConsoleTextAttribute API call directly into our Driver Message servicing call inside Conhost.exe
// Sets BOTH the FG and the BG component of the attributes.
// Arguments:
// - wAttr - new color/graphical attributes to apply as default within the console text buffer
// - attr - new color/graphical attributes to apply as default within the console text buffer
// Return Value:
// - TRUE if successful (see DoSrvSetConsoleTextAttribute). FALSE otherwise.
BOOL ConhostInternalGetSet::SetConsoleTextAttribute(const WORD wAttr)
// - true if successful (see DoSrvSetConsoleTextAttribute). false otherwise.
bool ConhostInternalGetSet::SetConsoleTextAttribute(const WORD attr)
{
return SUCCEEDED(ServiceLocator::LocateGlobals().api.SetConsoleTextAttributeImpl(_io.GetActiveOutputBuffer(), wAttr));
return SUCCEEDED(ServiceLocator::LocateGlobals().api.SetConsoleTextAttributeImpl(_io.GetActiveOutputBuffer(), attr));
}
// Routine Description:
// - Connects the PrivateSetDefaultAttributes API call directly into our Driver Message servicing call inside Conhost.exe
// Sets the FG and/or BG to the Default attributes values.
// Arguments:
// - fForeground - Set the foreground to the default attributes
// - fBackground - Set the background to the default attributes
// - foreground - Set the foreground to the default attributes
// - background - Set the background to the default attributes
// Return Value:
// - TRUE if successful (see DoSrvPrivateSetDefaultAttributes). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateSetDefaultAttributes(const bool fForeground,
const bool fBackground)
// - true if successful (see DoSrvPrivateSetDefaultAttributes). false otherwise.
bool ConhostInternalGetSet::PrivateSetDefaultAttributes(const bool foreground,
const bool background)
{
DoSrvPrivateSetDefaultAttributes(_io.GetActiveOutputBuffer(), fForeground, fBackground);
return TRUE;
DoSrvPrivateSetDefaultAttributes(_io.GetActiveOutputBuffer(), foreground, background);
return true;
}
// Routine Description:
// - Connects the PrivateSetLegacyAttributes API call directly into our Driver Message servicing call inside Conhost.exe
// Sets only the components of the attributes requested with the fForeground, fBackground, and fMeta flags.
// Sets only the components of the attributes requested with the foreground, background, and meta flags.
// Arguments:
// - wAttr - new color/graphical attributes to apply as default within the console text buffer
// - fForeground - The new attributes contain an update to the foreground attributes
// - fBackground - The new attributes contain an update to the background attributes
// - fMeta - The new attributes contain an update to the meta attributes
// - attr - new color/graphical attributes to apply as default within the console text buffer
// - foreground - The new attributes contain an update to the foreground attributes
// - background - The new attributes contain an update to the background attributes
// - meta - The new attributes contain an update to the meta attributes
// Return Value:
// - TRUE if successful (see DoSrvVtSetLegacyAttributes). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateSetLegacyAttributes(const WORD wAttr,
const bool fForeground,
const bool fBackground,
const bool fMeta)
// - true if successful (see DoSrvVtSetLegacyAttributes). false otherwise.
bool ConhostInternalGetSet::PrivateSetLegacyAttributes(const WORD attr,
const bool foreground,
const bool background,
const bool meta)
{
DoSrvPrivateSetLegacyAttributes(_io.GetActiveOutputBuffer(), wAttr, fForeground, fBackground, fMeta);
return TRUE;
DoSrvPrivateSetLegacyAttributes(_io.GetActiveOutputBuffer(), attr, foreground, background, meta);
return true;
}
// Routine Description:
// - Sets the current attributes of the screen buffer to use the color table entry specified by
// the iXtermTableEntry. Sets either the FG or the BG component of the attributes.
// the xtermTableEntry. Sets either the FG or the BG component of the attributes.
// Arguments:
// - iXtermTableEntry - The entry of the xterm table to use.
// - fIsForeground - Whether or not the color applies to the foreground.
// - xtermTableEntry - The entry of the xterm table to use.
// - isForeground - Whether or not the color applies to the foreground.
// Return Value:
// - TRUE if successful (see DoSrvPrivateSetConsoleXtermTextAttribute). FALSE otherwise.
BOOL ConhostInternalGetSet::SetConsoleXtermTextAttribute(const int iXtermTableEntry, const bool fIsForeground)
// - true if successful (see DoSrvPrivateSetConsoleXtermTextAttribute). false otherwise.
bool ConhostInternalGetSet::SetConsoleXtermTextAttribute(const int xtermTableEntry, const bool isForeground)
{
DoSrvPrivateSetConsoleXtermTextAttribute(_io.GetActiveOutputBuffer(), iXtermTableEntry, fIsForeground);
return TRUE;
DoSrvPrivateSetConsoleXtermTextAttribute(_io.GetActiveOutputBuffer(), xtermTableEntry, isForeground);
return true;
}
// Routine Description:
@ -222,32 +222,32 @@ BOOL ConhostInternalGetSet::SetConsoleXtermTextAttribute(const int iXtermTableEn
// Sets either the FG or the BG component of the attributes.
// Arguments:
// - rgbColor - The rgb color to use.
// - fIsForeground - Whether or not the color applies to the foreground.
// - isForeground - Whether or not the color applies to the foreground.
// Return Value:
// - TRUE if successful (see DoSrvPrivateSetConsoleRGBTextAttribute). FALSE otherwise.
BOOL ConhostInternalGetSet::SetConsoleRGBTextAttribute(const COLORREF rgbColor, const bool fIsForeground)
// - true if successful (see DoSrvPrivateSetConsoleRGBTextAttribute). false otherwise.
bool ConhostInternalGetSet::SetConsoleRGBTextAttribute(const COLORREF rgbColor, const bool isForeground)
{
DoSrvPrivateSetConsoleRGBTextAttribute(_io.GetActiveOutputBuffer(), rgbColor, fIsForeground);
return TRUE;
DoSrvPrivateSetConsoleRGBTextAttribute(_io.GetActiveOutputBuffer(), rgbColor, isForeground);
return true;
}
BOOL ConhostInternalGetSet::PrivateBoldText(const bool bolded)
bool ConhostInternalGetSet::PrivateBoldText(const bool bolded)
{
DoSrvPrivateBoldText(_io.GetActiveOutputBuffer(), bolded);
return TRUE;
return true;
}
// Method Description:
// - Retrieves the currently active ExtendedAttributes. See also
// DoSrvPrivateGetExtendedTextAttributes
// Arguments:
// - pAttrs: Recieves the ExtendedAttributes value.
// - attrs: Recieves the ExtendedAttributes value.
// Return Value:
// - TRUE if successful (see DoSrvPrivateGetExtendedTextAttributes). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateGetExtendedTextAttributes(ExtendedAttributes* const pAttrs)
// - true if successful (see DoSrvPrivateGetExtendedTextAttributes). false otherwise.
bool ConhostInternalGetSet::PrivateGetExtendedTextAttributes(ExtendedAttributes& attrs)
{
*pAttrs = DoSrvPrivateGetExtendedTextAttributes(_io.GetActiveOutputBuffer());
return TRUE;
attrs = DoSrvPrivateGetExtendedTextAttributes(_io.GetActiveOutputBuffer());
return true;
}
// Method Description:
@ -256,23 +256,23 @@ BOOL ConhostInternalGetSet::PrivateGetExtendedTextAttributes(ExtendedAttributes*
// Arguments:
// - extendedAttrs: The new ExtendedAttributes to use
// Return Value:
// - TRUE if successful (see DoSrvPrivateSetExtendedTextAttributes). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateSetExtendedTextAttributes(const ExtendedAttributes attrs)
// - true if successful (see DoSrvPrivateSetExtendedTextAttributes). false otherwise.
bool ConhostInternalGetSet::PrivateSetExtendedTextAttributes(const ExtendedAttributes attrs)
{
DoSrvPrivateSetExtendedTextAttributes(_io.GetActiveOutputBuffer(), attrs);
return TRUE;
return true;
}
// Method Description:
// - Retrieves the current TextAttribute of the active screen buffer.
// Arguments:
// - pAttrs: Receives the TextAttribute value.
// - attrs: Receives the TextAttribute value.
// Return Value:
// - TRUE if successful. FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateGetTextAttributes(TextAttribute* const pAttrs) const
// - true if successful. false otherwise.
bool ConhostInternalGetSet::PrivateGetTextAttributes(TextAttribute& attrs) const
{
*pAttrs = _io.GetActiveOutputBuffer().GetAttributes();
return TRUE;
attrs = _io.GetActiveOutputBuffer().GetAttributes();
return true;
}
// Method Description:
@ -281,23 +281,23 @@ BOOL ConhostInternalGetSet::PrivateGetTextAttributes(TextAttribute* const pAttrs
// Arguments:
// - attrs: The new TextAttribute to use
// Return Value:
// - TRUE if successful. FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateSetTextAttributes(const TextAttribute& attrs)
// - true if successful. false otherwise.
bool ConhostInternalGetSet::PrivateSetTextAttributes(const TextAttribute& attrs)
{
_io.GetActiveOutputBuffer().SetAttributes(attrs);
return TRUE;
return true;
}
// Routine Description:
// - Connects the WriteConsoleInput API call directly into our Driver Message servicing call inside Conhost.exe
// Arguments:
// - events - the input events to be copied into the head of the input
// buffer for the underlying attached process
// buffer for the underlying attached process
// - eventsWritten - on output, the number of events written
// Return Value:
// - TRUE if successful (see DoSrvWriteConsoleInput). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateWriteConsoleInputW(_Inout_ std::deque<std::unique_ptr<IInputEvent>>& events,
_Out_ size_t& eventsWritten)
// - true if successful (see DoSrvWriteConsoleInput). false otherwise.
bool ConhostInternalGetSet::PrivateWriteConsoleInputW(std::deque<std::unique_ptr<IInputEvent>>& events,
size_t& eventsWritten)
{
eventsWritten = 0;
@ -310,13 +310,13 @@ BOOL ConhostInternalGetSet::PrivateWriteConsoleInputW(_Inout_ std::deque<std::un
// Routine Description:
// - Connects the SetConsoleWindowInfo API call directly into our Driver Message servicing call inside Conhost.exe
// Arguments:
// - bAbsolute - Should the window be moved to an absolute position? If false, the movement is relative to the current pos.
// - lpConsoleWindow - Info about how to move the viewport
// - absolute - Should the window be moved to an absolute position? If false, the movement is relative to the current pos.
// - window - Info about how to move the viewport
// Return Value:
// - TRUE if successful (see DoSrvSetConsoleWindowInfo). FALSE otherwise.
BOOL ConhostInternalGetSet::SetConsoleWindowInfo(const BOOL bAbsolute, const SMALL_RECT* const lpConsoleWindow)
// - true if successful (see DoSrvSetConsoleWindowInfo). false otherwise.
bool ConhostInternalGetSet::SetConsoleWindowInfo(const bool absolute, const SMALL_RECT& window)
{
return SUCCEEDED(ServiceLocator::LocateGlobals().api.SetConsoleWindowInfoImpl(_io.GetActiveOutputBuffer(), !!bAbsolute, *lpConsoleWindow));
return SUCCEEDED(ServiceLocator::LocateGlobals().api.SetConsoleWindowInfoImpl(_io.GetActiveOutputBuffer(), absolute, window));
}
// Routine Description:
@ -326,8 +326,8 @@ BOOL ConhostInternalGetSet::SetConsoleWindowInfo(const BOOL bAbsolute, const SMA
// Arguments:
// - fApplicationMode - set to true to enable Application Mode Input, false for Normal Mode.
// Return Value:
// - TRUE if successful (see DoSrvPrivateSetCursorKeysMode). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateSetCursorKeysMode(const bool fApplicationMode)
// - true if successful (see DoSrvPrivateSetCursorKeysMode). false otherwise.
bool ConhostInternalGetSet::PrivateSetCursorKeysMode(const bool fApplicationMode)
{
return NT_SUCCESS(DoSrvPrivateSetCursorKeysMode(fApplicationMode));
}
@ -339,8 +339,8 @@ BOOL ConhostInternalGetSet::PrivateSetCursorKeysMode(const bool fApplicationMode
// Arguments:
// - fApplicationMode - set to true to enable Application Mode Input, false for Numeric Mode.
// Return Value:
// - TRUE if successful (see DoSrvPrivateSetKeypadMode). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateSetKeypadMode(const bool fApplicationMode)
// - true if successful (see DoSrvPrivateSetKeypadMode). false otherwise.
bool ConhostInternalGetSet::PrivateSetKeypadMode(const bool fApplicationMode)
{
return NT_SUCCESS(DoSrvPrivateSetKeypadMode(fApplicationMode));
}
@ -352,11 +352,11 @@ BOOL ConhostInternalGetSet::PrivateSetKeypadMode(const bool fApplicationMode)
// Arguments:
// - show - set to true to make the cursor visible, false to hide.
// Return Value:
// - TRUE if successful (see DoSrvPrivateShowCursor). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateShowCursor(const bool show) noexcept
// - true if successful (see DoSrvPrivateShowCursor). false otherwise.
bool ConhostInternalGetSet::PrivateShowCursor(const bool show) noexcept
{
DoSrvPrivateShowCursor(_io.GetActiveOutputBuffer(), show);
return TRUE;
return true;
}
// Routine Description:
@ -366,11 +366,11 @@ BOOL ConhostInternalGetSet::PrivateShowCursor(const bool show) noexcept
// Arguments:
// - fEnable - set to true to enable blinking, false to disable
// Return Value:
// - TRUE if successful (see DoSrvPrivateAllowCursorBlinking). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateAllowCursorBlinking(const bool fEnable)
// - true if successful (see DoSrvPrivateAllowCursorBlinking). false otherwise.
bool ConhostInternalGetSet::PrivateAllowCursorBlinking(const bool fEnable)
{
DoSrvPrivateAllowCursorBlinking(_io.GetActiveOutputBuffer(), fEnable);
return TRUE;
return true;
}
// Routine Description:
@ -378,12 +378,12 @@ BOOL ConhostInternalGetSet::PrivateAllowCursorBlinking(const bool fEnable)
// PrivateSetScrollingRegion is an internal-only "API" call that the vt commands can execute,
// but it is not represented as a function call on out public API surface.
// Arguments:
// - psrScrollMargins - The bounds of the region to be the scrolling region of the viewport.
// - scrollMargins - The bounds of the region to be the scrolling region of the viewport.
// Return Value:
// - TRUE if successful (see DoSrvPrivateSetScrollingRegion). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateSetScrollingRegion(const SMALL_RECT* const psrScrollMargins)
// - true if successful (see DoSrvPrivateSetScrollingRegion). false otherwise.
bool ConhostInternalGetSet::PrivateSetScrollingRegion(const SMALL_RECT& scrollMargins)
{
return NT_SUCCESS(DoSrvPrivateSetScrollingRegion(_io.GetActiveOutputBuffer(), psrScrollMargins));
return NT_SUCCESS(DoSrvPrivateSetScrollingRegion(_io.GetActiveOutputBuffer(), scrollMargins));
}
// Routine Description:
@ -391,8 +391,8 @@ BOOL ConhostInternalGetSet::PrivateSetScrollingRegion(const SMALL_RECT* const ps
// PrivateReverseLineFeed is an internal-only "API" call that the vt commands can execute,
// but it is not represented as a function call on out public API surface.
// Return Value:
// - TRUE if successful (see DoSrvPrivateReverseLineFeed). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateReverseLineFeed()
// - true if successful (see DoSrvPrivateReverseLineFeed). false otherwise.
bool ConhostInternalGetSet::PrivateReverseLineFeed()
{
return NT_SUCCESS(DoSrvPrivateReverseLineFeed(_io.GetActiveOutputBuffer()));
}
@ -402,10 +402,16 @@ BOOL ConhostInternalGetSet::PrivateReverseLineFeed()
// MoveCursorVertically is an internal-only "API" call that the vt commands can execute,
// but it is not represented as a function call on out public API surface.
// Return Value:
// - TRUE if successful (see DoSrvMoveCursorVertically). FALSE otherwise.
BOOL ConhostInternalGetSet::MoveCursorVertically(const short lines)
// - true if successful (see DoSrvMoveCursorVertically). false otherwise.
bool ConhostInternalGetSet::MoveCursorVertically(const ptrdiff_t lines)
{
return SUCCEEDED(DoSrvMoveCursorVertically(_io.GetActiveOutputBuffer(), lines));
SHORT l;
if (FAILED(PtrdiffTToShort(lines, &l)))
{
return false;
}
return SUCCEEDED(DoSrvMoveCursorVertically(_io.GetActiveOutputBuffer(), l));
}
// Routine Description:
@ -413,8 +419,8 @@ BOOL ConhostInternalGetSet::MoveCursorVertically(const short lines)
// Arguments:
// - title - The null-terminated string to set as the window title
// Return Value:
// - TRUE if successful (see DoSrvSetConsoleTitle). FALSE otherwise.
BOOL ConhostInternalGetSet::SetConsoleTitleW(std::wstring_view title)
// - true if successful (see DoSrvSetConsoleTitle). false otherwise.
bool ConhostInternalGetSet::SetConsoleTitleW(std::wstring_view title)
{
return SUCCEEDED(DoSrvSetConsoleTitleW(title));
}
@ -424,8 +430,8 @@ BOOL ConhostInternalGetSet::SetConsoleTitleW(std::wstring_view title)
// PrivateUseAlternateScreenBuffer is an internal-only "API" call that the vt commands can execute,
// but it is not represented as a function call on out public API surface.
// Return Value:
// - TRUE if successful (see DoSrvPrivateUseAlternateScreenBuffer). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateUseAlternateScreenBuffer()
// - true if successful (see DoSrvPrivateUseAlternateScreenBuffer). false otherwise.
bool ConhostInternalGetSet::PrivateUseAlternateScreenBuffer()
{
return NT_SUCCESS(DoSrvPrivateUseAlternateScreenBuffer(_io.GetActiveOutputBuffer()));
}
@ -435,11 +441,11 @@ BOOL ConhostInternalGetSet::PrivateUseAlternateScreenBuffer()
// PrivateUseMainScreenBuffer is an internal-only "API" call that the vt commands can execute,
// but it is not represented as a function call on out public API surface.
// Return Value:
// - TRUE if successful (see DoSrvPrivateUseMainScreenBuffer). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateUseMainScreenBuffer()
// - true if successful (see DoSrvPrivateUseMainScreenBuffer). false otherwise.
bool ConhostInternalGetSet::PrivateUseMainScreenBuffer()
{
DoSrvPrivateUseMainScreenBuffer(_io.GetActiveOutputBuffer());
return TRUE;
return true;
}
// - Connects the PrivateHorizontalTabSet call directly into our Driver Message servicing call inside Conhost.exe
@ -448,8 +454,8 @@ BOOL ConhostInternalGetSet::PrivateUseMainScreenBuffer()
// Arguments:
// <none>
// Return Value:
// - TRUE if successful (see PrivateHorizontalTabSet). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateHorizontalTabSet()
// - true if successful (see PrivateHorizontalTabSet). false otherwise.
bool ConhostInternalGetSet::PrivateHorizontalTabSet()
{
return NT_SUCCESS(DoSrvPrivateHorizontalTabSet());
}
@ -461,10 +467,16 @@ BOOL ConhostInternalGetSet::PrivateHorizontalTabSet()
// Arguments:
// - sNumTabs - the number of tabs to execute
// Return Value:
// - TRUE if successful (see PrivateForwardTab). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateForwardTab(const SHORT sNumTabs)
// - true if successful (see PrivateForwardTab). false otherwise.
bool ConhostInternalGetSet::PrivateForwardTab(const size_t numTabs)
{
return NT_SUCCESS(DoSrvPrivateForwardTab(sNumTabs));
SHORT tabs;
if (FAILED(SizeTToShort(numTabs, &tabs)))
{
return false;
}
return NT_SUCCESS(DoSrvPrivateForwardTab(tabs));
}
// Routine Description:
@ -472,12 +484,18 @@ BOOL ConhostInternalGetSet::PrivateForwardTab(const SHORT sNumTabs)
// PrivateBackwardsTab is an internal-only "API" call that the vt commands can execute,
// but it is not represented as a function call on out public API surface.
// Arguments:
// - sNumTabs - the number of tabs to execute
// - numTabs - the number of tabs to execute
// Return Value:
// - TRUE if successful (see PrivateBackwardsTab). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateBackwardsTab(const SHORT sNumTabs)
// - true if successful (see PrivateBackwardsTab). false otherwise.
bool ConhostInternalGetSet::PrivateBackwardsTab(const size_t numTabs)
{
return NT_SUCCESS(DoSrvPrivateBackwardsTab(sNumTabs));
SHORT tabs;
if (FAILED(SizeTToShort(numTabs, &tabs)))
{
return false;
}
return NT_SUCCESS(DoSrvPrivateBackwardsTab(tabs));
}
// Routine Description:
@ -485,23 +503,23 @@ BOOL ConhostInternalGetSet::PrivateBackwardsTab(const SHORT sNumTabs)
// PrivateTabClear is an internal-only "API" call that the vt commands can execute,
// but it is not represented as a function call on out public API surface.
// Arguments:
// - fClearAll - set to true to enable blinking, false to disable
// - clearAll - set to true to enable blinking, false to disable
// Return Value:
// - TRUE if successful (see PrivateTabClear). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateTabClear(const bool fClearAll)
// - true if successful (see PrivateTabClear). false otherwise.
bool ConhostInternalGetSet::PrivateTabClear(const bool clearAll)
{
DoSrvPrivateTabClear(fClearAll);
return TRUE;
DoSrvPrivateTabClear(clearAll);
return true;
}
// Routine Description:
// - Connects the PrivateSetDefaultTabStops call directly into the private api point
// Return Value:
// - TRUE
BOOL ConhostInternalGetSet::PrivateSetDefaultTabStops()
// - true
bool ConhostInternalGetSet::PrivateSetDefaultTabStops()
{
DoSrvPrivateSetDefaultTabStops();
return TRUE;
return true;
}
// Routine Description:
@ -509,13 +527,13 @@ BOOL ConhostInternalGetSet::PrivateSetDefaultTabStops()
// PrivateEnableVT200MouseMode is an internal-only "API" call that the vt commands can execute,
// but it is not represented as a function call on out public API surface.
// Arguments:
// - fEnabled - set to true to enable vt200 mouse mode, false to disable
// - enabled - set to true to enable vt200 mouse mode, false to disable
// Return Value:
// - TRUE if successful (see DoSrvPrivateEnableVT200MouseMode). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateEnableVT200MouseMode(const bool fEnabled)
// - true if successful (see DoSrvPrivateEnableVT200MouseMode). false otherwise.
bool ConhostInternalGetSet::PrivateEnableVT200MouseMode(const bool enabled)
{
DoSrvPrivateEnableVT200MouseMode(fEnabled);
return TRUE;
DoSrvPrivateEnableVT200MouseMode(enabled);
return true;
}
// Routine Description:
@ -523,13 +541,13 @@ BOOL ConhostInternalGetSet::PrivateEnableVT200MouseMode(const bool fEnabled)
// PrivateEnableUTF8ExtendedMouseMode is an internal-only "API" call that the vt commands can execute,
// but it is not represented as a function call on out public API surface.
// Arguments:
// - fEnabled - set to true to enable utf8 extended mouse mode, false to disable
// - enabled - set to true to enable utf8 extended mouse mode, false to disable
// Return Value:
// - TRUE if successful (see DoSrvPrivateEnableUTF8ExtendedMouseMode). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateEnableUTF8ExtendedMouseMode(const bool fEnabled)
// - true if successful (see DoSrvPrivateEnableUTF8ExtendedMouseMode). false otherwise.
bool ConhostInternalGetSet::PrivateEnableUTF8ExtendedMouseMode(const bool enabled)
{
DoSrvPrivateEnableUTF8ExtendedMouseMode(fEnabled);
return TRUE;
DoSrvPrivateEnableUTF8ExtendedMouseMode(enabled);
return true;
}
// Routine Description:
@ -537,13 +555,13 @@ BOOL ConhostInternalGetSet::PrivateEnableUTF8ExtendedMouseMode(const bool fEnabl
// PrivateEnableSGRExtendedMouseMode is an internal-only "API" call that the vt commands can execute,
// but it is not represented as a function call on out public API surface.
// Arguments:
// - fEnabled - set to true to enable SGR extended mouse mode, false to disable
// - enabled - set to true to enable SGR extended mouse mode, false to disable
// Return Value:
// - TRUE if successful (see DoSrvPrivateEnableSGRExtendedMouseMode). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateEnableSGRExtendedMouseMode(const bool fEnabled)
// - true if successful (see DoSrvPrivateEnableSGRExtendedMouseMode). false otherwise.
bool ConhostInternalGetSet::PrivateEnableSGRExtendedMouseMode(const bool enabled)
{
DoSrvPrivateEnableSGRExtendedMouseMode(fEnabled);
return TRUE;
DoSrvPrivateEnableSGRExtendedMouseMode(enabled);
return true;
}
// Routine Description:
@ -551,13 +569,13 @@ BOOL ConhostInternalGetSet::PrivateEnableSGRExtendedMouseMode(const bool fEnable
// PrivateEnableButtonEventMouseMode is an internal-only "API" call that the vt commands can execute,
// but it is not represented as a function call on out public API surface.
// Arguments:
// - fEnabled - set to true to enable button-event mouse mode, false to disable
// - enabled - set to true to enable button-event mouse mode, false to disable
// Return Value:
// - TRUE if successful (see DoSrvPrivateEnableButtonEventMouseMode). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateEnableButtonEventMouseMode(const bool fEnabled)
// - true if successful (see DoSrvPrivateEnableButtonEventMouseMode). false otherwise.
bool ConhostInternalGetSet::PrivateEnableButtonEventMouseMode(const bool enabled)
{
DoSrvPrivateEnableButtonEventMouseMode(fEnabled);
return TRUE;
DoSrvPrivateEnableButtonEventMouseMode(enabled);
return true;
}
// Routine Description:
@ -565,13 +583,13 @@ BOOL ConhostInternalGetSet::PrivateEnableButtonEventMouseMode(const bool fEnable
// PrivateEnableAnyEventMouseMode is an internal-only "API" call that the vt commands can execute,
// but it is not represented as a function call on out public API surface.
// Arguments:
// - fEnabled - set to true to enable any-event mouse mode, false to disable
// - enabled - set to true to enable any-event mouse mode, false to disable
// Return Value:
// - TRUE if successful (see DoSrvPrivateEnableAnyEventMouseMode). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateEnableAnyEventMouseMode(const bool fEnabled)
// - true if successful (see DoSrvPrivateEnableAnyEventMouseMode). false otherwise.
bool ConhostInternalGetSet::PrivateEnableAnyEventMouseMode(const bool enabled)
{
DoSrvPrivateEnableAnyEventMouseMode(fEnabled);
return TRUE;
DoSrvPrivateEnableAnyEventMouseMode(enabled);
return true;
}
// Routine Description:
@ -579,13 +597,13 @@ BOOL ConhostInternalGetSet::PrivateEnableAnyEventMouseMode(const bool fEnabled)
// PrivateEnableAlternateScroll is an internal-only "API" call that the vt commands can execute,
// but it is not represented as a function call on out public API surface.
// Arguments:
// - fEnabled - set to true to enable alternate scroll mode, false to disable
// - enabled - set to true to enable alternate scroll mode, false to disable
// Return Value:
// - TRUE if successful (see DoSrvPrivateEnableAnyEventMouseMode). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateEnableAlternateScroll(const bool fEnabled)
// - true if successful (see DoSrvPrivateEnableAnyEventMouseMode). false otherwise.
bool ConhostInternalGetSet::PrivateEnableAlternateScroll(const bool enabled)
{
DoSrvPrivateEnableAlternateScroll(fEnabled);
return TRUE;
DoSrvPrivateEnableAlternateScroll(enabled);
return true;
}
// Routine Description:
@ -595,8 +613,8 @@ BOOL ConhostInternalGetSet::PrivateEnableAlternateScroll(const bool fEnabled)
// Arguments:
// <none>
// Return Value:
// - TRUE if successful (see DoSrvPrivateEraseAll). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateEraseAll()
// - true if successful (see DoSrvPrivateEraseAll). false otherwise.
bool ConhostInternalGetSet::PrivateEraseAll()
{
return NT_SUCCESS(DoSrvPrivateEraseAll(_io.GetActiveOutputBuffer()));
}
@ -606,13 +624,13 @@ BOOL ConhostInternalGetSet::PrivateEraseAll()
// SetCursorStyle is an internal-only "API" call that the vt commands can execute,
// but it is not represented as a function call on our public API surface.
// Arguments:
// - cursorType: The style of cursor to change the cursor to.
// - style: The style of cursor to change the cursor to.
// Return Value:
// - TRUE if successful (see DoSrvSetCursorStyle). FALSE otherwise.
BOOL ConhostInternalGetSet::SetCursorStyle(const CursorType cursorType)
// - true if successful (see DoSrvSetCursorStyle). false otherwise.
bool ConhostInternalGetSet::SetCursorStyle(const CursorType style)
{
DoSrvSetCursorStyle(_io.GetActiveOutputBuffer(), cursorType);
return TRUE;
DoSrvSetCursorStyle(_io.GetActiveOutputBuffer(), style);
return true;
}
// Routine Description:
@ -621,22 +639,22 @@ BOOL ConhostInternalGetSet::SetCursorStyle(const CursorType cursorType)
// Arguments:
// - pwAttributes - Pointer to space to receive color attributes data
// Return Value:
// - TRUE if successful. FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateGetConsoleScreenBufferAttributes(_Out_ WORD* const pwAttributes)
// - true if successful. false otherwise.
bool ConhostInternalGetSet::PrivateGetConsoleScreenBufferAttributes(WORD& attributes)
{
return NT_SUCCESS(DoSrvPrivateGetConsoleScreenBufferAttributes(_io.GetActiveOutputBuffer(), pwAttributes));
return NT_SUCCESS(DoSrvPrivateGetConsoleScreenBufferAttributes(_io.GetActiveOutputBuffer(), attributes));
}
// Routine Description:
// - Connects the PrivatePrependConsoleInput API call directly into our Driver Message servicing call inside Conhost.exe
// Arguments:
// - events - the input events to be copied into the head of the input
// buffer for the underlying attached process
// buffer for the underlying attached process
// - eventsWritten - on output, the number of events written
// Return Value:
// - TRUE if successful (see DoSrvPrivatePrependConsoleInput). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivatePrependConsoleInput(_Inout_ std::deque<std::unique_ptr<IInputEvent>>& events,
_Out_ size_t& eventsWritten)
// - true if successful (see DoSrvPrivatePrependConsoleInput). false otherwise.
bool ConhostInternalGetSet::PrivatePrependConsoleInput(std::deque<std::unique_ptr<IInputEvent>>& events,
size_t& eventsWritten)
{
return SUCCEEDED(DoSrvPrivatePrependConsoleInput(_io.GetActiveInputBuffer(),
events,
@ -648,11 +666,11 @@ BOOL ConhostInternalGetSet::PrivatePrependConsoleInput(_Inout_ std::deque<std::u
// Arguments:
// - <none>
// Return Value:
// - TRUE if successful (see DoSrvPrivateRefreshWindow). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateRefreshWindow()
// - true if successful (see DoSrvPrivateRefreshWindow). false otherwise.
bool ConhostInternalGetSet::PrivateRefreshWindow()
{
DoSrvPrivateRefreshWindow(_io.GetActiveOutputBuffer());
return TRUE;
return true;
}
// Routine Description:
@ -660,8 +678,8 @@ BOOL ConhostInternalGetSet::PrivateRefreshWindow()
// Arguments:
// - key - a KeyEvent representing a special type of keypress, typically Ctrl-C
// Return Value:
// - TRUE if successful (see DoSrvPrivateWriteConsoleControlInput). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateWriteConsoleControlInput(_In_ KeyEvent key)
// - true if successful (see DoSrvPrivateWriteConsoleControlInput). false otherwise.
bool ConhostInternalGetSet::PrivateWriteConsoleControlInput(const KeyEvent key)
{
return SUCCEEDED(DoSrvPrivateWriteConsoleControlInput(_io.GetActiveInputBuffer(),
key));
@ -670,13 +688,13 @@ BOOL ConhostInternalGetSet::PrivateWriteConsoleControlInput(_In_ KeyEvent key)
// Routine Description:
// - Connects the GetConsoleOutputCP API call directly into our Driver Message servicing call inside Conhost.exe
// Arguments:
// - puiOutputCP - recieves the outputCP of the console.
// - codepage - recieves the outputCP of the console.
// Return Value:
// - TRUE if successful (see DoSrvPrivateWriteConsoleControlInput). FALSE otherwise.
BOOL ConhostInternalGetSet::GetConsoleOutputCP(_Out_ unsigned int* const puiOutputCP)
// - true if successful (see DoSrvPrivateWriteConsoleControlInput). false otherwise.
bool ConhostInternalGetSet::GetConsoleOutputCP(unsigned int& codepage)
{
DoSrvGetConsoleOutputCodePage(puiOutputCP);
return TRUE;
DoSrvGetConsoleOutputCodePage(codepage);
return true;
}
// Routine Description:
@ -685,8 +703,8 @@ BOOL ConhostInternalGetSet::GetConsoleOutputCP(_Out_ unsigned int* const puiOutp
// Arguments:
// - <none>
// Return Value:
// - TRUE if successful (see DoSrvPrivateSuppressResizeRepaint). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateSuppressResizeRepaint()
// - true if successful (see DoSrvPrivateSuppressResizeRepaint). false otherwise.
bool ConhostInternalGetSet::PrivateSuppressResizeRepaint()
{
return SUCCEEDED(DoSrvPrivateSuppressResizeRepaint());
}
@ -699,11 +717,11 @@ BOOL ConhostInternalGetSet::PrivateSuppressResizeRepaint()
// - cursorColor: The color to change the cursor to. INVALID_COLOR will revert
// it to the legacy inverting behavior.
// Return Value:
// - TRUE if successful (see DoSrvSetCursorStyle). FALSE otherwise.
BOOL ConhostInternalGetSet::SetCursorColor(const COLORREF cursorColor)
// - true if successful (see DoSrvSetCursorStyle). false otherwise.
bool ConhostInternalGetSet::SetCursorColor(const COLORREF cursorColor)
{
DoSrvSetCursorColor(_io.GetActiveOutputBuffer(), cursorColor);
return TRUE;
return true;
}
// Routine Description:
@ -711,23 +729,23 @@ BOOL ConhostInternalGetSet::SetCursorColor(const COLORREF cursorColor)
// Arguments:
// - isPty: recieves the bool indicating whether or not we're in pty mode.
// Return Value:
// - TRUE if successful (see DoSrvIsConsolePty). FALSE otherwise.
BOOL ConhostInternalGetSet::IsConsolePty(_Out_ bool* const pIsPty) const
// - true if successful (see DoSrvIsConsolePty). false otherwise.
bool ConhostInternalGetSet::IsConsolePty(bool& isPty) const
{
DoSrvIsConsolePty(pIsPty);
return TRUE;
DoSrvIsConsolePty(isPty);
return true;
}
BOOL ConhostInternalGetSet::DeleteLines(const unsigned int count)
bool ConhostInternalGetSet::DeleteLines(const size_t count)
{
DoSrvPrivateDeleteLines(count);
return TRUE;
return true;
}
BOOL ConhostInternalGetSet::InsertLines(const unsigned int count)
bool ConhostInternalGetSet::InsertLines(const size_t count)
{
DoSrvPrivateInsertLines(count);
return TRUE;
return true;
}
// Method Description:
@ -736,11 +754,11 @@ BOOL ConhostInternalGetSet::InsertLines(const unsigned int count)
// Arguments:
// <none>
// Return Value:
// - TRUE if successful (see DoSrvPrivateMoveToBottom). FALSE otherwise.
BOOL ConhostInternalGetSet::MoveToBottom() const
// - true if successful (see DoSrvPrivateMoveToBottom). false otherwise.
bool ConhostInternalGetSet::MoveToBottom() const
{
DoSrvPrivateMoveToBottom(_io.GetActiveOutputBuffer());
return TRUE;
return true;
}
// Method Description:
@ -750,8 +768,8 @@ BOOL ConhostInternalGetSet::MoveToBottom() const
// - index: the index in the table to change.
// - value: the new RGB value to use for that index in the color table.
// Return Value:
// - TRUE if successful (see DoSrvPrivateSetColorTableEntry). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateSetColorTableEntry(const short index, const COLORREF value) const noexcept
// - true if successful (see DoSrvPrivateSetColorTableEntry). false otherwise.
bool ConhostInternalGetSet::PrivateSetColorTableEntry(const short index, const COLORREF value) const noexcept
{
return SUCCEEDED(DoSrvPrivateSetColorTableEntry(index, value));
}
@ -762,8 +780,8 @@ BOOL ConhostInternalGetSet::PrivateSetColorTableEntry(const short index, const C
// Arguments:
// - value: the new RGB value to use, as a COLORREF, format 0x00BBGGRR.
// Return Value:
// - TRUE if successful (see DoSrvPrivateSetDefaultForegroundColor). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateSetDefaultForeground(const COLORREF value) const noexcept
// - true if successful (see DoSrvPrivateSetDefaultForegroundColor). false otherwise.
bool ConhostInternalGetSet::PrivateSetDefaultForeground(const COLORREF value) const noexcept
{
return SUCCEEDED(DoSrvPrivateSetDefaultForegroundColor(value));
}
@ -774,8 +792,8 @@ BOOL ConhostInternalGetSet::PrivateSetDefaultForeground(const COLORREF value) co
// Arguments:
// - value: the new RGB value to use, as a COLORREF, format 0x00BBGGRR.
// Return Value:
// - TRUE if successful (see DoSrvPrivateSetDefaultBackgroundColor). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateSetDefaultBackground(const COLORREF value) const noexcept
// - true if successful (see DoSrvPrivateSetDefaultBackgroundColor). false otherwise.
bool ConhostInternalGetSet::PrivateSetDefaultBackground(const COLORREF value) const noexcept
{
return SUCCEEDED(DoSrvPrivateSetDefaultBackgroundColor(value));
}
@ -793,8 +811,8 @@ BOOL ConhostInternalGetSet::PrivateSetDefaultBackground(const COLORREF value) co
// - standardFillAttrs - If true, fill with the standard erase attributes.
// If false, fill with the default attributes.
// Return value:
// - TRUE if successful (see DoSrvPrivateScrollRegion). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateFillRegion(const COORD startPosition,
// - true if successful (see DoSrvPrivateScrollRegion). false otherwise.
bool ConhostInternalGetSet::PrivateFillRegion(const COORD startPosition,
const size_t fillLength,
const wchar_t fillChar,
const bool standardFillAttrs) noexcept
@ -818,8 +836,8 @@ BOOL ConhostInternalGetSet::PrivateFillRegion(const COORD startPosition,
// - standardFillAttrs - If true, fill with the standard erase attributes.
// If false, fill with the default attributes.
// Return value:
// - TRUE if successful (see DoSrvPrivateScrollRegion). FALSE otherwise.
BOOL ConhostInternalGetSet::PrivateScrollRegion(const SMALL_RECT scrollRect,
// - true if successful (see DoSrvPrivateScrollRegion). false otherwise.
bool ConhostInternalGetSet::PrivateScrollRegion(const SMALL_RECT scrollRect,
const std::optional<SMALL_RECT> clipRect,
const COORD destinationOrigin,
const bool standardFillAttrs) noexcept

View file

@ -29,14 +29,14 @@ public:
// Implement Adapter callbacks for default cases (non-escape sequences)
void Print(const wchar_t wch) override;
void PrintString(const wchar_t* const rgwch, const size_t cch) override;
void PrintString(const std::wstring_view string) override;
void Execute(const wchar_t wch) override;
[[nodiscard]] NTSTATUS GetResult() { return _ntstatus; };
private:
void _DefaultCase(const wchar_t wch);
void _DefaultStringCase(_In_reads_(cch) const wchar_t* const rgwch, const size_t cch);
void _DefaultStringCase(const std::wstring_view string);
Microsoft::Console::IIoProvider& _io;
NTSTATUS _ntstatus;
@ -54,109 +54,109 @@ class ConhostInternalGetSet final : public Microsoft::Console::VirtualTerminal::
public:
ConhostInternalGetSet(_In_ Microsoft::Console::IIoProvider& io);
BOOL GetConsoleScreenBufferInfoEx(_Out_ CONSOLE_SCREEN_BUFFER_INFOEX* const pConsoleScreenBufferInfoEx) const override;
BOOL SetConsoleScreenBufferInfoEx(const CONSOLE_SCREEN_BUFFER_INFOEX* const pConsoleScreenBufferInfoEx) override;
bool GetConsoleScreenBufferInfoEx(CONSOLE_SCREEN_BUFFER_INFOEX& screenBufferInfo) const override;
bool SetConsoleScreenBufferInfoEx(const CONSOLE_SCREEN_BUFFER_INFOEX& screenBufferInfo) override;
BOOL SetConsoleCursorPosition(const COORD coordCursorPosition) override;
bool SetConsoleCursorPosition(const COORD position) override;
BOOL GetConsoleCursorInfo(_In_ CONSOLE_CURSOR_INFO* const pConsoleCursorInfo) const override;
BOOL SetConsoleCursorInfo(const CONSOLE_CURSOR_INFO* const pConsoleCursorInfo) override;
bool GetConsoleCursorInfo(CONSOLE_CURSOR_INFO& cursorInfo) const override;
bool SetConsoleCursorInfo(const CONSOLE_CURSOR_INFO& cursorInfo) override;
BOOL SetConsoleTextAttribute(const WORD wAttr) override;
bool SetConsoleTextAttribute(const WORD attr) override;
BOOL PrivateSetLegacyAttributes(const WORD wAttr,
const bool fForeground,
const bool fBackground,
const bool fMeta) override;
bool PrivateSetLegacyAttributes(const WORD attr,
const bool foreground,
const bool background,
const bool meta) override;
BOOL PrivateSetDefaultAttributes(const bool fForeground,
const bool fBackground) override;
bool PrivateSetDefaultAttributes(const bool foreground,
const bool background) override;
BOOL SetConsoleXtermTextAttribute(const int iXtermTableEntry,
const bool fIsForeground) override;
bool SetConsoleXtermTextAttribute(const int xtermTableEntry,
const bool isForeground) override;
BOOL SetConsoleRGBTextAttribute(const COLORREF rgbColor,
const bool fIsForeground) override;
bool SetConsoleRGBTextAttribute(const COLORREF rgbColor,
const bool isForeground) override;
BOOL PrivateBoldText(const bool bolded) override;
BOOL PrivateGetExtendedTextAttributes(ExtendedAttributes* const pAttrs) override;
BOOL PrivateSetExtendedTextAttributes(const ExtendedAttributes attrs) override;
BOOL PrivateGetTextAttributes(TextAttribute* const pAttrs) const override;
BOOL PrivateSetTextAttributes(const TextAttribute& attrs) override;
bool PrivateBoldText(const bool bolded) override;
bool PrivateGetExtendedTextAttributes(ExtendedAttributes& attrs) override;
bool PrivateSetExtendedTextAttributes(const ExtendedAttributes attrs) override;
bool PrivateGetTextAttributes(TextAttribute& attrs) const override;
bool PrivateSetTextAttributes(const TextAttribute& attrs) override;
BOOL PrivateWriteConsoleInputW(_Inout_ std::deque<std::unique_ptr<IInputEvent>>& events,
_Out_ size_t& eventsWritten) override;
bool PrivateWriteConsoleInputW(std::deque<std::unique_ptr<IInputEvent>>& events,
size_t& eventsWritten) override;
BOOL SetConsoleWindowInfo(BOOL const bAbsolute,
const SMALL_RECT* const lpConsoleWindow) override;
bool SetConsoleWindowInfo(bool const absolute,
const SMALL_RECT& window) override;
BOOL PrivateSetCursorKeysMode(const bool fApplicationMode) override;
BOOL PrivateSetKeypadMode(const bool fApplicationMode) override;
bool PrivateSetCursorKeysMode(const bool applicationMode) override;
bool PrivateSetKeypadMode(const bool applicationMode) override;
BOOL PrivateShowCursor(const bool show) noexcept override;
BOOL PrivateAllowCursorBlinking(const bool fEnable) override;
bool PrivateShowCursor(const bool show) noexcept override;
bool PrivateAllowCursorBlinking(const bool enable) override;
BOOL PrivateSetScrollingRegion(const SMALL_RECT* const srScrollMargins) override;
bool PrivateSetScrollingRegion(const SMALL_RECT& scrollMargins) override;
BOOL PrivateReverseLineFeed() override;
bool PrivateReverseLineFeed() override;
BOOL MoveCursorVertically(const short lines) override;
bool MoveCursorVertically(const ptrdiff_t lines) override;
BOOL SetConsoleTitleW(const std::wstring_view title) override;
bool SetConsoleTitleW(const std::wstring_view title) override;
BOOL PrivateUseAlternateScreenBuffer() override;
bool PrivateUseAlternateScreenBuffer() override;
BOOL PrivateUseMainScreenBuffer() override;
bool PrivateUseMainScreenBuffer() override;
BOOL PrivateHorizontalTabSet();
BOOL PrivateForwardTab(const SHORT sNumTabs) override;
BOOL PrivateBackwardsTab(const SHORT sNumTabs) override;
BOOL PrivateTabClear(const bool fClearAll) override;
BOOL PrivateSetDefaultTabStops() override;
bool PrivateHorizontalTabSet();
bool PrivateForwardTab(const size_t numTabs) override;
bool PrivateBackwardsTab(const size_t numTabs) override;
bool PrivateTabClear(const bool clearAll) override;
bool PrivateSetDefaultTabStops() override;
BOOL PrivateEnableVT200MouseMode(const bool fEnabled) override;
BOOL PrivateEnableUTF8ExtendedMouseMode(const bool fEnabled) override;
BOOL PrivateEnableSGRExtendedMouseMode(const bool fEnabled) override;
BOOL PrivateEnableButtonEventMouseMode(const bool fEnabled) override;
BOOL PrivateEnableAnyEventMouseMode(const bool fEnabled) override;
BOOL PrivateEnableAlternateScroll(const bool fEnabled) override;
BOOL PrivateEraseAll() override;
bool PrivateEnableVT200MouseMode(const bool enabled) override;
bool PrivateEnableUTF8ExtendedMouseMode(const bool enabled) override;
bool PrivateEnableSGRExtendedMouseMode(const bool enabled) override;
bool PrivateEnableButtonEventMouseMode(const bool enabled) override;
bool PrivateEnableAnyEventMouseMode(const bool enabled) override;
bool PrivateEnableAlternateScroll(const bool enabled) override;
bool PrivateEraseAll() override;
BOOL PrivateGetConsoleScreenBufferAttributes(_Out_ WORD* const pwAttributes) override;
bool PrivateGetConsoleScreenBufferAttributes(WORD& attributes) override;
BOOL PrivatePrependConsoleInput(_Inout_ std::deque<std::unique_ptr<IInputEvent>>& events,
_Out_ size_t& eventsWritten) override;
bool PrivatePrependConsoleInput(std::deque<std::unique_ptr<IInputEvent>>& events,
size_t& eventsWritten) override;
BOOL SetCursorStyle(CursorType const cursorType) override;
BOOL SetCursorColor(COLORREF const cursorColor) override;
bool SetCursorStyle(CursorType const style) override;
bool SetCursorColor(COLORREF const color) override;
BOOL PrivateRefreshWindow() override;
bool PrivateRefreshWindow() override;
BOOL PrivateSuppressResizeRepaint() override;
bool PrivateSuppressResizeRepaint() override;
BOOL PrivateWriteConsoleControlInput(_In_ KeyEvent key) override;
bool PrivateWriteConsoleControlInput(const KeyEvent key) override;
BOOL GetConsoleOutputCP(_Out_ unsigned int* const puiOutputCP) override;
bool GetConsoleOutputCP(unsigned int& codepage) override;
BOOL IsConsolePty(_Out_ bool* const pIsPty) const override;
bool IsConsolePty(bool& isPty) const override;
BOOL DeleteLines(const unsigned int count) override;
BOOL InsertLines(const unsigned int count) override;
bool DeleteLines(const size_t count) override;
bool InsertLines(const size_t count) override;
BOOL MoveToBottom() const override;
bool MoveToBottom() const override;
BOOL PrivateSetColorTableEntry(const short index, const COLORREF value) const noexcept override;
bool PrivateSetColorTableEntry(const short index, const COLORREF value) const noexcept override;
BOOL PrivateSetDefaultForeground(const COLORREF value) const noexcept override;
bool PrivateSetDefaultForeground(const COLORREF value) const noexcept override;
BOOL PrivateSetDefaultBackground(const COLORREF value) const noexcept override;
bool PrivateSetDefaultBackground(const COLORREF value) const noexcept override;
BOOL PrivateFillRegion(const COORD startPosition,
bool PrivateFillRegion(const COORD startPosition,
const size_t fillLength,
const wchar_t fillChar,
const bool standardFillAttrs) noexcept override;
BOOL PrivateScrollRegion(const SMALL_RECT scrollRect,
bool PrivateScrollRegion(const SMALL_RECT scrollRect,
const std::optional<SMALL_RECT> clipRect,
const COORD destinationOrigin,
const bool standardFillAttrs) noexcept override;

View file

@ -275,15 +275,14 @@ void SCREEN_INFORMATION::s_RemoveScreenBuffer(_In_ SCREEN_INFORMATION* const pSc
{
try
{
auto adapter = std::make_unique<AdaptDispatch>(new ConhostInternalGetSet{ *this },
new WriteBuffer{ *this });
THROW_IF_NULL_ALLOC(adapter.get());
auto getset = std::make_unique<ConhostInternalGetSet>(*this);
auto defaults = std::make_unique<WriteBuffer>(*this);
auto adapter = std::make_unique<AdaptDispatch>(std::move(getset), std::move(defaults));
auto engine = std::make_unique<OutputStateMachineEngine>(std::move(adapter));
// Note that at this point in the setup, we haven't determined if we're
// in VtIo mode or not yet. We'll set the OutputStateMachine's
// TerminalConnection later, in VtIo::StartIfNeeded
_stateMachine = std::make_shared<StateMachine>(new OutputStateMachineEngine(adapter.release()));
THROW_IF_NULL_ALLOC(_stateMachine.get());
_stateMachine = std::make_shared<StateMachine>(std::move(engine));
}
catch (...)
{
@ -2508,7 +2507,7 @@ void SCREEN_INFORMATION::SetViewport(const Viewport& newViewport,
// Method Description:
// - Sets up the Output state machine to be in pty mode. Sequences it doesn't
// understand will be written to tthe pTtyConnection passed in here.
// understand will be written to the pTtyConnection passed in here.
// Arguments:
// - pTtyConnection: This is a TerminaOutputConnection that we can write the
// sequence we didn't understand to.

View file

@ -341,7 +341,7 @@ void ScreenBufferTests::TestReverseLineFeed()
////////////////////////////////////////////////////////////////////////
Log::Comment(L"Case 1: RI from below top of viewport");
stateMachine.ProcessString(L"foo\nfoo", 7);
stateMachine.ProcessString(L"foo\nfoo");
VERIFY_ARE_EQUAL(cursor.GetPosition().X, 3);
VERIFY_ARE_EQUAL(cursor.GetPosition().Y, 1);
VERIFY_ARE_EQUAL(viewport.Top(), 0);
@ -362,7 +362,7 @@ void ScreenBufferTests::TestReverseLineFeed()
////////////////////////////////////////////////////////////////////////
Log::Comment(L"Case 2: RI from top of viewport");
cursor.SetPosition({ 0, 0 });
stateMachine.ProcessString(L"123456789", 9);
stateMachine.ProcessString(L"123456789");
VERIFY_ARE_EQUAL(cursor.GetPosition().X, 9);
VERIFY_ARE_EQUAL(cursor.GetPosition().Y, 0);
VERIFY_ARE_EQUAL(screenInfo.GetViewport().Top(), 0);
@ -762,7 +762,7 @@ void ScreenBufferTests::EraseAllTests()
////////////////////////////////////////////////////////////////////////
Log::Comment(L"Case 1: Erase a single line of text in the buffer\n");
stateMachine.ProcessString(L"foo", 3);
stateMachine.ProcessString(L"foo");
COORD originalRelativePosition = { 3, 0 };
VERIFY_ARE_EQUAL(si.GetViewport().Top(), 0);
VERIFY_ARE_EQUAL(cursor.GetPosition(), originalRelativePosition);
@ -784,7 +784,7 @@ void ScreenBufferTests::EraseAllTests()
////////////////////////////////////////////////////////////////////////
Log::Comment(L"Case 2: Erase multiple lines, below the top of the buffer\n");
stateMachine.ProcessString(L"bar\nbar\nbar", 11);
stateMachine.ProcessString(L"bar\nbar\nbar");
viewport = si._viewport;
originalRelativePosition = cursor.GetPosition();
viewport.ConvertToOrigin(&originalRelativePosition);
@ -814,7 +814,7 @@ void ScreenBufferTests::EraseAllTests()
cursor.SetPosition({ 0, 275 });
VERIFY_SUCCEEDED(si.SetViewportOrigin(true, { 0, 220 }, true));
stateMachine.ProcessString(L"bar\nbar\nbar", 11);
stateMachine.ProcessString(L"bar\nbar\nbar");
viewport = si._viewport;
VERIFY_ARE_EQUAL(cursor.GetPosition().X, 3);
VERIFY_ARE_EQUAL(cursor.GetPosition().Y, 277);
@ -855,19 +855,19 @@ void ScreenBufferTests::OutputNULTest()
Log::Comment(NoThrowString().Format(
L"Writing a single NUL"));
stateMachine.ProcessString(L"\0", 1);
stateMachine.ProcessString({ L"\0", 1 });
VERIFY_ARE_EQUAL(0, cursor.GetPosition().X);
VERIFY_ARE_EQUAL(0, cursor.GetPosition().Y);
Log::Comment(NoThrowString().Format(
L"Writing many NULs"));
stateMachine.ProcessString(L"\0\0\0\0\0\0\0\0", 8);
stateMachine.ProcessString({ L"\0\0\0\0\0\0\0\0", 8 });
VERIFY_ARE_EQUAL(0, cursor.GetPosition().X);
VERIFY_ARE_EQUAL(0, cursor.GetPosition().Y);
Log::Comment(NoThrowString().Format(
L"Testing a single NUL followed by real text"));
stateMachine.ProcessString(L"\0foo", 4);
stateMachine.ProcessString({ L"\0foo", 4 });
VERIFY_ARE_EQUAL(3, cursor.GetPosition().X);
VERIFY_ARE_EQUAL(0, cursor.GetPosition().Y);
@ -877,7 +877,7 @@ void ScreenBufferTests::OutputNULTest()
Log::Comment(NoThrowString().Format(
L"Writing NULs in between other strings"));
stateMachine.ProcessString(L"\0foo\0bar\0", 9);
stateMachine.ProcessString({ L"\0foo\0bar\0", 9 });
VERIFY_ARE_EQUAL(6, cursor.GetPosition().X);
VERIFY_ARE_EQUAL(1, cursor.GetPosition().Y);
}
@ -909,8 +909,7 @@ void ScreenBufferTests::VtResize()
L" The Screen buffer height should remain unchanged, but the width should be 80 columns"
L" The viewport should be w,h=80,30"));
std::wstring sequence = L"\x1b[8;30;80t";
stateMachine.ProcessString(&sequence[0], sequence.length());
stateMachine.ProcessString(L"\x1b[8;30;80t");
auto newSbHeight = si.GetBufferSize().Height();
auto newSbWidth = si.GetBufferSize().Width();
@ -932,8 +931,7 @@ void ScreenBufferTests::VtResize()
L" The Screen buffer height should remain unchanged, but the width should be 80 columns"
L" The viewport should be w,h=80,40"));
sequence = L"\x1b[8;40;80t";
stateMachine.ProcessString(&sequence[0], sequence.length());
stateMachine.ProcessString(L"\x1b[8;40;80t");
newSbHeight = si.GetBufferSize().Height();
newSbWidth = si.GetBufferSize().Width();
@ -955,8 +953,7 @@ void ScreenBufferTests::VtResize()
L" The Screen buffer height should remain unchanged, but the width should be 90 columns"
L" The viewport should be w,h=90,40"));
sequence = L"\x1b[8;40;90t";
stateMachine.ProcessString(&sequence[0], sequence.length());
stateMachine.ProcessString(L"\x1b[8;40;90t");
newSbHeight = si.GetBufferSize().Height();
newSbWidth = si.GetBufferSize().Width();
@ -978,8 +975,7 @@ void ScreenBufferTests::VtResize()
L" The Screen buffer height should remain unchanged, but the width should be 12 columns"
L" The viewport should be w,h=12,12"));
sequence = L"\x1b[8;12;12t";
stateMachine.ProcessString(&sequence[0], sequence.length());
stateMachine.ProcessString(L"\x1b[8;12;12t");
newSbHeight = si.GetBufferSize().Height();
newSbWidth = si.GetBufferSize().Width();
@ -1000,8 +996,7 @@ void ScreenBufferTests::VtResize()
L"Write '\x1b[8;0;0t'"
L" Nothing should change"));
sequence = L"\x1b[8;0;0t";
stateMachine.ProcessString(&sequence[0], sequence.length());
stateMachine.ProcessString(L"\x1b[8;0;0t");
newSbHeight = si.GetBufferSize().Height();
newSbWidth = si.GetBufferSize().Width();
@ -1054,8 +1049,7 @@ void ScreenBufferTests::VtResizeComprehensive()
expectedViewWidth,
expectedViewHeight));
std::wstring sequence = ss.str();
stateMachine.ProcessString(sequence);
stateMachine.ProcessString(ss.str());
auto newViewHeight = si.GetViewport().Height();
auto newViewWidth = si.GetViewport().Width();
@ -1210,29 +1204,24 @@ void ScreenBufferTests::VtSoftResetCursorPosition()
L"Move the cursor to 2,2, then execute a soft reset.\n"
L"The cursor should not move."));
std::wstring seq = L"\x1b[2;2H";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b[2;2H");
VERIFY_ARE_EQUAL(COORD({ 1, 1 }), cursor.GetPosition());
seq = L"\x1b[!p";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b[!p");
VERIFY_ARE_EQUAL(COORD({ 1, 1 }), cursor.GetPosition());
Log::Comment(NoThrowString().Format(
L"Set some margins. The cursor should move home."));
seq = L"\x1b[2;10r";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b[2;10r");
VERIFY_ARE_EQUAL(COORD({ 0, 0 }), cursor.GetPosition());
Log::Comment(NoThrowString().Format(
L"Move the cursor to 2,2, then execute a soft reset.\n"
L"The cursor should not move, even though there are margins."));
seq = L"\x1b[2;2H";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b[2;2H");
VERIFY_ARE_EQUAL(COORD({ 1, 1 }), cursor.GetPosition());
seq = L"\x1b[!p";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b[!p");
VERIFY_ARE_EQUAL(COORD({ 1, 1 }), cursor.GetPosition());
Log::Comment(
@ -1273,16 +1262,13 @@ void ScreenBufferTests::VtScrollMarginsNewlineColor()
Log::Comment(NoThrowString().Format(L"Begin by clearing the screen."));
std::wstring seq = L"\x1b[2J";
stateMachine.ProcessString(seq);
seq = L"\x1b[m";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b[2J");
stateMachine.ProcessString(L"\x1b[m");
Log::Comment(NoThrowString().Format(
L"Set the margins to 2, 5, then emit 10 'X\\n' strings. "
L"Each time, check that rows 0-10 have default attributes in their entire row."));
seq = L"\x1b[2;5r";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b[2;5r");
// Make sure we clear the margins to not screw up another test.
auto clearMargins = wil::scope_exit([&] { stateMachine.ProcessString(L"\x1b[r"); });
@ -1290,10 +1276,8 @@ void ScreenBufferTests::VtScrollMarginsNewlineColor()
{
Log::Comment(NoThrowString().Format(
L"Iteration:%d", iteration));
seq = L"X";
stateMachine.ProcessString(seq);
seq = L"\n";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"X");
stateMachine.ProcessString(L"\n");
const COORD cursorPos = cursor.GetPosition();
@ -1339,10 +1323,8 @@ void ScreenBufferTests::VtNewlinePastViewport()
VERIFY_SUCCEEDED(si.SetViewportOrigin(true, COORD({ 0, 0 }), true));
cursor.SetPosition(COORD({ 0, 0 }));
std::wstring seq = L"\x1b[m";
stateMachine.ProcessString(seq);
seq = L"\x1b[2J";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b[m");
stateMachine.ProcessString(L"\x1b[2J");
const TextAttribute defaultAttrs{};
@ -1365,8 +1347,7 @@ void ScreenBufferTests::VtNewlinePastViewport()
auto expectedFillAttr = fillAttr;
expectedFillAttr.SetStandardErase();
seq = L"\n";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\n");
const auto viewport = si.GetViewport();
Log::Comment(NoThrowString().Format(
@ -1415,10 +1396,8 @@ void ScreenBufferTests::VtNewlinePastEndOfBuffer()
VERIFY_SUCCEEDED(si.SetViewportOrigin(true, COORD({ 0, 0 }), true));
cursor.SetPosition(COORD({ 0, 0 }));
std::wstring seq = L"\x1b[m";
stateMachine.ProcessString(seq);
seq = L"\x1b[2J";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b[m");
stateMachine.ProcessString(L"\x1b[2J");
const TextAttribute defaultAttrs{};
@ -1444,8 +1423,7 @@ void ScreenBufferTests::VtNewlinePastEndOfBuffer()
auto expectedFillAttr = fillAttr;
expectedFillAttr.SetStandardErase();
seq = L"\n";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\n");
const auto viewport = si.GetViewport();
Log::Comment(NoThrowString().Format(
@ -1521,96 +1499,79 @@ void ScreenBufferTests::VtSetColorTable()
Log::Comment(NoThrowString().Format(
L"Process some valid sequences for setting the table"));
std::wstring seq = L"\x1b]4;0;rgb:1/1/1\x7";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b]4;0;rgb:1/1/1\x7");
VERIFY_ARE_EQUAL(RGB(1, 1, 1), gci.GetColorTableEntry(::XtermToWindowsIndex(0)));
seq = L"\x1b]4;1;rgb:1/23/1\x7";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b]4;1;rgb:1/23/1\x7");
VERIFY_ARE_EQUAL(RGB(1, 0x23, 1), gci.GetColorTableEntry(::XtermToWindowsIndex(1)));
seq = L"\x1b]4;2;rgb:1/23/12\x7";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b]4;2;rgb:1/23/12\x7");
VERIFY_ARE_EQUAL(RGB(1, 0x23, 0x12), gci.GetColorTableEntry(::XtermToWindowsIndex(2)));
seq = L"\x1b]4;3;rgb:12/23/12\x7";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b]4;3;rgb:12/23/12\x7");
VERIFY_ARE_EQUAL(RGB(0x12, 0x23, 0x12), gci.GetColorTableEntry(::XtermToWindowsIndex(3)));
seq = L"\x1b]4;4;rgb:ff/a1/1b\x7";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b]4;4;rgb:ff/a1/1b\x7");
VERIFY_ARE_EQUAL(RGB(0xff, 0xa1, 0x1b), gci.GetColorTableEntry(::XtermToWindowsIndex(4)));
seq = L"\x1b]4;5;rgb:ff/a1/1b\x1b\\";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b]4;5;rgb:ff/a1/1b\x1b\\");
VERIFY_ARE_EQUAL(RGB(0xff, 0xa1, 0x1b), gci.GetColorTableEntry(::XtermToWindowsIndex(5)));
Log::Comment(NoThrowString().Format(
L"Try a bunch of invalid sequences."));
Log::Comment(NoThrowString().Format(
L"First start by setting an entry to a known value to compare to."));
seq = L"\x1b]4;5;rgb:9/9/9\x1b\\";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b]4;5;rgb:9/9/9\x1b\\");
VERIFY_ARE_EQUAL(RGB(9, 9, 9), gci.GetColorTableEntry(::XtermToWindowsIndex(5)));
Log::Comment(NoThrowString().Format(
L"invalid: Missing the first component"));
seq = L"\x1b]4;5;rgb:/1/1\x1b\\";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b]4;5;rgb:/1/1\x1b\\");
VERIFY_ARE_EQUAL(RGB(9, 9, 9), gci.GetColorTableEntry(::XtermToWindowsIndex(5)));
Log::Comment(NoThrowString().Format(
L"invalid: too many characters in a component"));
seq = L"\x1b]4;5;rgb:111/1/1\x1b\\";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b]4;5;rgb:111/1/1\x1b\\");
VERIFY_ARE_EQUAL(RGB(9, 9, 9), gci.GetColorTableEntry(::XtermToWindowsIndex(5)));
Log::Comment(NoThrowString().Format(
L"invalid: too many componenets"));
seq = L"\x1b]4;5;rgb:1/1/1/1\x1b\\";
stateMachine.ProcessString(&seq[0], seq.length());
L"invalid: too many components"));
stateMachine.ProcessString(L"\x1b]4;5;rgb:1/1/1/1\x1b\\");
VERIFY_ARE_EQUAL(RGB(9, 9, 9), gci.GetColorTableEntry(::XtermToWindowsIndex(5)));
Log::Comment(NoThrowString().Format(
L"invalid: no second component"));
seq = L"\x1b]4;5;rgb:1//1\x1b\\";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b]4;5;rgb:1//1\x1b\\");
VERIFY_ARE_EQUAL(RGB(9, 9, 9), gci.GetColorTableEntry(::XtermToWindowsIndex(5)));
Log::Comment(NoThrowString().Format(
L"invalid: no components"));
seq = L"\x1b]4;5;rgb://\x1b\\";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b]4;5;rgb://\x1b\\");
VERIFY_ARE_EQUAL(RGB(9, 9, 9), gci.GetColorTableEntry(::XtermToWindowsIndex(5)));
Log::Comment(NoThrowString().Format(
L"invalid: no third component"));
seq = L"\x1b]4;5;rgb:1/11/\x1b\\";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b]4;5;rgb:1/11/\x1b\\");
VERIFY_ARE_EQUAL(RGB(9, 9, 9), gci.GetColorTableEntry(::XtermToWindowsIndex(5)));
Log::Comment(NoThrowString().Format(
L"invalid: rgbi is not a supported color space"));
seq = L"\x1b]4;5;rgbi:1/1/1\x1b\\";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b]4;5;rgbi:1/1/1\x1b\\");
VERIFY_ARE_EQUAL(RGB(9, 9, 9), gci.GetColorTableEntry(::XtermToWindowsIndex(5)));
Log::Comment(NoThrowString().Format(
L"invalid: cmyk is not a supported color space"));
seq = L"\x1b]4;5;cmyk:1/1/1\x1b\\";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b]4;5;cmyk:1/1/1\x1b\\");
VERIFY_ARE_EQUAL(RGB(9, 9, 9), gci.GetColorTableEntry(::XtermToWindowsIndex(5)));
Log::Comment(NoThrowString().Format(
L"invalid: no table index should do nothing"));
seq = L"\x1b]4;;rgb:1/1/1\x1b\\";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b]4;;rgb:1/1/1\x1b\\");
VERIFY_ARE_EQUAL(RGB(9, 9, 9), gci.GetColorTableEntry(::XtermToWindowsIndex(5)));
Log::Comment(NoThrowString().Format(
L"invalid: need to specify a color space"));
seq = L"\x1b]4;5;1/1/1\x1b\\";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b]4;5;1/1/1\x1b\\");
VERIFY_ARE_EQUAL(RGB(9, 9, 9), gci.GetColorTableEntry(::XtermToWindowsIndex(5)));
}
@ -1690,8 +1651,7 @@ void ScreenBufferTests::ResizeAltBuffer()
Log::Comment(NoThrowString().Format(
L"Switch to alt buffer"));
std::wstring seq = L"\x1b[?1049h";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b[?1049h");
VERIFY_IS_FALSE(si._IsAltBuffer());
VERIFY_IS_NOT_NULL(si._psiAlternateBuffer);
@ -1708,8 +1668,7 @@ void ScreenBufferTests::ResizeAltBuffer()
Log::Comment(NoThrowString().Format(
L"Switch back from buffer"));
seq = L"\x1b[?1049l";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b[?1049l");
VERIFY_IS_FALSE(si._IsAltBuffer());
VERIFY_IS_NULL(si._psiAlternateBuffer);
}
@ -1744,8 +1703,7 @@ void ScreenBufferTests::ResizeAltBufferGetScreenBufferInfo()
Log::Comment(NoThrowString().Format(
L"Switch to alt buffer"));
std::wstring seq = L"\x1b[?1049h";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b[?1049h");
VERIFY_IS_FALSE(mainBuffer._IsAltBuffer());
VERIFY_IS_NOT_NULL(mainBuffer._psiAlternateBuffer);
@ -1797,12 +1755,10 @@ void ScreenBufferTests::VtEraseAllPersistCursor()
L"Move the cursor to 2,2, then execute a Erase All.\n"
L"The cursor should not move relative to the viewport."));
std::wstring seq = L"\x1b[2;2H";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b[2;2H");
VERIFY_ARE_EQUAL(COORD({ 1, 1 }), cursor.GetPosition());
seq = L"\x1b[2J";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b[2J");
auto newViewport = si._viewport;
COORD expectedCursor = { 1, 1 };
@ -1827,13 +1783,11 @@ void ScreenBufferTests::VtEraseAllPersistCursorFillColor()
L"The viewport should be full of dark_red on bright_blue"));
auto expectedAttr = TextAttribute(XtermToLegacy(1, 12));
std::wstring seq = L"\x1b[31;104m";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b[31;104m");
VERIFY_ARE_EQUAL(expectedAttr, si.GetAttributes());
seq = L"\x1b[2J";
stateMachine.ProcessString(&seq[0], seq.length());
stateMachine.ProcessString(L"\x1b[2J");
VERIFY_ARE_EQUAL(expectedAttr, si.GetAttributes());
@ -2165,35 +2119,23 @@ void ScreenBufferTests::SetDefaultsIndividuallyBothDefault()
Log::Comment(NoThrowString().Format(L" The fifth with bright-green on dark-blue"));
Log::Comment(NoThrowString().Format(L" The sixth with bright-green on default-bg"));
std::wstring seq = L"\x1b[m"; // Reset to defaults
stateMachine.ProcessString(seq);
seq = L"X";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b[m"); // Reset to defaults
stateMachine.ProcessString(L"X");
seq = L"\x1b[92;44m"; // bright-green on dark-blue
stateMachine.ProcessString(seq);
seq = L"X";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b[92;44m"); // bright-green on dark-blue
stateMachine.ProcessString(L"X");
seq = L"\x1b[39m"; // reset fg
stateMachine.ProcessString(seq);
seq = L"X";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b[39m"); // reset fg
stateMachine.ProcessString(L"X");
seq = L"\x1b[49m"; // reset bg
stateMachine.ProcessString(seq);
seq = L"X";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b[49m"); // reset bg
stateMachine.ProcessString(L"X");
seq = L"\x1b[92;44m"; // bright-green on dark-blue
stateMachine.ProcessString(seq);
seq = L"X";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b[92;44m"); // bright-green on dark-blue
stateMachine.ProcessString(L"X");
seq = L"\x1b[49m"; // reset bg
stateMachine.ProcessString(seq);
seq = L"X";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b[49m"); // reset bg
stateMachine.ProcessString(L"X");
// See the log comment above for description of these values.
TextAttribute expectedDefaults{};
@ -2356,16 +2298,11 @@ void ScreenBufferTests::ReverseResetWithDefaultBackground()
Log::Comment(NoThrowString().Format(L" The second with reversed attrs"));
Log::Comment(NoThrowString().Format(L" The third after resetting the attrs back"));
std::wstring seq = L"X";
stateMachine.ProcessString(seq);
seq = L"\x1b[7m";
stateMachine.ProcessString(seq);
seq = L"X";
stateMachine.ProcessString(seq);
seq = L"\x1b[27m";
stateMachine.ProcessString(seq);
seq = L"X";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"X");
stateMachine.ProcessString(L"\x1b[7m");
stateMachine.ProcessString(L"X");
stateMachine.ProcessString(L"\x1b[27m");
stateMachine.ProcessString(L"X");
TextAttribute expectedDefaults{ gci.GetFillAttribute() };
expectedDefaults.SetDefaultBackground();
@ -2426,13 +2363,9 @@ void ScreenBufferTests::BackspaceDefaultAttrs()
Log::Comment(NoThrowString().Format(L"Write 2 X's, then backspace one."));
std::wstring seq = L"\x1b[m";
stateMachine.ProcessString(seq);
seq = L"XX";
stateMachine.ProcessString(seq);
seq = UNICODE_BACKSPACE;
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b[m");
stateMachine.ProcessString(L"XX");
stateMachine.ProcessString({ &UNICODE_BACKSPACE, 1 });
TextAttribute expectedDefaults{};
expectedDefaults.SetDefaultBackground();
@ -2493,8 +2426,7 @@ void ScreenBufferTests::BackspaceDefaultAttrsWriteCharsLegacy()
Log::Comment(NoThrowString().Format(L"Write 2 X's, then backspace one."));
std::wstring seq = L"\x1b[m";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b[m");
if (writeSingly)
{
@ -2564,12 +2496,10 @@ void ScreenBufferTests::BackspaceDefaultAttrsInPrompt()
Log::Comment(NoThrowString().Format(L"Write 3 X's, move to the left, then delete-char the second."));
Log::Comment(NoThrowString().Format(L"This emulates editing the prompt line on bash"));
std::wstring seq = L"\x1b[m";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b[m");
Log::Comment(NoThrowString().Format(
L"Clear the screen - make sure the line is filled with the current attributes."));
seq = L"\x1b[2J";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b[2J");
const auto viewport = si.GetViewport();
const ROW& row = tbi.GetRowByOffset(cursor.GetPosition().Y);
@ -2591,12 +2521,9 @@ void ScreenBufferTests::BackspaceDefaultAttrsInPrompt()
Log::Comment(NoThrowString().Format(
L"Print 'XXX', move the cursor left 2, delete a character."));
seq = L"XXX";
stateMachine.ProcessString(seq);
seq = L"\x1b[2D";
stateMachine.ProcessString(seq);
seq = L"\x1b[P";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"XXX");
stateMachine.ProcessString(L"\x1b[2D");
stateMachine.ProcessString(L"\x1b[P");
COORD expectedCursor{ 1, 1 }; // We're expecting y=1, because the 2J above
// should have moved the viewport down a line.
@ -2639,10 +2566,8 @@ void ScreenBufferTests::SetGlobalColorTable()
const COLORREF testColor = RGB(0x11, 0x22, 0x33);
VERIFY_ARE_NOT_EQUAL(originalRed, testColor);
std::wstring seq = L"\x1b[41m";
stateMachine.ProcessString(seq);
seq = L"X";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b[41m");
stateMachine.ProcessString(L"X");
COORD expectedCursor{ 1, 0 };
VERIFY_ARE_EQUAL(expectedCursor, mainCursor.GetPosition());
{
@ -2668,10 +2593,8 @@ void ScreenBufferTests::SetGlobalColorTable()
Log::Comment(NoThrowString().Format(
L"Print one X in red, should be the original red color"));
seq = L"\x1b[41m";
stateMachine.ProcessString(seq);
seq = L"X";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b[41m");
stateMachine.ProcessString(L"X");
VERIFY_ARE_EQUAL(expectedCursor, altCursor.GetPosition());
{
const ROW& row = altBuffer.GetTextBuffer().GetRowByOffset(altCursor.GetPosition().Y);
@ -2683,12 +2606,10 @@ void ScreenBufferTests::SetGlobalColorTable()
}
Log::Comment(NoThrowString().Format(L"Change the value of red to RGB(0x11, 0x22, 0x33)"));
seq = L"\x1b]4;1;rgb:11/22/33\x07";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b]4;1;rgb:11/22/33\x07");
Log::Comment(NoThrowString().Format(
L"Print another X, both should be the new \"red\" color"));
seq = L"X";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"X");
VERIFY_ARE_EQUAL(COORD({ 2, 0 }), altCursor.GetPosition());
{
const ROW& row = altBuffer.GetTextBuffer().GetRowByOffset(altCursor.GetPosition().Y);
@ -2711,8 +2632,7 @@ void ScreenBufferTests::SetGlobalColorTable()
Log::Comment(NoThrowString().Format(
L"Print another X, both should be the new \"red\" color"));
seq = L"X";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"X");
VERIFY_ARE_EQUAL(COORD({ 2, 0 }), mainCursor.GetPosition());
{
const ROW& row = mainBuffer.GetTextBuffer().GetRowByOffset(mainCursor.GetPosition().Y);
@ -2752,10 +2672,8 @@ void ScreenBufferTests::SetColorTableThreeDigits()
const COLORREF testColor = RGB(0x11, 0x22, 0x33);
VERIFY_ARE_NOT_EQUAL(originalRed, testColor);
std::wstring seq = L"\x1b[48;5;123m";
stateMachine.ProcessString(seq);
seq = L"X";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b[48;5;123m");
stateMachine.ProcessString(L"X");
COORD expectedCursor{ 1, 0 };
VERIFY_ARE_EQUAL(expectedCursor, mainCursor.GetPosition());
{
@ -2781,10 +2699,8 @@ void ScreenBufferTests::SetColorTableThreeDigits()
Log::Comment(NoThrowString().Format(
L"Print one X in red, should be the original red color"));
seq = L"\x1b[48;5;123m";
stateMachine.ProcessString(seq);
seq = L"X";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b[48;5;123m");
stateMachine.ProcessString(L"X");
VERIFY_ARE_EQUAL(expectedCursor, altCursor.GetPosition());
{
const ROW& row = altBuffer.GetTextBuffer().GetRowByOffset(altCursor.GetPosition().Y);
@ -2796,16 +2712,13 @@ void ScreenBufferTests::SetColorTableThreeDigits()
}
Log::Comment(NoThrowString().Format(L"Change the value of red to RGB(0x11, 0x22, 0x33)"));
seq = L"\x1b]4;123;rgb:11/22/33\x07";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b]4;123;rgb:11/22/33\x07");
Log::Comment(NoThrowString().Format(
L"Print another X, it should be the new \"red\" color"));
// TODO MSFT:20105972 -
// You shouldn't need to manually update the attributes again.
seq = L"\x1b[48;5;123m";
stateMachine.ProcessString(seq);
seq = L"X";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b[48;5;123m");
stateMachine.ProcessString(L"X");
VERIFY_ARE_EQUAL(COORD({ 2, 0 }), altCursor.GetPosition());
{
const ROW& row = altBuffer.GetTextBuffer().GetRowByOffset(altCursor.GetPosition().Y);
@ -2839,8 +2752,7 @@ void ScreenBufferTests::SetDefaultForegroundColor()
VERIFY_ARE_NOT_EQUAL(originalColor, testColor);
Log::Comment(L"Valid Hexadecimal Notation");
std::wstring seq = L"\x1b]10;rgb:33/66/99\x1b\\";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b]10;rgb:33/66/99\x1b\\");
newColor = gci.GetDefaultForegroundColor();
VERIFY_ARE_EQUAL(testColor, newColor);
@ -2848,8 +2760,7 @@ void ScreenBufferTests::SetDefaultForegroundColor()
Log::Comment(L"Valid Hexadecimal Notation");
originalColor = newColor;
testColor = RGB(0xff, 0xff, 0xff);
seq = L"\x1b]10;rgb:ff/ff/ff\x1b\\";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b]10;rgb:ff/ff/ff\x1b\\");
newColor = gci.GetDefaultForegroundColor();
VERIFY_ARE_EQUAL(testColor, newColor);
@ -2857,8 +2768,7 @@ void ScreenBufferTests::SetDefaultForegroundColor()
Log::Comment(L"Invalid Decimal Notation");
originalColor = newColor;
testColor = RGB(153, 102, 51);
seq = L"\x1b]10;rgb:153/102/51\x1b\\";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b]10;rgb:153/102/51\x1b\\");
newColor = gci.GetDefaultForegroundColor();
VERIFY_ARE_NOT_EQUAL(testColor, newColor);
@ -2867,8 +2777,7 @@ void ScreenBufferTests::SetDefaultForegroundColor()
Log::Comment(L"Invalid syntax");
testColor = RGB(153, 102, 51);
seq = L"\x1b]10;99/66/33\x1b\\";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b]10;99/66/33\x1b\\");
newColor = gci.GetDefaultForegroundColor();
VERIFY_ARE_NOT_EQUAL(testColor, newColor);
@ -2897,8 +2806,7 @@ void ScreenBufferTests::SetDefaultBackgroundColor()
VERIFY_ARE_NOT_EQUAL(originalColor, testColor);
Log::Comment(L"Valid Hexadecimal Notation");
std::wstring seq = L"\x1b]11;rgb:33/66/99\x1b\\";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b]11;rgb:33/66/99\x1b\\");
newColor = gci.GetDefaultBackgroundColor();
VERIFY_ARE_EQUAL(testColor, newColor);
@ -2906,8 +2814,7 @@ void ScreenBufferTests::SetDefaultBackgroundColor()
Log::Comment(L"Valid Hexadecimal Notation");
originalColor = newColor;
testColor = RGB(0xff, 0xff, 0xff);
seq = L"\x1b]11;rgb:ff/ff/ff\x1b\\";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b]11;rgb:ff/ff/ff\x1b\\");
newColor = gci.GetDefaultBackgroundColor();
VERIFY_ARE_EQUAL(testColor, newColor);
@ -2915,8 +2822,7 @@ void ScreenBufferTests::SetDefaultBackgroundColor()
Log::Comment(L"Invalid Decimal Notation");
originalColor = newColor;
testColor = RGB(153, 102, 51);
seq = L"\x1b]11;rgb:153/102/51\x1b\\";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b]11;rgb:153/102/51\x1b\\");
newColor = gci.GetDefaultBackgroundColor();
VERIFY_ARE_NOT_EQUAL(testColor, newColor);
@ -2925,8 +2831,7 @@ void ScreenBufferTests::SetDefaultBackgroundColor()
Log::Comment(L"Invalid Syntax");
testColor = RGB(153, 102, 51);
seq = L"\x1b]11;99/66/33\x1b\\";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b]11;99/66/33\x1b\\");
newColor = gci.GetDefaultBackgroundColor();
VERIFY_ARE_NOT_EQUAL(testColor, newColor);
@ -2995,10 +2900,9 @@ void ScreenBufferTests::DeleteCharsNearEndOfLine()
VERIFY_ARE_EQUAL(mainBuffer.GetBufferSize().Width(), mainView.Width());
VERIFY_IS_GREATER_THAN(mainView.Width(), (dx + numCharsToDelete));
std::wstring seq = L"X";
for (int x = 0; x < mainView.Width(); x++)
{
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"X");
}
VERIFY_ARE_EQUAL(COORD({ mainView.Width() - 1, 0 }), mainCursor.GetPosition());
@ -3009,9 +2913,8 @@ void ScreenBufferTests::DeleteCharsNearEndOfLine()
mainCursor.SetPosition({ mainView.Width() - static_cast<short>(dx), 0 });
std::wstringstream ss;
ss << L"\x1b[" << numCharsToDelete << L"P";
seq = ss.str(); // Delete N chars
stateMachine.ProcessString(seq);
ss << L"\x1b[" << numCharsToDelete << L"P"; // Delete N chars
stateMachine.ProcessString(ss.str());
Log::Comment(NoThrowString().Format(
L"row_f=[%s]",
@ -3066,8 +2969,7 @@ void ScreenBufferTests::DeleteCharsNearEndOfLineSimpleFirstCase()
VERIFY_ARE_EQUAL(newBufferWidth, mainView.Width());
VERIFY_ARE_EQUAL(mainBuffer.GetBufferSize().Width(), mainView.Width());
std::wstring seq = L"ABCDEFG";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"ABCDEFG");
VERIFY_ARE_EQUAL(COORD({ 7, 0 }), mainCursor.GetPosition());
// Place the cursor on the 'D'
@ -3077,8 +2979,7 @@ void ScreenBufferTests::DeleteCharsNearEndOfLineSimpleFirstCase()
// Delete 3 chars - [D, E, F]
std::wstringstream ss;
ss << L"\x1b[" << 3 << L"P";
seq = ss.str();
stateMachine.ProcessString(seq);
stateMachine.ProcessString(ss.str());
Log::Comment(NoThrowString().Format(L"after =[%s]", tbi.GetRowByOffset(0).GetText().c_str()));
@ -3128,8 +3029,7 @@ void ScreenBufferTests::DeleteCharsNearEndOfLineSimpleSecondCase()
VERIFY_ARE_EQUAL(newBufferWidth, mainView.Width());
VERIFY_ARE_EQUAL(mainBuffer.GetBufferSize().Width(), mainView.Width());
std::wstring seq = L"ABCDEFG";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"ABCDEFG");
VERIFY_ARE_EQUAL(COORD({ 7, 0 }), mainCursor.GetPosition());
@ -3141,8 +3041,7 @@ void ScreenBufferTests::DeleteCharsNearEndOfLineSimpleSecondCase()
// Delete 4 chars - [C, D, E, F]
std::wstringstream ss;
ss << L"\x1b[" << 4 << L"P";
seq = ss.str();
stateMachine.ProcessString(seq);
stateMachine.ProcessString(ss.str());
Log::Comment(NoThrowString().Format(L"after =[%s]", tbi.GetRowByOffset(0).GetText().c_str()));
@ -4030,17 +3929,12 @@ void _CommonScrollingSetup()
const auto view = Viewport::FromDimensions({ 0, 0 }, { oldView.Width(), 6 });
si.SetViewport(view, true);
cursor.SetPosition({ 0, 0 });
std::wstring seq = L"A";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"A");
cursor.SetPosition({ 0, 5 });
seq = L"B";
stateMachine.ProcessString(seq);
seq = L"\x1b[2;5r";
stateMachine.ProcessString(seq);
seq = L"\x1b[2;1H";
stateMachine.ProcessString(seq);
seq = L"1\n2\n3\n4";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"B");
stateMachine.ProcessString(L"\x1b[2;5r");
stateMachine.ProcessString(L"\x1b[2;1H");
stateMachine.ProcessString(L"1\n2\n3\n4");
Log::Comment(NoThrowString().Format(
L"cursor=%s", VerifyOutputTraits<COORD>::ToString(cursor.GetPosition()).GetBuffer()));
@ -4064,8 +3958,7 @@ void _CommonScrollingSetup()
VERIFY_ARE_EQUAL(L"B", iter5->Chars());
}
seq = L"\n5\n6\n7\n";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\n5\n6\n7\n");
Log::Comment(NoThrowString().Format(
L"cursor=%s", VerifyOutputTraits<COORD>::ToString(cursor.GetPosition()).GetBuffer()));
@ -4105,8 +3998,7 @@ void ScreenBufferTests::ScrollUpInMargins()
auto& cursor = si.GetTextBuffer().GetCursor();
// Execute a Scroll Up command
std::wstring seq = L"\x1b[S";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b[S");
Log::Comment(NoThrowString().Format(
L"cursor=%s", VerifyOutputTraits<COORD>::ToString(cursor.GetPosition()).GetBuffer()));
@ -4145,8 +4037,7 @@ void ScreenBufferTests::ScrollDownInMargins()
auto& cursor = si.GetTextBuffer().GetCursor();
// Execute a Scroll Down command
std::wstring seq = L"\x1b[T";
stateMachine.ProcessString(seq);
stateMachine.ProcessString(L"\x1b[T");
Log::Comment(NoThrowString().Format(
L"cursor=%s", VerifyOutputTraits<COORD>::ToString(cursor.GetPosition()).GetBuffer()));
@ -4438,7 +4329,7 @@ void ScreenBufferTests::ScrollLines256Colors()
auto& cursor = si.GetTextBuffer().GetCursor();
TextAttribute expectedAttr{ si.GetAttributes() };
std::wstring sgrSeq = L"\x1b[48;5;2m";
std::wstring_view sgrSeq = L"\x1b[48;5;2m";
if (colorStyle == Use16Color)
{
expectedAttr.SetBackground(gci.GetColorTableEntry(2));
@ -4466,7 +4357,7 @@ void ScreenBufferTests::ScrollLines256Colors()
stateMachine.ProcessString(L"\x1b[H");
// Insert/Delete/Reverse Index 10 lines
std::wstring scrollSeq = L"";
std::wstring_view scrollSeq = L"";
if (scrollType == InsertLines)
{
scrollSeq = L"\x1b[10L";

View file

@ -639,7 +639,7 @@ void TextBufferTests::TestMixedRgbAndLegacyForeground()
wchar_t* sequence = L"\x1b[m\x1b[38;2;64;128;255mX\x1b[49mX\x1b[m";
stateMachine.ProcessString(sequence, std::wcslen(sequence));
stateMachine.ProcessString(sequence);
const short x = cursor.GetPosition().X;
const short y = cursor.GetPosition().Y;
const ROW& row = tbi.GetRowByOffset(y);
@ -665,7 +665,7 @@ void TextBufferTests::TestMixedRgbAndLegacyForeground()
VERIFY_ARE_EQUAL(gci.LookupBackgroundColor(attrB), gci.LookupBackgroundColor(si.GetAttributes()));
wchar_t* reset = L"\x1b[0m";
stateMachine.ProcessString(reset, std::wcslen(reset));
stateMachine.ProcessString(reset);
}
void TextBufferTests::TestMixedRgbAndLegacyBackground()
@ -683,7 +683,7 @@ void TextBufferTests::TestMixedRgbAndLegacyBackground()
Log::Comment(L"Case 2 \"\\E[m\\E[48;2;64;128;255mX\\E[39mX\\E[m\"");
wchar_t* sequence = L"\x1b[m\x1b[48;2;64;128;255mX\x1b[39mX\x1b[m";
stateMachine.ProcessString(sequence, std::wcslen(sequence));
stateMachine.ProcessString(sequence);
const auto x = cursor.GetPosition().X;
const auto y = cursor.GetPosition().Y;
const auto& row = tbi.GetRowByOffset(y);
@ -709,7 +709,7 @@ void TextBufferTests::TestMixedRgbAndLegacyBackground()
VERIFY_ARE_EQUAL(gci.LookupForegroundColor(attrB), gci.LookupForegroundColor(si.GetAttributes()));
wchar_t* reset = L"\x1b[0m";
stateMachine.ProcessString(reset, std::wcslen(reset));
stateMachine.ProcessString(reset);
}
void TextBufferTests::TestMixedRgbAndLegacyUnderline()
@ -725,7 +725,7 @@ void TextBufferTests::TestMixedRgbAndLegacyUnderline()
// Make sure that the second X has RGB attributes AND underline
Log::Comment(L"Case 3 \"\\E[m\\E[48;2;64;128;255mX\\E[4mX\\E[m\"");
wchar_t* sequence = L"\x1b[m\x1b[48;2;64;128;255mX\x1b[4mX\x1b[m";
stateMachine.ProcessString(sequence, std::wcslen(sequence));
stateMachine.ProcessString(sequence);
const auto x = cursor.GetPosition().X;
const auto y = cursor.GetPosition().Y;
const auto& row = tbi.GetRowByOffset(y);
@ -754,7 +754,7 @@ void TextBufferTests::TestMixedRgbAndLegacyUnderline()
VERIFY_ARE_EQUAL(attrB.GetLegacyAttributes() & COMMON_LVB_UNDERSCORE, COMMON_LVB_UNDERSCORE);
wchar_t* reset = L"\x1b[0m";
stateMachine.ProcessString(reset, std::wcslen(reset));
stateMachine.ProcessString(reset);
}
void TextBufferTests::TestMixedRgbAndLegacyBrightness()
@ -773,7 +773,7 @@ void TextBufferTests::TestMixedRgbAndLegacyBrightness()
VERIFY_ARE_NOT_EQUAL(dark_green, bright_green);
wchar_t* sequence = L"\x1b[m\x1b[32mX\x1b[1mX";
stateMachine.ProcessString(sequence, std::wcslen(sequence));
stateMachine.ProcessString(sequence);
const auto x = cursor.GetPosition().X;
const auto y = cursor.GetPosition().Y;
const auto& row = tbi.GetRowByOffset(y);
@ -796,7 +796,7 @@ void TextBufferTests::TestMixedRgbAndLegacyBrightness()
VERIFY_ARE_EQUAL(gci.LookupForegroundColor(attrB), bright_green);
wchar_t* reset = L"\x1b[0m";
stateMachine.ProcessString(reset, std::wcslen(reset));
stateMachine.ProcessString(reset);
}
void TextBufferTests::TestRgbEraseLine()
@ -815,15 +815,15 @@ void TextBufferTests::TestRgbEraseLine()
// BG = rgb(128;128;255)
{
std::wstring sequence = L"\x1b[m\x1b[48;2;64;128;255m";
stateMachine.ProcessString(&sequence[0], sequence.length());
stateMachine.ProcessString(sequence);
sequence = L"X";
stateMachine.ProcessString(&sequence[0], sequence.length());
stateMachine.ProcessString(sequence);
sequence = L"\x1b[48;2;128;128;255m";
stateMachine.ProcessString(&sequence[0], sequence.length());
stateMachine.ProcessString(sequence);
sequence = L"\x1b[K";
stateMachine.ProcessString(&sequence[0], sequence.length());
stateMachine.ProcessString(sequence);
sequence = L"X";
stateMachine.ProcessString(&sequence[0], sequence.length());
stateMachine.ProcessString(sequence);
const auto x = cursor.GetPosition().X;
const auto y = cursor.GetPosition().Y;
@ -853,7 +853,7 @@ void TextBufferTests::TestRgbEraseLine()
VERIFY_ARE_EQUAL(gci.LookupBackgroundColor(attr), RGB(128, 128, 255));
}
std::wstring reset = L"\x1b[0m";
stateMachine.ProcessString(&reset[0], reset.length());
stateMachine.ProcessString(reset);
}
}
@ -872,7 +872,7 @@ void TextBufferTests::TestUnBold()
// The first X should be bright green.
// The second x should be dark green.
std::wstring sequence = L"\x1b[1;32mX\x1b[22mX";
stateMachine.ProcessString(&sequence[0], sequence.length());
stateMachine.ProcessString(sequence);
const auto x = cursor.GetPosition().X;
const auto y = cursor.GetPosition().Y;
@ -905,7 +905,7 @@ void TextBufferTests::TestUnBold()
VERIFY_ARE_EQUAL(gci.LookupForegroundColor(attrB), dark_green);
std::wstring reset = L"\x1b[0m";
stateMachine.ProcessString(&reset[0], reset.length());
stateMachine.ProcessString(reset);
}
void TextBufferTests::TestUnBoldRgb()
@ -924,7 +924,7 @@ void TextBufferTests::TestUnBoldRgb()
// The second X should be dark green, and not legacy.
// BG = rgb(1;2;3)
std::wstring sequence = L"\x1b[1;32m\x1b[48;2;1;2;3mX\x1b[22mX";
stateMachine.ProcessString(&sequence[0], sequence.length());
stateMachine.ProcessString(sequence);
const auto x = cursor.GetPosition().X;
const auto y = cursor.GetPosition().Y;
@ -960,7 +960,7 @@ void TextBufferTests::TestUnBoldRgb()
VERIFY_ARE_EQUAL(gci.LookupForegroundColor(attrB), dark_green);
std::wstring reset = L"\x1b[0m";
stateMachine.ProcessString(&reset[0], reset.length());
stateMachine.ProcessString(reset);
}
void TextBufferTests::TestComplexUnBold()
@ -984,7 +984,7 @@ void TextBufferTests::TestComplexUnBold()
// BG = rgb(1;2;3)
std::wstring sequence = L"\x1b[1;32m\x1b[48;2;1;2;3mA\x1b[22mB\x1b[38;2;32;32;32mC\x1b[1mD\x1b[38;2;64;64;64mE\x1b[22mF";
Log::Comment(NoThrowString().Format(sequence.c_str()));
stateMachine.ProcessString(&sequence[0], sequence.length());
stateMachine.ProcessString(sequence);
const auto x = cursor.GetPosition().X;
const auto y = cursor.GetPosition().Y;
@ -1054,7 +1054,7 @@ void TextBufferTests::TestComplexUnBold()
VERIFY_IS_FALSE(attrF.IsBold());
std::wstring reset = L"\x1b[0m";
stateMachine.ProcessString(&reset[0], reset.length());
stateMachine.ProcessString(reset);
}
void TextBufferTests::CopyAttrs()
@ -1073,7 +1073,7 @@ void TextBufferTests::CopyAttrs()
// The third X should be blue
// The fourth X should be magenta
std::wstring sequence = L"\x1b[32mX\x1b[33mX\n\x1b[34mX\x1b[35mX\x1b[H\x1b[M";
stateMachine.ProcessString(&sequence[0], sequence.length());
stateMachine.ProcessString(sequence);
const auto x = cursor.GetPosition().X;
const auto y = cursor.GetPosition().Y;
@ -1119,7 +1119,7 @@ void TextBufferTests::EmptySgrTest()
cursor.SetYPosition(0);
std::wstring reset = L"\x1b[0m";
stateMachine.ProcessString(&reset[0], reset.length());
stateMachine.ProcessString(reset);
const COLORREF defaultFg = gci.LookupForegroundColor(si.GetAttributes());
const COLORREF defaultBg = gci.LookupBackgroundColor(si.GetAttributes());
@ -1129,7 +1129,7 @@ void TextBufferTests::EmptySgrTest()
// The second X should be (darkRed,default).
// The third X should be default colors.
std::wstring sequence = L"\x1b[0mX\x1b[31mX\x1b[31;mX";
stateMachine.ProcessString(&sequence[0], sequence.length());
stateMachine.ProcessString(sequence);
const auto x = cursor.GetPosition().X;
const auto y = cursor.GetPosition().Y;
@ -1166,7 +1166,7 @@ void TextBufferTests::EmptySgrTest()
VERIFY_ARE_EQUAL(gci.LookupForegroundColor(attrC), defaultFg);
VERIFY_ARE_EQUAL(gci.LookupBackgroundColor(attrC), defaultBg);
stateMachine.ProcessString(&reset[0], reset.length());
stateMachine.ProcessString(reset);
}
void TextBufferTests::TestReverseReset()
@ -1183,7 +1183,7 @@ void TextBufferTests::TestReverseReset()
cursor.SetYPosition(0);
std::wstring reset = L"\x1b[0m";
stateMachine.ProcessString(&reset[0], reset.length());
stateMachine.ProcessString(reset);
const COLORREF defaultFg = gci.LookupForegroundColor(si.GetAttributes());
const COLORREF defaultBg = gci.LookupBackgroundColor(si.GetAttributes());
@ -1193,7 +1193,7 @@ void TextBufferTests::TestReverseReset()
// The second X should be (fg,bg) = (dark_green, rgb(128;5;255))
// The third X should be (fg,bg) = (rgb(128;5;255), dark_green)
std::wstring sequence = L"\x1b[42m\x1b[38;2;128;5;255mX\x1b[7mX\x1b[27mX";
stateMachine.ProcessString(&sequence[0], sequence.length());
stateMachine.ProcessString(sequence);
const auto x = cursor.GetPosition().X;
const auto y = cursor.GetPosition().Y;
@ -1232,7 +1232,7 @@ void TextBufferTests::TestReverseReset()
VERIFY_ARE_EQUAL(gci.LookupForegroundColor(attrC), rgbColor);
VERIFY_ARE_EQUAL(gci.LookupBackgroundColor(attrC), dark_green);
stateMachine.ProcessString(&reset[0], reset.length());
stateMachine.ProcessString(reset);
}
void TextBufferTests::CopyLastAttr()
@ -1251,7 +1251,7 @@ void TextBufferTests::CopyLastAttr()
cursor.SetYPosition(0);
std::wstring reset = L"\x1b[0m";
stateMachine.ProcessString(&reset[0], reset.length());
stateMachine.ProcessString(reset);
const COLORREF defaultFg = gci.LookupForegroundColor(si.GetAttributes());
const COLORREF defaultBg = gci.LookupBackgroundColor(si.GetAttributes());
@ -1278,30 +1278,30 @@ void TextBufferTests::CopyLastAttr()
// then go home, and insert a line.
// Row 1
stateMachine.ProcessString(&solFgSeq[0], solFgSeq.length());
stateMachine.ProcessString(&solBgSeq[0], solBgSeq.length());
stateMachine.ProcessString(L"X", 1);
stateMachine.ProcessString(L"\n", 1);
stateMachine.ProcessString(solFgSeq);
stateMachine.ProcessString(solBgSeq);
stateMachine.ProcessString(L"X");
stateMachine.ProcessString(L"\n");
// Row 2
// Remember that the colors from before persist here too, so we don't need
// to emit both the FG and BG if they haven't changed.
stateMachine.ProcessString(L"X", 1);
stateMachine.ProcessString(&solCyanSeq[0], solCyanSeq.length());
stateMachine.ProcessString(L"X", 1);
stateMachine.ProcessString(L"\n", 1);
stateMachine.ProcessString(L"X");
stateMachine.ProcessString(solCyanSeq);
stateMachine.ProcessString(L"X");
stateMachine.ProcessString(L"\n");
// Row 3
stateMachine.ProcessString(&solFgSeq[0], solFgSeq.length());
stateMachine.ProcessString(&solBgSeq[0], solBgSeq.length());
stateMachine.ProcessString(L"X", 1);
stateMachine.ProcessString(&solCyanSeq[0], solCyanSeq.length());
stateMachine.ProcessString(L"X", 1);
stateMachine.ProcessString(&solFgSeq[0], solFgSeq.length());
stateMachine.ProcessString(L"X", 1);
stateMachine.ProcessString(solFgSeq);
stateMachine.ProcessString(solBgSeq);
stateMachine.ProcessString(L"X");
stateMachine.ProcessString(solCyanSeq);
stateMachine.ProcessString(L"X");
stateMachine.ProcessString(solFgSeq);
stateMachine.ProcessString(L"X");
std::wstring insertLineAtHome = L"\x1b[H\x1b[L";
stateMachine.ProcessString(&insertLineAtHome[0], insertLineAtHome.length());
stateMachine.ProcessString(insertLineAtHome);
const auto x = cursor.GetPosition().X;
const auto y = cursor.GetPosition().Y;
@ -1359,7 +1359,7 @@ void TextBufferTests::CopyLastAttr()
VERIFY_ARE_EQUAL(gci.LookupForegroundColor(attr3C), solFg);
VERIFY_ARE_EQUAL(gci.LookupBackgroundColor(attr3C), solBg);
stateMachine.ProcessString(&reset[0], reset.length());
stateMachine.ProcessString(reset);
}
void TextBufferTests::TestRgbThenBold()
@ -1377,7 +1377,7 @@ void TextBufferTests::TestRgbThenBold()
const auto background = RGB(168, 153, 132);
const wchar_t* const sequence = L"\x1b[38;2;40;40;40m\x1b[48;2;168;153;132mX\x1b[1mX\x1b[m";
stateMachine.ProcessString(sequence, std::wcslen(sequence));
stateMachine.ProcessString(sequence);
const auto x = cursor.GetPosition().X;
const auto y = cursor.GetPosition().Y;
const auto& row = tbi.GetRowByOffset(y);
@ -1404,7 +1404,7 @@ void TextBufferTests::TestRgbThenBold()
VERIFY_ARE_EQUAL(gci.LookupBackgroundColor(attrB), background);
wchar_t* reset = L"\x1b[0m";
stateMachine.ProcessString(reset, std::wcslen(reset));
stateMachine.ProcessString(reset);
}
void TextBufferTests::TestResetClearsBoldness()
@ -1430,7 +1430,7 @@ void TextBufferTests::TestResetClearsBoldness()
wchar_t* sequence = L"\x1b[32mA\x1b[1mB\x1b[0mC\x1b[32mD";
Log::Comment(NoThrowString().Format(sequence));
stateMachine.ProcessString(sequence, std::wcslen(sequence));
stateMachine.ProcessString(sequence);
const auto x = cursor.GetPosition().X;
const auto y = cursor.GetPosition().Y;
@ -1464,7 +1464,7 @@ void TextBufferTests::TestResetClearsBoldness()
VERIFY_IS_FALSE(attrD.IsBold());
wchar_t* reset = L"\x1b[0m";
stateMachine.ProcessString(reset, std::wcslen(reset));
stateMachine.ProcessString(reset);
}
void TextBufferTests::TestBackspaceRightSideVt()
@ -1482,7 +1482,7 @@ void TextBufferTests::TestBackspaceRightSideVt()
Log::Comment(NoThrowString().Format(sequence));
const auto preCursorPosition = cursor.GetPosition();
stateMachine.ProcessString(sequence, std::wcslen(sequence));
stateMachine.ProcessString(sequence);
const auto postCursorPosition = cursor.GetPosition();
// make sure newline was handled correctly
@ -1514,7 +1514,7 @@ void TextBufferTests::TestBackspaceStrings()
x0,
y0));
std::wstring seq = L"a\b \b";
stateMachine.ProcessString(seq.c_str(), seq.length());
stateMachine.ProcessString(seq);
const auto x1 = cursor.GetPosition().X;
const auto y1 = cursor.GetPosition().Y;
@ -1523,13 +1523,13 @@ void TextBufferTests::TestBackspaceStrings()
VERIFY_ARE_EQUAL(y1, y0);
seq = L"a";
stateMachine.ProcessString(seq.c_str(), seq.length());
stateMachine.ProcessString(seq);
seq = L"\b";
stateMachine.ProcessString(seq.c_str(), seq.length());
stateMachine.ProcessString(seq);
seq = L" ";
stateMachine.ProcessString(seq.c_str(), seq.length());
stateMachine.ProcessString(seq);
seq = L"\b";
stateMachine.ProcessString(seq.c_str(), seq.length());
stateMachine.ProcessString(seq);
const auto x2 = cursor.GetPosition().X;
const auto y2 = cursor.GetPosition().Y;

View file

@ -21,8 +21,8 @@ namespace Microsoft::Console
public:
virtual ~ITerminalOutputConnection() = 0;
[[nodiscard]] virtual HRESULT WriteTerminalUtf8(const std::string& str) = 0;
[[nodiscard]] virtual HRESULT WriteTerminalW(const std::wstring& wstr) = 0;
[[nodiscard]] virtual HRESULT WriteTerminalUtf8(const std::string_view str) = 0;
[[nodiscard]] virtual HRESULT WriteTerminalW(const std::wstring_view wstr) = 0;
};
inline Microsoft::Console::ITerminalOutputConnection::~ITerminalOutputConnection() {}

View file

@ -31,6 +31,7 @@
#include <queue>
#include <stdexcept>
#include <string>
#include <string_view>
#include <thread>
#include <tuple>
#include <utility>

View file

@ -109,7 +109,7 @@ WinTelnetEngine::WinTelnetEngine(_In_ wil::unique_hfile hPipe,
// - wstr - wstring of text to be written
// Return Value:
// - S_OK or suitable HRESULT error from either conversion or writing pipe.
[[nodiscard]] HRESULT WinTelnetEngine::WriteTerminalW(_In_ const std::wstring& wstr) noexcept
[[nodiscard]] HRESULT WinTelnetEngine::WriteTerminalW(_In_ const std::wstring_view wstr) noexcept
{
return VtEngine::_WriteTerminalAscii(wstr);
}

View file

@ -39,7 +39,7 @@ namespace Microsoft::Console::Render
[[nodiscard]] HRESULT InvalidateScroll(const COORD* const pcoordDelta) noexcept override;
[[nodiscard]] HRESULT WriteTerminalW(const std::wstring& wstr) noexcept override;
[[nodiscard]] HRESULT WriteTerminalW(const std::wstring_view wstr) noexcept override;
protected:
[[nodiscard]] HRESULT _MoveCursor(const COORD coord) noexcept;

View file

@ -433,7 +433,7 @@ XtermEngine::XtermEngine(_In_ wil::unique_hfile hPipe,
// - wstr - wstring of text to be written
// Return Value:
// - S_OK or suitable HRESULT error from either conversion or writing pipe.
[[nodiscard]] HRESULT XtermEngine::WriteTerminalW(const std::wstring& wstr) noexcept
[[nodiscard]] HRESULT XtermEngine::WriteTerminalW(const std::wstring_view wstr) noexcept
{
return _fUseAsciiOnly ?
VtEngine::_WriteTerminalAscii(wstr) :

View file

@ -53,7 +53,7 @@ namespace Microsoft::Console::Render
[[nodiscard]] HRESULT InvalidateScroll(const COORD* const pcoordDelta) noexcept override;
[[nodiscard]] HRESULT WriteTerminalW(_In_ const std::wstring& str) noexcept override;
[[nodiscard]] HRESULT WriteTerminalW(const std::wstring_view str) noexcept override;
protected:
const COLORREF* const _ColorTable;

View file

@ -125,7 +125,7 @@ VtEngine::VtEngine(_In_ wil::unique_hfile pipe,
// Method Description:
// - Wrapper for ITerminalOutputConnection. See _Write.
[[nodiscard]] HRESULT VtEngine::WriteTerminalUtf8(const std::string& str) noexcept
[[nodiscard]] HRESULT VtEngine::WriteTerminalUtf8(const std::string_view str) noexcept
{
return _Write(str);
}
@ -137,7 +137,7 @@ VtEngine::VtEngine(_In_ wil::unique_hfile pipe,
// - wstr - wstring of text to be written
// Return Value:
// - S_OK or suitable HRESULT error from either conversion or writing pipe.
[[nodiscard]] HRESULT VtEngine::_WriteTerminalUtf8(const std::wstring& wstr) noexcept
[[nodiscard]] HRESULT VtEngine::_WriteTerminalUtf8(const std::wstring_view wstr) noexcept
{
try
{
@ -156,7 +156,7 @@ VtEngine::VtEngine(_In_ wil::unique_hfile pipe,
// - wstr - wstring of text to be written
// Return Value:
// - S_OK or suitable HRESULT error from writing pipe.
[[nodiscard]] HRESULT VtEngine::_WriteTerminalAscii(const std::wstring& wstr) noexcept
[[nodiscard]] HRESULT VtEngine::_WriteTerminalAscii(const std::wstring_view wstr) noexcept
{
const size_t cchActual = wstr.length();

View file

@ -89,9 +89,9 @@ namespace Microsoft::Console::Render
[[nodiscard]] HRESULT RequestCursor() noexcept;
[[nodiscard]] HRESULT InheritCursor(const COORD coordCursor) noexcept;
[[nodiscard]] HRESULT WriteTerminalUtf8(const std::string& str) noexcept;
[[nodiscard]] HRESULT WriteTerminalUtf8(const std::string_view str) noexcept;
[[nodiscard]] virtual HRESULT WriteTerminalW(const std::wstring& str) noexcept = 0;
[[nodiscard]] virtual HRESULT WriteTerminalW(const std::wstring_view str) noexcept = 0;
void SetTerminalOwner(Microsoft::Console::ITerminalOwner* const terminalOwner);
void BeginResizeRequest();
@ -209,8 +209,8 @@ namespace Microsoft::Console::Render
[[nodiscard]] HRESULT _PaintAsciiBufferLine(std::basic_string_view<Cluster> const clusters,
const COORD coord) noexcept;
[[nodiscard]] HRESULT _WriteTerminalUtf8(const std::wstring& str) noexcept;
[[nodiscard]] HRESULT _WriteTerminalAscii(const std::wstring& str) noexcept;
[[nodiscard]] HRESULT _WriteTerminalUtf8(const std::wstring_view str) noexcept;
[[nodiscard]] HRESULT _WriteTerminalAscii(const std::wstring_view str) noexcept;
[[nodiscard]] virtual HRESULT _DoUpdateTitle(const std::wstring& newTitle) noexcept override;

View file

@ -13,27 +13,27 @@ using namespace Microsoft::Console::VirtualTerminal;
// - Resizes the window to the specified dimensions, in characters.
// Arguments:
// - conApi: The ConGetSet implementation to call back into.
// - usWidth: The new width of the window, in columns
// - usHeight: The new height of the window, in rows
// - width: The new width of the window, in columns
// - height: The new height of the window, in rows
// Return Value:
// True if handled successfully. False othewise.
bool DispatchCommon::s_ResizeWindow(ConGetSet& conApi,
const unsigned short usWidth,
const unsigned short usHeight)
const size_t width,
const size_t height)
{
SHORT sColumns = 0;
SHORT sRows = 0;
// We should do nothing if 0 is passed in for a size.
bool fSuccess = SUCCEEDED(UShortToShort(usWidth, &sColumns)) &&
SUCCEEDED(UShortToShort(usHeight, &sRows)) &&
(usWidth > 0 && usHeight > 0);
bool fSuccess = SUCCEEDED(SizeTToShort(width, &sColumns)) &&
SUCCEEDED(SizeTToShort(height, &sRows)) &&
(width > 0 && height > 0);
if (fSuccess)
{
CONSOLE_SCREEN_BUFFER_INFOEX csbiex = { 0 };
csbiex.cbSize = sizeof(CONSOLE_SCREEN_BUFFER_INFOEX);
fSuccess = !!conApi.GetConsoleScreenBufferInfoEx(&csbiex);
fSuccess = !!conApi.GetConsoleScreenBufferInfoEx(csbiex);
if (fSuccess)
{
@ -57,10 +57,10 @@ bool DispatchCommon::s_ResizeWindow(ConGetSet& conApi,
SMALL_RECT sre = newViewport.ToExclusive();
csbiex.srWindow = sre;
fSuccess = !!conApi.SetConsoleScreenBufferInfoEx(&csbiex);
fSuccess = conApi.SetConsoleScreenBufferInfoEx(csbiex);
if (fSuccess)
{
fSuccess = !!conApi.SetConsoleWindowInfo(true, &sri);
fSuccess = conApi.SetConsoleWindowInfo(true, sri);
}
}
}
@ -75,7 +75,7 @@ bool DispatchCommon::s_ResizeWindow(ConGetSet& conApi,
// True if handled successfully. False othewise.
bool DispatchCommon::s_RefreshWindow(ConGetSet& conApi)
{
return !!conApi.PrivateRefreshWindow();
return conApi.PrivateRefreshWindow();
}
// Routine Description:
@ -89,5 +89,5 @@ bool DispatchCommon::s_RefreshWindow(ConGetSet& conApi)
// True if handled successfully. False othewise.
bool DispatchCommon::s_SuppressResizeRepaint(ConGetSet& conApi)
{
return !!conApi.PrivateSuppressResizeRepaint();
return conApi.PrivateSuppressResizeRepaint();
}

View file

@ -23,8 +23,8 @@ namespace Microsoft::Console::VirtualTerminal
{
public:
static bool s_ResizeWindow(ConGetSet& conApi,
const unsigned short usWidth,
const unsigned short usHeight);
const size_t width,
const size_t height);
static bool s_RefreshWindow(ConGetSet& conApi);

View file

@ -25,17 +25,16 @@ namespace Microsoft::Console::VirtualTerminal
public:
virtual ~IInteractDispatch() = default;
virtual bool WriteInput(_In_ std::deque<std::unique_ptr<IInputEvent>>& inputEvents) = 0;
virtual bool WriteInput(std::deque<std::unique_ptr<IInputEvent>>& inputEvents) = 0;
virtual bool WriteCtrlC() = 0;
virtual bool WriteString(_In_reads_(cch) const wchar_t* const pws, const size_t cch) = 0;
virtual bool WriteString(const std::wstring_view string) = 0;
virtual bool WindowManipulation(const DispatchTypes::WindowManipulationType uiFunction,
_In_reads_(cParams) const unsigned short* const rgusParams,
const size_t cParams) = 0;
virtual bool WindowManipulation(const DispatchTypes::WindowManipulationType function,
const std::basic_string_view<size_t> parameters) = 0;
virtual bool MoveCursor(const unsigned int row,
const unsigned int col) = 0;
virtual bool MoveCursor(const size_t row,
const size_t col) = 0;
};
}

View file

@ -25,63 +25,60 @@ public:
virtual ~ITermDispatch() = 0;
virtual void Execute(const wchar_t wchControl) = 0;
virtual void Print(const wchar_t wchPrintable) = 0;
virtual void PrintString(const wchar_t* const rgwch, const size_t cch) = 0;
virtual void PrintString(const std::wstring_view string) = 0;
virtual bool CursorUp(const unsigned int uiDistance) = 0; // CUU
virtual bool CursorDown(const unsigned int uiDistance) = 0; // CUD
virtual bool CursorForward(const unsigned int uiDistance) = 0; // CUF
virtual bool CursorBackward(const unsigned int uiDistance) = 0; // CUB
virtual bool CursorNextLine(const unsigned int uiDistance) = 0; // CNL
virtual bool CursorPrevLine(const unsigned int uiDistance) = 0; // CPL
virtual bool CursorHorizontalPositionAbsolute(const unsigned int uiColumn) = 0; // CHA
virtual bool VerticalLinePositionAbsolute(const unsigned int uiLine) = 0; // VPA
virtual bool CursorPosition(const unsigned int uiLine, const unsigned int uiColumn) = 0; // CUP
virtual bool CursorUp(const size_t distance) = 0; // CUU
virtual bool CursorDown(const size_t distance) = 0; // CUD
virtual bool CursorForward(const size_t distance) = 0; // CUF
virtual bool CursorBackward(const size_t distance) = 0; // CUB
virtual bool CursorNextLine(const size_t distance) = 0; // CNL
virtual bool CursorPrevLine(const size_t distance) = 0; // CPL
virtual bool CursorHorizontalPositionAbsolute(const size_t column) = 0; // CHA
virtual bool VerticalLinePositionAbsolute(const size_t line) = 0; // VPA
virtual bool CursorPosition(const size_t line, const size_t column) = 0; // CUP
virtual bool CursorSaveState() = 0; // DECSC
virtual bool CursorRestoreState() = 0; // DECRC
virtual bool CursorVisibility(const bool fIsVisible) = 0; // DECTCEM
virtual bool InsertCharacter(const unsigned int uiCount) = 0; // ICH
virtual bool DeleteCharacter(const unsigned int uiCount) = 0; // DCH
virtual bool ScrollUp(const unsigned int uiDistance) = 0; // SU
virtual bool ScrollDown(const unsigned int uiDistance) = 0; // SD
virtual bool InsertLine(const unsigned int uiDistance) = 0; // IL
virtual bool DeleteLine(const unsigned int uiDistance) = 0; // DL
virtual bool SetColumns(const unsigned int uiColumns) = 0; // DECSCPP, DECCOLM
virtual bool SetCursorKeysMode(const bool fApplicationMode) = 0; // DECCKM
virtual bool SetKeypadMode(const bool fApplicationMode) = 0; // DECKPAM, DECKPNM
virtual bool EnableCursorBlinking(const bool fEnable) = 0; // ATT610
virtual bool SetOriginMode(const bool fRelativeMode) = 0; // DECOM
virtual bool SetTopBottomScrollingMargins(const SHORT sTopMargin, const SHORT sBottomMargin) = 0; // DECSTBM
virtual bool CursorVisibility(const bool isVisible) = 0; // DECTCEM
virtual bool InsertCharacter(const size_t count) = 0; // ICH
virtual bool DeleteCharacter(const size_t count) = 0; // DCH
virtual bool ScrollUp(const size_t distance) = 0; // SU
virtual bool ScrollDown(const size_t distance) = 0; // SD
virtual bool InsertLine(const size_t distance) = 0; // IL
virtual bool DeleteLine(const size_t distance) = 0; // DL
virtual bool SetColumns(const size_t columns) = 0; // DECSCPP, DECCOLM
virtual bool SetCursorKeysMode(const bool applicationMode) = 0; // DECCKM
virtual bool SetKeypadMode(const bool applicationMode) = 0; // DECKPAM, DECKPNM
virtual bool EnableCursorBlinking(const bool enable) = 0; // ATT610
virtual bool SetOriginMode(const bool relativeMode) = 0; // DECOM
virtual bool SetTopBottomScrollingMargins(const size_t topMargin, const size_t bottomMargin) = 0; // DECSTBM
virtual bool ReverseLineFeed() = 0; // RI
virtual bool SetWindowTitle(std::wstring_view title) = 0; // OscWindowTitle
virtual bool UseAlternateScreenBuffer() = 0; // ASBSET
virtual bool UseMainScreenBuffer() = 0; // ASBRST
virtual bool HorizontalTabSet() = 0; // HTS
virtual bool ForwardTab(const SHORT sNumTabs) = 0; // CHT
virtual bool BackwardsTab(const SHORT sNumTabs) = 0; // CBT
virtual bool TabClear(const SHORT sClearType) = 0; // TBC
virtual bool EnableDECCOLMSupport(const bool fEnabled) = 0; // ?40
virtual bool EnableVT200MouseMode(const bool fEnabled) = 0; // ?1000
virtual bool EnableUTF8ExtendedMouseMode(const bool fEnabled) = 0; // ?1005
virtual bool EnableSGRExtendedMouseMode(const bool fEnabled) = 0; // ?1006
virtual bool EnableButtonEventMouseMode(const bool fEnabled) = 0; // ?1002
virtual bool EnableAnyEventMouseMode(const bool fEnabled) = 0; // ?1003
virtual bool EnableAlternateScroll(const bool fEnabled) = 0; // ?1007
virtual bool SetColorTableEntry(const size_t tableIndex, const DWORD dwColor) = 0; // OSCColorTable
virtual bool SetDefaultForeground(const DWORD dwColor) = 0; // OSCDefaultForeground
virtual bool SetDefaultBackground(const DWORD dwColor) = 0; // OSCDefaultBackground
virtual bool ForwardTab(const size_t numTabs) = 0; // CHT
virtual bool BackwardsTab(const size_t numTabs) = 0; // CBT
virtual bool TabClear(const size_t clearType) = 0; // TBC
virtual bool EnableDECCOLMSupport(const bool enabled) = 0; // ?40
virtual bool EnableVT200MouseMode(const bool enabled) = 0; // ?1000
virtual bool EnableUTF8ExtendedMouseMode(const bool enabled) = 0; // ?1005
virtual bool EnableSGRExtendedMouseMode(const bool enabled) = 0; // ?1006
virtual bool EnableButtonEventMouseMode(const bool enabled) = 0; // ?1002
virtual bool EnableAnyEventMouseMode(const bool enabled) = 0; // ?1003
virtual bool EnableAlternateScroll(const bool enabled) = 0; // ?1007
virtual bool SetColorTableEntry(const size_t tableIndex, const DWORD color) = 0; // OSCColorTable
virtual bool SetDefaultForeground(const DWORD color) = 0; // OSCDefaultForeground
virtual bool SetDefaultBackground(const DWORD color) = 0; // OSCDefaultBackground
virtual bool EraseInDisplay(const DispatchTypes::EraseType eraseType) = 0; // ED
virtual bool EraseInLine(const DispatchTypes::EraseType eraseType) = 0; // EL
virtual bool EraseCharacters(const unsigned int uiNumChars) = 0; // ECH
virtual bool EraseCharacters(const size_t numChars) = 0; // ECH
virtual bool SetGraphicsRendition(_In_reads_(cOptions) const DispatchTypes::GraphicsOptions* const rgOptions,
const size_t cOptions) = 0; // SGR
virtual bool SetGraphicsRendition(const std::basic_string_view<DispatchTypes::GraphicsOptions> options) = 0; // SGR
virtual bool SetPrivateModes(_In_reads_(cParams) const DispatchTypes::PrivateModeParams* const rgParams,
const size_t cParams) = 0; // DECSET
virtual bool SetPrivateModes(const std::basic_string_view<DispatchTypes::PrivateModeParams> params) = 0; // DECSET
virtual bool ResetPrivateModes(_In_reads_(cParams) const DispatchTypes::PrivateModeParams* const rgParams,
const size_t cParams) = 0; // DECRST
virtual bool ResetPrivateModes(const std::basic_string_view<DispatchTypes::PrivateModeParams> params) = 0; // DECRST
virtual bool DeviceStatusReport(const DispatchTypes::AnsiStatusType statusType) = 0; // DSR
virtual bool DeviceAttributes() = 0; // DA
@ -93,11 +90,10 @@ public:
virtual bool ScreenAlignmentPattern() = 0; // DECALN
virtual bool SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) = 0; // DECSCUSR
virtual bool SetCursorColor(const COLORREF Color) = 0; // OSCSetCursorColor, OSCResetCursorColor
virtual bool SetCursorColor(const COLORREF color) = 0; // OSCSetCursorColor, OSCResetCursorColor
// DTTERM_WindowManipulation
virtual bool WindowManipulation(const DispatchTypes::WindowManipulationType uiFunction,
_In_reads_(cParams) const unsigned short* const rgusParams,
const size_t cParams) = 0;
virtual bool WindowManipulation(const DispatchTypes::WindowManipulationType function,
const std::basic_string_view<size_t> parameters) = 0;
};
inline Microsoft::Console::VirtualTerminal::ITermDispatch::~ITermDispatch() {}

View file

@ -14,9 +14,10 @@ using namespace Microsoft::Console::Types;
using namespace Microsoft::Console::VirtualTerminal;
// takes ownership of pConApi
InteractDispatch::InteractDispatch(ConGetSet* const pConApi) :
_pConApi(THROW_IF_NULL_ALLOC(pConApi))
InteractDispatch::InteractDispatch(std::unique_ptr<ConGetSet> pConApi) :
_pConApi(std::move(pConApi))
{
THROW_IF_NULL_ALLOC(_pConApi.get());
}
// Method Description:
@ -29,10 +30,10 @@ InteractDispatch::InteractDispatch(ConGetSet* const pConApi) :
// - inputEvents: a collection of IInputEvents
// Return Value:
// True if handled successfully. False otherwise.
bool InteractDispatch::WriteInput(_In_ std::deque<std::unique_ptr<IInputEvent>>& inputEvents)
bool InteractDispatch::WriteInput(std::deque<std::unique_ptr<IInputEvent>>& inputEvents)
{
size_t dwWritten = 0;
return !!_pConApi->PrivateWriteConsoleInputW(inputEvents, dwWritten);
size_t written = 0;
return _pConApi->PrivateWriteConsoleInputW(inputEvents, written);
}
// Method Description:
@ -46,43 +47,41 @@ bool InteractDispatch::WriteInput(_In_ std::deque<std::unique_ptr<IInputEvent>>&
bool InteractDispatch::WriteCtrlC()
{
KeyEvent key = KeyEvent(true, 1, 'C', 0, UNICODE_ETX, LEFT_CTRL_PRESSED);
return !!_pConApi->PrivateWriteConsoleControlInput(key);
return _pConApi->PrivateWriteConsoleControlInput(key);
}
// Method Description:
// - Writes a string of input to the host. The string is converted to keystrokes
// that will faithfully represent the input by CharToKeyEvents.
// Arguments:
// - pws: a string to write to the console.
// - cch: the number of chars in pws.
// - string : a string to write to the console.
// Return Value:
// True if handled successfully. False otherwise.
bool InteractDispatch::WriteString(_In_reads_(cch) const wchar_t* const pws,
const size_t cch)
bool InteractDispatch::WriteString(const std::wstring_view string)
{
if (cch == 0)
if (string.empty())
{
return true;
}
unsigned int codepage = 0;
bool fSuccess = !!_pConApi->GetConsoleOutputCP(&codepage);
if (fSuccess)
bool success = _pConApi->GetConsoleOutputCP(codepage);
if (success)
{
std::deque<std::unique_ptr<IInputEvent>> keyEvents;
for (size_t i = 0; i < cch; ++i)
for (const auto& wch : string)
{
std::deque<std::unique_ptr<KeyEvent>> convertedEvents = CharToKeyEvents(pws[i], codepage);
std::deque<std::unique_ptr<KeyEvent>> convertedEvents = CharToKeyEvents(wch, codepage);
std::move(convertedEvents.begin(),
convertedEvents.end(),
std::back_inserter(keyEvents));
}
fSuccess = WriteInput(keyEvents);
success = WriteInput(keyEvents);
}
return fSuccess;
return success;
}
//Method Description:
@ -92,45 +91,43 @@ bool InteractDispatch::WriteString(_In_reads_(cch) const wchar_t* const pws,
// This is kept seperate from the output version, as there may be
// codes that are supported in one direction but not the other.
//Arguments:
// - uiFunction - An identifier of the WindowManipulation function to perform
// - rgusParams - Additional parameters to pass to the function
// - cParams - size of rgusParams
// - function - An identifier of the WindowManipulation function to perform
// - parameters - Additional parameters to pass to the function
// Return value:
// True if handled successfully. False otherwise.
bool InteractDispatch::WindowManipulation(const DispatchTypes::WindowManipulationType uiFunction,
_In_reads_(cParams) const unsigned short* const rgusParams,
const size_t cParams)
bool InteractDispatch::WindowManipulation(const DispatchTypes::WindowManipulationType function,
const std::basic_string_view<size_t> parameters)
{
bool fSuccess = false;
bool success = false;
// Other Window Manipulation functions:
// MSFT:13271098 - QueryViewport
// MSFT:13271146 - QueryScreenSize
switch (uiFunction)
switch (function)
{
case DispatchTypes::WindowManipulationType::RefreshWindow:
if (cParams == 0)
if (parameters.empty())
{
fSuccess = DispatchCommon::s_RefreshWindow(*_pConApi);
success = DispatchCommon::s_RefreshWindow(*_pConApi);
}
break;
case DispatchTypes::WindowManipulationType::ResizeWindowInCharacters:
// TODO:GH#1765 We should introduce a better `ResizeConpty` function to
// the ConGetSet interface, that specifically handles a conpty resize.
if (cParams == 2)
if (parameters.size() == 2)
{
fSuccess = DispatchCommon::s_ResizeWindow(*_pConApi, rgusParams[1], rgusParams[0]);
if (fSuccess)
success = DispatchCommon::s_ResizeWindow(*_pConApi, parameters[1], parameters[0]);
if (success)
{
DispatchCommon::s_SuppressResizeRepaint(*_pConApi);
}
}
break;
default:
fSuccess = false;
success = false;
break;
}
return fSuccess;
return success;
}
//Method Description:
@ -143,66 +140,66 @@ bool InteractDispatch::WindowManipulation(const DispatchTypes::WindowManipulatio
// True if we successfully moved the cursor to the given location.
// False otherwise, including if given invalid coordinates (either component being 0)
// or if any API calls failed.
bool InteractDispatch::MoveCursor(const unsigned int row, const unsigned int col)
bool InteractDispatch::MoveCursor(const size_t row, const size_t col)
{
unsigned int uiRow = row;
unsigned int uiCol = col;
size_t rowFixed = row;
size_t colFixed = col;
bool fSuccess = true;
bool success = true;
// In VT, the origin is 1,1. For our array, it's 0,0. So subtract 1.
if (row != 0)
{
uiRow = row - 1;
rowFixed = row - 1;
}
else
{
// The parser should never return 0 (0 maps to 1), so this is a failure condition.
fSuccess = false;
success = false;
}
if (col != 0)
{
uiCol = col - 1;
colFixed = col - 1;
}
else
{
// The parser should never return 0 (0 maps to 1), so this is a failure condition.
fSuccess = false;
success = false;
}
if (fSuccess)
if (success)
{
// First retrieve some information about the buffer
CONSOLE_SCREEN_BUFFER_INFOEX csbiex = { 0 };
csbiex.cbSize = sizeof(CONSOLE_SCREEN_BUFFER_INFOEX);
fSuccess = !!_pConApi->GetConsoleScreenBufferInfoEx(&csbiex);
success = _pConApi->GetConsoleScreenBufferInfoEx(csbiex);
if (fSuccess)
if (success)
{
COORD coordCursor = csbiex.dwCursorPosition;
// Safely convert the UINT positions we were given into shorts (which is the size the console deals with)
fSuccess = SUCCEEDED(UIntToShort(uiRow, &coordCursor.Y)) &&
SUCCEEDED(UIntToShort(uiCol, &coordCursor.X));
// Safely convert the size_t positions we were given into shorts (which is the size the console deals with)
success = SUCCEEDED(SizeTToShort(rowFixed, &coordCursor.Y)) &&
SUCCEEDED(SizeTToShort(colFixed, &coordCursor.X));
if (fSuccess)
if (success)
{
// Set the line and column values as offsets from the viewport edge. Use safe math to prevent overflow.
fSuccess = SUCCEEDED(ShortAdd(coordCursor.Y, csbiex.srWindow.Top, &coordCursor.Y)) &&
SUCCEEDED(ShortAdd(coordCursor.X, csbiex.srWindow.Left, &coordCursor.X));
success = SUCCEEDED(ShortAdd(coordCursor.Y, csbiex.srWindow.Top, &coordCursor.Y)) &&
SUCCEEDED(ShortAdd(coordCursor.X, csbiex.srWindow.Left, &coordCursor.X));
if (fSuccess)
if (success)
{
// Apply boundary tests to ensure the cursor isn't outside the viewport rectangle.
coordCursor.Y = std::clamp(coordCursor.Y, csbiex.srWindow.Top, gsl::narrow<SHORT>(csbiex.srWindow.Bottom - 1));
coordCursor.X = std::clamp(coordCursor.X, csbiex.srWindow.Left, gsl::narrow<SHORT>(csbiex.srWindow.Right - 1));
// Finally, attempt to set the adjusted cursor position back into the console.
fSuccess = !!_pConApi->SetConsoleCursorPosition(coordCursor);
success = _pConApi->SetConsoleCursorPosition(coordCursor);
}
}
}
}
return fSuccess;
return success;
}

View file

@ -23,18 +23,16 @@ namespace Microsoft::Console::VirtualTerminal
class InteractDispatch : public IInteractDispatch
{
public:
InteractDispatch(ConGetSet* const pConApi);
InteractDispatch(std::unique_ptr<ConGetSet> pConApi);
~InteractDispatch() = default;
bool WriteInput(_In_ std::deque<std::unique_ptr<IInputEvent>>& inputEvents) override;
bool WriteInput(std::deque<std::unique_ptr<IInputEvent>>& inputEvents) override;
bool WriteCtrlC() override;
bool WriteString(_In_reads_(cch) const wchar_t* const pws, const size_t cch) override;
bool WindowManipulation(const DispatchTypes::WindowManipulationType uiFunction,
_In_reads_(cParams) const unsigned short* const rgusParams,
const size_t cParams) override; // DTTERM_WindowManipulation
bool MoveCursor(const unsigned int row,
const unsigned int col) override;
bool WriteString(const std::wstring_view string) override;
bool WindowManipulation(const DispatchTypes::WindowManipulationType function,
const std::basic_string_view<size_t> parameters) override; // DTTERM_WindowManipulation
bool MoveCursor(const size_t row, const size_t col) override;
private:
std::unique_ptr<ConGetSet> _pConApi;

View file

@ -23,7 +23,7 @@ namespace Microsoft::Console::VirtualTerminal
public:
virtual void Print(const wchar_t wch) = 0;
// These characters need to be mutable so that they can be processed by the TerminalInput translater.
virtual void PrintString(const wchar_t* const rgwch, const size_t cch) = 0;
virtual void PrintString(const std::wstring_view string) = 0;
virtual void Execute(const wchar_t wch) = 0;
};
}

File diff suppressed because it is too large Load diff

View file

@ -19,90 +19,85 @@ Author(s):
#include "conGetSet.hpp"
#include "adaptDefaults.hpp"
#include "terminalOutput.hpp"
#include <math.h>
namespace Microsoft::Console::VirtualTerminal
{
class AdaptDispatch : public ITermDispatch
{
public:
AdaptDispatch(ConGetSet* const pConApi,
AdaptDefaults* const pDefaults);
AdaptDispatch(std::unique_ptr<ConGetSet> pConApi,
std::unique_ptr<AdaptDefaults> pDefaults);
void Execute(const wchar_t wchControl) override
{
_pDefaults->Execute(wchControl);
}
void PrintString(const wchar_t* const rgwch, const size_t cch) override;
void PrintString(const std::wstring_view string) override;
void Print(const wchar_t wchPrintable) override;
bool CursorUp(_In_ unsigned int const uiDistance) override; // CUU
bool CursorDown(_In_ unsigned int const uiDistance) override; // CUD
bool CursorForward(_In_ unsigned int const uiDistance) override; // CUF
bool CursorBackward(_In_ unsigned int const uiDistance) override; // CUB
bool CursorNextLine(_In_ unsigned int const uiDistance) override; // CNL
bool CursorPrevLine(_In_ unsigned int const uiDistance) override; // CPL
bool CursorHorizontalPositionAbsolute(_In_ unsigned int const uiColumn) override; // CHA
bool VerticalLinePositionAbsolute(_In_ unsigned int const uiLine) override; // VPA
bool CursorPosition(_In_ unsigned int const uiLine, _In_ unsigned int const uiColumn) override; // CUP
bool CursorUp(const size_t distance) override; // CUU
bool CursorDown(const size_t distance) override; // CUD
bool CursorForward(const size_t distance) override; // CUF
bool CursorBackward(const size_t distance) override; // CUB
bool CursorNextLine(const size_t distance) override; // CNL
bool CursorPrevLine(const size_t distance) override; // CPL
bool CursorHorizontalPositionAbsolute(const size_t column) override; // CHA
bool VerticalLinePositionAbsolute(const size_t line) override; // VPA
bool CursorPosition(const size_t line, const size_t column) override; // CUP
bool CursorSaveState() override; // DECSC
bool CursorRestoreState() override; // DECRC
bool CursorVisibility(const bool fIsVisible) override; // DECTCEM
bool CursorVisibility(const bool isVisible) override; // DECTCEM
bool EraseInDisplay(const DispatchTypes::EraseType eraseType) override; // ED
bool EraseInLine(const DispatchTypes::EraseType eraseType) override; // EL
bool EraseCharacters(_In_ unsigned int const uiNumChars) override; // ECH
bool InsertCharacter(_In_ unsigned int const uiCount) override; // ICH
bool DeleteCharacter(_In_ unsigned int const uiCount) override; // DCH
bool SetGraphicsRendition(_In_reads_(cOptions) const DispatchTypes::GraphicsOptions* const rgOptions,
const size_t cOptions) override; // SGR
bool EraseCharacters(const size_t numChars) override; // ECH
bool InsertCharacter(const size_t count) override; // ICH
bool DeleteCharacter(const size_t count) override; // DCH
bool SetGraphicsRendition(const std::basic_string_view<DispatchTypes::GraphicsOptions> options) override; // SGR
bool DeviceStatusReport(const DispatchTypes::AnsiStatusType statusType) override; // DSR
bool DeviceAttributes() override; // DA
bool ScrollUp(_In_ unsigned int const uiDistance) override; // SU
bool ScrollDown(_In_ unsigned int const uiDistance) override; // SD
bool InsertLine(_In_ unsigned int const uiDistance) override; // IL
bool DeleteLine(_In_ unsigned int const uiDistance) override; // DL
bool SetColumns(_In_ unsigned int const uiColumns) override; // DECSCPP, DECCOLM
bool SetPrivateModes(_In_reads_(cParams) const DispatchTypes::PrivateModeParams* const rParams,
const size_t cParams) override; // DECSET
bool ResetPrivateModes(_In_reads_(cParams) const DispatchTypes::PrivateModeParams* const rParams,
const size_t cParams) override; // DECRST
bool SetCursorKeysMode(const bool fApplicationMode) override; // DECCKM
bool SetKeypadMode(const bool fApplicationMode) override; // DECKPAM, DECKPNM
bool EnableCursorBlinking(const bool bEnable) override; // ATT610
bool SetOriginMode(const bool fRelativeMode) override; // DECOM
bool SetTopBottomScrollingMargins(const SHORT sTopMargin,
const SHORT sBottomMargin) override; // DECSTBM
bool ScrollUp(const size_t distance) override; // SU
bool ScrollDown(const size_t distance) override; // SD
bool InsertLine(const size_t distance) override; // IL
bool DeleteLine(const size_t distance) override; // DL
bool SetColumns(const size_t columns) override; // DECSCPP, DECCOLM
bool SetPrivateModes(const std::basic_string_view<DispatchTypes::PrivateModeParams> params) override; // DECSET
bool ResetPrivateModes(const std::basic_string_view<DispatchTypes::PrivateModeParams> params) override; // DECRST
bool SetCursorKeysMode(const bool applicationMode) override; // DECCKM
bool SetKeypadMode(const bool applicationMode) override; // DECKPAM, DECKPNM
bool EnableCursorBlinking(const bool enable) override; // ATT610
bool SetOriginMode(const bool relativeMode) override; // DECOM
bool SetTopBottomScrollingMargins(const size_t topMargin,
const size_t bottomMargin) override; // DECSTBM
bool ReverseLineFeed() override; // RI
bool SetWindowTitle(const std::wstring_view title) override; // OscWindowTitle
bool UseAlternateScreenBuffer() override; // ASBSET
bool UseMainScreenBuffer() override; // ASBRST
bool HorizontalTabSet() override; // HTS
bool ForwardTab(const SHORT sNumTabs) override; // CHT
bool BackwardsTab(const SHORT sNumTabs) override; // CBT
bool TabClear(const SHORT sClearType) override; // TBC
bool ForwardTab(const size_t numTabs) override; // CHT
bool BackwardsTab(const size_t numTabs) override; // CBT
bool TabClear(const size_t clearType) override; // TBC
bool DesignateCharset(const wchar_t wchCharset) override; // DesignateCharset
bool SoftReset() override; // DECSTR
bool HardReset() override; // RIS
bool ScreenAlignmentPattern() override; // DECALN
bool EnableDECCOLMSupport(const bool fEnabled) override; // ?40
bool EnableVT200MouseMode(const bool fEnabled) override; // ?1000
bool EnableUTF8ExtendedMouseMode(const bool fEnabled) override; // ?1005
bool EnableSGRExtendedMouseMode(const bool fEnabled) override; // ?1006
bool EnableButtonEventMouseMode(const bool fEnabled) override; // ?1002
bool EnableAnyEventMouseMode(const bool fEnabled) override; // ?1003
bool EnableAlternateScroll(const bool fEnabled) override; // ?1007
bool EnableDECCOLMSupport(const bool enabled) override; // ?40
bool EnableVT200MouseMode(const bool enabled) override; // ?1000
bool EnableUTF8ExtendedMouseMode(const bool enabled) override; // ?1005
bool EnableSGRExtendedMouseMode(const bool enabled) override; // ?1006
bool EnableButtonEventMouseMode(const bool enabled) override; // ?1002
bool EnableAnyEventMouseMode(const bool enabled) override; // ?1003
bool EnableAlternateScroll(const bool enabled) override; // ?1007
bool SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) override; // DECSCUSR
bool SetCursorColor(const COLORREF cursorColor) override;
bool SetColorTableEntry(const size_t tableIndex,
const DWORD dwColor) override; // OscColorTable
bool SetDefaultForeground(const DWORD dwColor) override; // OSCDefaultForeground
bool SetDefaultBackground(const DWORD dwColor) override; // OSCDefaultBackground
const DWORD color) override; // OscColorTable
bool SetDefaultForeground(const DWORD color) override; // OSCDefaultForeground
bool SetDefaultBackground(const DWORD color) override; // OSCDefaultBackground
bool WindowManipulation(const DispatchTypes::WindowManipulationType uiFunction,
_In_reads_(cParams) const unsigned short* const rgusParams,
const size_t cParams) override; // DTTERM_WindowManipulation
bool WindowManipulation(const DispatchTypes::WindowManipulationType function,
const std::basic_string_view<size_t> parameters) override; // DTTERM_WindowManipulation
private:
enum class CursorDirection
@ -128,62 +123,59 @@ namespace Microsoft::Console::VirtualTerminal
TerminalOutput TermOutput = {};
};
bool _CursorMovement(const CursorDirection dir, _In_ unsigned int const uiDistance) const;
bool _CursorMovePosition(_In_opt_ const unsigned int* const puiRow, _In_opt_ const unsigned int* const puiCol) const;
bool _EraseSingleLineHelper(const CONSOLE_SCREEN_BUFFER_INFOEX* const pcsbiex, const DispatchTypes::EraseType eraseType, const SHORT sLineId) const;
void _SetGraphicsOptionHelper(const DispatchTypes::GraphicsOptions opt, _Inout_ WORD* const pAttr);
bool _CursorMovement(const CursorDirection dir, const size_t distance) const;
bool _CursorMovePosition(const std::optional<size_t> row, const std::optional<size_t> column) const;
bool _EraseSingleLineHelper(const CONSOLE_SCREEN_BUFFER_INFOEX& csbiex,
const DispatchTypes::EraseType eraseType,
const size_t lineId) const;
void _SetGraphicsOptionHelper(const DispatchTypes::GraphicsOptions opt, WORD& attr);
bool _EraseScrollback();
bool _EraseAll();
void _SetGraphicsOptionHelper(const DispatchTypes::GraphicsOptions opt, _Inout_ WORD* const pAttr) const;
bool _InsertDeleteHelper(_In_ unsigned int const uiCount, const bool fIsInsert) const;
bool _ScrollMovement(const ScrollDirection dir, _In_ unsigned int const uiDistance) const;
static void s_DisableAllColors(_Inout_ WORD* const pAttr, const bool fIsForeground);
static void s_ApplyColors(_Inout_ WORD* const pAttr, const WORD wApplyThis, const bool fIsForeground);
bool _InsertDeleteHelper(const size_t count, const bool isInsert) const;
bool _ScrollMovement(const ScrollDirection dir, const size_t distance) const;
static void s_DisableAllColors(WORD& attr, const bool isForeground);
static void s_ApplyColors(WORD& attr, const WORD applyThis, const bool isForeground);
bool _DoSetTopBottomScrollingMargins(const SHORT sTopMargin,
const SHORT sBottomMargin);
bool _DoSetTopBottomScrollingMargins(const size_t topMargin,
const size_t bottomMargin);
bool _CursorPositionReport() const;
bool _WriteResponse(_In_reads_(cchReply) PCWSTR pwszReply, const size_t cchReply) const;
bool _SetResetPrivateModes(_In_reads_(cParams) const DispatchTypes::PrivateModeParams* const rgParams, const size_t cParams, const bool fEnable);
bool _PrivateModeParamsHelper(_In_ DispatchTypes::PrivateModeParams const param, const bool fEnable);
bool _DoDECCOLMHelper(_In_ unsigned int uiColumns);
bool _WriteResponse(const std::wstring_view reply) const;
bool _SetResetPrivateModes(const std::basic_string_view<DispatchTypes::PrivateModeParams> params, const bool enable);
bool _PrivateModeParamsHelper(const DispatchTypes::PrivateModeParams param, const bool enable);
bool _DoDECCOLMHelper(const size_t columns);
std::unique_ptr<ConGetSet> _conApi;
std::unique_ptr<ConGetSet> _pConApi;
std::unique_ptr<AdaptDefaults> _pDefaults;
TerminalOutput _TermOutput;
TerminalOutput _termOutput;
// We have two instances of the saved cursor state, because we need
// one for the main buffer (at index 0), and another for the alt buffer
// (at index 1). The _usingAltBuffer property keeps tracks of which
// buffer is active, so can be used as an index into this array to
// obtain the saved state that should be currently active.
CursorState _savedCursorState[2];
std::array<CursorState, 2> _savedCursorState;
bool _usingAltBuffer;
SMALL_RECT _srScrollMargins;
SMALL_RECT _scrollMargins;
bool _fIsOriginModeRelative;
bool _isOriginModeRelative;
bool _fIsSetColumnsEnabled;
bool _isDECCOLMAllowed;
bool _fIsDECCOLMAllowed;
bool _changedForeground;
bool _changedBackground;
bool _changedMetaAttrs;
bool _fChangedForeground;
bool _fChangedBackground;
bool _fChangedMetaAttrs;
bool _SetRgbColorsHelper(_In_reads_(cOptions) const DispatchTypes::GraphicsOptions* const rgOptions,
const size_t cOptions,
_Out_ COLORREF* const prgbColor,
_Out_ bool* const pfIsForeground,
_Out_ size_t* const pcOptionsConsumed);
bool _SetRgbColorsHelper(const std::basic_string_view<DispatchTypes::GraphicsOptions> options,
COLORREF& rgbColor,
bool& isForeground,
size_t& optionsConsumed);
bool _SetBoldColorHelper(const DispatchTypes::GraphicsOptions option);
bool _SetDefaultColorHelper(const DispatchTypes::GraphicsOptions option);
bool _SetExtendedTextAttributeHelper(const DispatchTypes::GraphicsOptions option);
static bool s_IsXtermColorOption(const DispatchTypes::GraphicsOptions opt);
static bool s_IsRgbColorOption(const DispatchTypes::GraphicsOptions opt);
static bool s_IsBoldColorOption(const DispatchTypes::GraphicsOptions opt) noexcept;
static bool s_IsDefaultColorOption(const DispatchTypes::GraphicsOptions opt) noexcept;

View file

@ -16,51 +16,51 @@ using namespace Microsoft::Console::VirtualTerminal::DispatchTypes;
// Routine Description:
// - Small helper to disable all color flags within a given font attributes field
// Arguments:
// - pAttr - Pointer to font attributes field to adjust
// - fIsForeground - True if we're modifying the FOREGROUND colors. False if we're doing BACKGROUND.
// - attr - Font attributes field to adjust
// - isForeground - True if we're modifying the FOREGROUND colors. False if we're doing BACKGROUND.
// Return Value:
// - <none>
void AdaptDispatch::s_DisableAllColors(_Inout_ WORD* const pAttr, const bool fIsForeground)
void AdaptDispatch::s_DisableAllColors(WORD& attr, const bool isForeground)
{
if (fIsForeground)
if (isForeground)
{
*pAttr &= ~(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
attr &= ~(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
}
else
{
*pAttr &= ~(BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY);
attr &= ~(BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY);
}
}
// Routine Description:
// - Small helper to help mask off the appropriate foreground/background bits in the colors bitfield.
// Arguments:
// - pAttr - Pointer to font attributes field to adjust
// - wApplyThis - Color values to apply to the low or high word of the font attributes field.
// - fIsForeground - TRUE = foreground color. FALSE = background color.
// - attr - Font attributes field to adjust
// - applyThis - Color values to apply to the low or high word of the font attributes field.
// - isForeground - TRUE = foreground color. FALSE = background color.
// Specifies which half of the bit field to reset and then apply wApplyThis
// upon.
// Return Value:
// - <none>
void AdaptDispatch::s_ApplyColors(_Inout_ WORD* const pAttr, const WORD wApplyThis, const bool fIsForeground)
void AdaptDispatch::s_ApplyColors(WORD& attr, const WORD applyThis, const bool isForeground)
{
// Copy the new attribute to apply
WORD wNewColors = wApplyThis;
WORD wNewColors = applyThis;
// Mask off only the foreground or background
if (fIsForeground)
if (isForeground)
{
*pAttr &= ~(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
attr &= ~(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
wNewColors &= (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_INTENSITY);
}
else
{
*pAttr &= ~(BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY);
attr &= ~(BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY);
wNewColors &= (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_INTENSITY);
}
// Apply appropriate flags.
*pAttr |= wNewColors;
attr |= wNewColors;
}
// Routine Description:
@ -70,10 +70,10 @@ void AdaptDispatch::s_ApplyColors(_Inout_ WORD* const pAttr, const WORD wApplyTh
// command.
// Arguments:
// - opt - Graphics option sent to us by the parser/requestor.
// - pAttr - Pointer to the font attribute field to adjust
// - attr - Font attribute field to adjust
// Return Value:
// - <none>
void AdaptDispatch::_SetGraphicsOptionHelper(const DispatchTypes::GraphicsOptions opt, _Inout_ WORD* const pAttr)
void AdaptDispatch::_SetGraphicsOptionHelper(const DispatchTypes::GraphicsOptions opt, WORD& attr)
{
switch (opt)
{
@ -84,185 +84,185 @@ void AdaptDispatch::_SetGraphicsOptionHelper(const DispatchTypes::GraphicsOption
// case DispatchTypes::GraphicsOptions::BoldBright:
// case DispatchTypes::GraphicsOptions::UnBold:
case DispatchTypes::GraphicsOptions::Negative:
*pAttr |= COMMON_LVB_REVERSE_VIDEO;
_fChangedMetaAttrs = true;
attr |= COMMON_LVB_REVERSE_VIDEO;
_changedMetaAttrs = true;
break;
case DispatchTypes::GraphicsOptions::Underline:
// TODO:GH#2915 Treat underline separately from LVB_UNDERSCORE
*pAttr |= COMMON_LVB_UNDERSCORE;
_fChangedMetaAttrs = true;
attr |= COMMON_LVB_UNDERSCORE;
_changedMetaAttrs = true;
break;
case DispatchTypes::GraphicsOptions::Positive:
*pAttr &= ~COMMON_LVB_REVERSE_VIDEO;
_fChangedMetaAttrs = true;
attr &= ~COMMON_LVB_REVERSE_VIDEO;
_changedMetaAttrs = true;
break;
case DispatchTypes::GraphicsOptions::NoUnderline:
*pAttr &= ~COMMON_LVB_UNDERSCORE;
_fChangedMetaAttrs = true;
attr &= ~COMMON_LVB_UNDERSCORE;
_changedMetaAttrs = true;
break;
case DispatchTypes::GraphicsOptions::ForegroundBlack:
s_DisableAllColors(pAttr, true); // turn off all color flags first.
_fChangedForeground = true;
s_DisableAllColors(attr, true); // turn off all color flags first.
_changedForeground = true;
break;
case DispatchTypes::GraphicsOptions::ForegroundBlue:
s_DisableAllColors(pAttr, true); // turn off all color flags first.
*pAttr |= FOREGROUND_BLUE;
_fChangedForeground = true;
s_DisableAllColors(attr, true); // turn off all color flags first.
attr |= FOREGROUND_BLUE;
_changedForeground = true;
break;
case DispatchTypes::GraphicsOptions::ForegroundGreen:
s_DisableAllColors(pAttr, true); // turn off all color flags first.
*pAttr |= FOREGROUND_GREEN;
_fChangedForeground = true;
s_DisableAllColors(attr, true); // turn off all color flags first.
attr |= FOREGROUND_GREEN;
_changedForeground = true;
break;
case DispatchTypes::GraphicsOptions::ForegroundCyan:
s_DisableAllColors(pAttr, true); // turn off all color flags first.
*pAttr |= FOREGROUND_BLUE | FOREGROUND_GREEN;
_fChangedForeground = true;
s_DisableAllColors(attr, true); // turn off all color flags first.
attr |= FOREGROUND_BLUE | FOREGROUND_GREEN;
_changedForeground = true;
break;
case DispatchTypes::GraphicsOptions::ForegroundRed:
s_DisableAllColors(pAttr, true); // turn off all color flags first.
*pAttr |= FOREGROUND_RED;
_fChangedForeground = true;
s_DisableAllColors(attr, true); // turn off all color flags first.
attr |= FOREGROUND_RED;
_changedForeground = true;
break;
case DispatchTypes::GraphicsOptions::ForegroundMagenta:
s_DisableAllColors(pAttr, true); // turn off all color flags first.
*pAttr |= FOREGROUND_BLUE | FOREGROUND_RED;
_fChangedForeground = true;
s_DisableAllColors(attr, true); // turn off all color flags first.
attr |= FOREGROUND_BLUE | FOREGROUND_RED;
_changedForeground = true;
break;
case DispatchTypes::GraphicsOptions::ForegroundYellow:
s_DisableAllColors(pAttr, true); // turn off all color flags first.
*pAttr |= FOREGROUND_GREEN | FOREGROUND_RED;
_fChangedForeground = true;
s_DisableAllColors(attr, true); // turn off all color flags first.
attr |= FOREGROUND_GREEN | FOREGROUND_RED;
_changedForeground = true;
break;
case DispatchTypes::GraphicsOptions::ForegroundWhite:
s_DisableAllColors(pAttr, true); // turn off all color flags first.
*pAttr |= FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
_fChangedForeground = true;
s_DisableAllColors(attr, true); // turn off all color flags first.
attr |= FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
_changedForeground = true;
break;
case DispatchTypes::GraphicsOptions::ForegroundDefault:
FAIL_FAST_MSG("GraphicsOptions::ForegroundDefault should be handled by _SetDefaultColorHelper");
break;
case DispatchTypes::GraphicsOptions::BackgroundBlack:
s_DisableAllColors(pAttr, false); // turn off all color flags first.
_fChangedBackground = true;
s_DisableAllColors(attr, false); // turn off all color flags first.
_changedBackground = true;
break;
case DispatchTypes::GraphicsOptions::BackgroundBlue:
s_DisableAllColors(pAttr, false); // turn off all color flags first.
*pAttr |= BACKGROUND_BLUE;
_fChangedBackground = true;
s_DisableAllColors(attr, false); // turn off all color flags first.
attr |= BACKGROUND_BLUE;
_changedBackground = true;
break;
case DispatchTypes::GraphicsOptions::BackgroundGreen:
s_DisableAllColors(pAttr, false); // turn off all color flags first.
*pAttr |= BACKGROUND_GREEN;
_fChangedBackground = true;
s_DisableAllColors(attr, false); // turn off all color flags first.
attr |= BACKGROUND_GREEN;
_changedBackground = true;
break;
case DispatchTypes::GraphicsOptions::BackgroundCyan:
s_DisableAllColors(pAttr, false); // turn off all color flags first.
*pAttr |= BACKGROUND_BLUE | BACKGROUND_GREEN;
_fChangedBackground = true;
s_DisableAllColors(attr, false); // turn off all color flags first.
attr |= BACKGROUND_BLUE | BACKGROUND_GREEN;
_changedBackground = true;
break;
case DispatchTypes::GraphicsOptions::BackgroundRed:
s_DisableAllColors(pAttr, false); // turn off all color flags first.
*pAttr |= BACKGROUND_RED;
_fChangedBackground = true;
s_DisableAllColors(attr, false); // turn off all color flags first.
attr |= BACKGROUND_RED;
_changedBackground = true;
break;
case DispatchTypes::GraphicsOptions::BackgroundMagenta:
s_DisableAllColors(pAttr, false); // turn off all color flags first.
*pAttr |= BACKGROUND_BLUE | BACKGROUND_RED;
_fChangedBackground = true;
s_DisableAllColors(attr, false); // turn off all color flags first.
attr |= BACKGROUND_BLUE | BACKGROUND_RED;
_changedBackground = true;
break;
case DispatchTypes::GraphicsOptions::BackgroundYellow:
s_DisableAllColors(pAttr, false); // turn off all color flags first.
*pAttr |= BACKGROUND_GREEN | BACKGROUND_RED;
_fChangedBackground = true;
s_DisableAllColors(attr, false); // turn off all color flags first.
attr |= BACKGROUND_GREEN | BACKGROUND_RED;
_changedBackground = true;
break;
case DispatchTypes::GraphicsOptions::BackgroundWhite:
s_DisableAllColors(pAttr, false); // turn off all color flags first.
*pAttr |= BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED;
_fChangedBackground = true;
s_DisableAllColors(attr, false); // turn off all color flags first.
attr |= BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED;
_changedBackground = true;
break;
case DispatchTypes::GraphicsOptions::BackgroundDefault:
FAIL_FAST_MSG("GraphicsOptions::BackgroundDefault should be handled by _SetDefaultColorHelper");
break;
case DispatchTypes::GraphicsOptions::BrightForegroundBlack:
_SetGraphicsOptionHelper(GraphicsOptions::ForegroundBlack, pAttr);
*pAttr |= FOREGROUND_INTENSITY;
_fChangedForeground = true;
_SetGraphicsOptionHelper(GraphicsOptions::ForegroundBlack, attr);
attr |= FOREGROUND_INTENSITY;
_changedForeground = true;
break;
case DispatchTypes::GraphicsOptions::BrightForegroundBlue:
_SetGraphicsOptionHelper(GraphicsOptions::ForegroundBlue, pAttr);
*pAttr |= FOREGROUND_INTENSITY;
_fChangedForeground = true;
_SetGraphicsOptionHelper(GraphicsOptions::ForegroundBlue, attr);
attr |= FOREGROUND_INTENSITY;
_changedForeground = true;
break;
case DispatchTypes::GraphicsOptions::BrightForegroundGreen:
_SetGraphicsOptionHelper(GraphicsOptions::ForegroundGreen, pAttr);
*pAttr |= FOREGROUND_INTENSITY;
_fChangedForeground = true;
_SetGraphicsOptionHelper(GraphicsOptions::ForegroundGreen, attr);
attr |= FOREGROUND_INTENSITY;
_changedForeground = true;
break;
case DispatchTypes::GraphicsOptions::BrightForegroundCyan:
_SetGraphicsOptionHelper(GraphicsOptions::ForegroundCyan, pAttr);
*pAttr |= FOREGROUND_INTENSITY;
_fChangedForeground = true;
_SetGraphicsOptionHelper(GraphicsOptions::ForegroundCyan, attr);
attr |= FOREGROUND_INTENSITY;
_changedForeground = true;
break;
case DispatchTypes::GraphicsOptions::BrightForegroundRed:
_SetGraphicsOptionHelper(GraphicsOptions::ForegroundRed, pAttr);
*pAttr |= FOREGROUND_INTENSITY;
_fChangedForeground = true;
_SetGraphicsOptionHelper(GraphicsOptions::ForegroundRed, attr);
attr |= FOREGROUND_INTENSITY;
_changedForeground = true;
break;
case DispatchTypes::GraphicsOptions::BrightForegroundMagenta:
_SetGraphicsOptionHelper(GraphicsOptions::ForegroundMagenta, pAttr);
*pAttr |= FOREGROUND_INTENSITY;
_fChangedForeground = true;
_SetGraphicsOptionHelper(GraphicsOptions::ForegroundMagenta, attr);
attr |= FOREGROUND_INTENSITY;
_changedForeground = true;
break;
case DispatchTypes::GraphicsOptions::BrightForegroundYellow:
_SetGraphicsOptionHelper(GraphicsOptions::ForegroundYellow, pAttr);
*pAttr |= FOREGROUND_INTENSITY;
_fChangedForeground = true;
_SetGraphicsOptionHelper(GraphicsOptions::ForegroundYellow, attr);
attr |= FOREGROUND_INTENSITY;
_changedForeground = true;
break;
case DispatchTypes::GraphicsOptions::BrightForegroundWhite:
_SetGraphicsOptionHelper(GraphicsOptions::ForegroundWhite, pAttr);
*pAttr |= FOREGROUND_INTENSITY;
_fChangedForeground = true;
_SetGraphicsOptionHelper(GraphicsOptions::ForegroundWhite, attr);
attr |= FOREGROUND_INTENSITY;
_changedForeground = true;
break;
case DispatchTypes::GraphicsOptions::BrightBackgroundBlack:
_SetGraphicsOptionHelper(GraphicsOptions::BackgroundBlack, pAttr);
*pAttr |= BACKGROUND_INTENSITY;
_fChangedBackground = true;
_SetGraphicsOptionHelper(GraphicsOptions::BackgroundBlack, attr);
attr |= BACKGROUND_INTENSITY;
_changedBackground = true;
break;
case DispatchTypes::GraphicsOptions::BrightBackgroundBlue:
_SetGraphicsOptionHelper(GraphicsOptions::BackgroundBlue, pAttr);
*pAttr |= BACKGROUND_INTENSITY;
_fChangedBackground = true;
_SetGraphicsOptionHelper(GraphicsOptions::BackgroundBlue, attr);
attr |= BACKGROUND_INTENSITY;
_changedBackground = true;
break;
case DispatchTypes::GraphicsOptions::BrightBackgroundGreen:
_SetGraphicsOptionHelper(GraphicsOptions::BackgroundGreen, pAttr);
*pAttr |= BACKGROUND_INTENSITY;
_fChangedBackground = true;
_SetGraphicsOptionHelper(GraphicsOptions::BackgroundGreen, attr);
attr |= BACKGROUND_INTENSITY;
_changedBackground = true;
break;
case DispatchTypes::GraphicsOptions::BrightBackgroundCyan:
_SetGraphicsOptionHelper(GraphicsOptions::BackgroundCyan, pAttr);
*pAttr |= BACKGROUND_INTENSITY;
_fChangedBackground = true;
_SetGraphicsOptionHelper(GraphicsOptions::BackgroundCyan, attr);
attr |= BACKGROUND_INTENSITY;
_changedBackground = true;
break;
case DispatchTypes::GraphicsOptions::BrightBackgroundRed:
_SetGraphicsOptionHelper(GraphicsOptions::BackgroundRed, pAttr);
*pAttr |= BACKGROUND_INTENSITY;
_fChangedBackground = true;
_SetGraphicsOptionHelper(GraphicsOptions::BackgroundRed, attr);
attr |= BACKGROUND_INTENSITY;
_changedBackground = true;
break;
case DispatchTypes::GraphicsOptions::BrightBackgroundMagenta:
_SetGraphicsOptionHelper(GraphicsOptions::BackgroundMagenta, pAttr);
*pAttr |= BACKGROUND_INTENSITY;
_fChangedBackground = true;
_SetGraphicsOptionHelper(GraphicsOptions::BackgroundMagenta, attr);
attr |= BACKGROUND_INTENSITY;
_changedBackground = true;
break;
case DispatchTypes::GraphicsOptions::BrightBackgroundYellow:
_SetGraphicsOptionHelper(GraphicsOptions::BackgroundYellow, pAttr);
*pAttr |= BACKGROUND_INTENSITY;
_fChangedBackground = true;
_SetGraphicsOptionHelper(GraphicsOptions::BackgroundYellow, attr);
attr |= BACKGROUND_INTENSITY;
_changedBackground = true;
break;
case DispatchTypes::GraphicsOptions::BrightBackgroundWhite:
_SetGraphicsOptionHelper(GraphicsOptions::BackgroundWhite, pAttr);
*pAttr |= BACKGROUND_INTENSITY;
_fChangedBackground = true;
_SetGraphicsOptionHelper(GraphicsOptions::BackgroundWhite, attr);
attr |= BACKGROUND_INTENSITY;
_changedBackground = true;
break;
}
}
@ -331,13 +331,10 @@ bool AdaptDispatch::s_IsDefaultColorOption(const DispatchTypes::GraphicsOptions
// RGB sequences then take 3 MORE params to designate the R, G, B parts of the color
// Xterm index will use the param that follows to use a color from the preset 256 color xterm color table.
// Arguments:
// - rgOptions - An array of options that will be used to generate the RGB color
// - cOptions - The count of options
// - prgbColor - A pointer to place the generated RGB color into.
// - pfIsForeground - a pointer to place whether or not the parsed color is for the foreground or not.
// - pcOptionsConsumed - a pointer to place the number of options we consumed parsing this option.
// - ColorTable - the windows color table, for xterm indices < 16
// - cColorTable - The number of elements in the windows color table.
// - options - An array of options that will be used to generate the RGB color
// - rgbColor - Location to place the generated RGB color into.
// - isForeground - Location to place whether or not the parsed color is for the foreground or not.
// - optionsConsumed - Location to place the number of options we consumed parsing this option.
// Return Value:
// Returns true if we successfully parsed an extended color option from the options array.
// - This corresponds to the following number of options consumed (pcOptionsConsumed):
@ -345,59 +342,58 @@ bool AdaptDispatch::s_IsDefaultColorOption(const DispatchTypes::GraphicsOptions
// 2 - false, not enough options to parse.
// 3 - true, parsed an xterm index to a color
// 5 - true, parsed an RGB color.
bool AdaptDispatch::_SetRgbColorsHelper(_In_reads_(cOptions) const DispatchTypes::GraphicsOptions* const rgOptions,
const size_t cOptions,
_Out_ COLORREF* const prgbColor,
_Out_ bool* const pfIsForeground,
_Out_ size_t* const pcOptionsConsumed)
bool AdaptDispatch::_SetRgbColorsHelper(const std::basic_string_view<DispatchTypes::GraphicsOptions> options,
COLORREF& rgbColor,
bool& isForeground,
size_t& optionsConsumed)
{
bool fSuccess = false;
*pcOptionsConsumed = 1;
if (cOptions >= 2 && s_IsRgbColorOption(rgOptions[0]))
bool success = false;
optionsConsumed = 1;
if (options.size() >= 2 && s_IsRgbColorOption(options.at(0)))
{
*pcOptionsConsumed = 2;
DispatchTypes::GraphicsOptions extendedOpt = rgOptions[0];
DispatchTypes::GraphicsOptions typeOpt = rgOptions[1];
optionsConsumed = 2;
DispatchTypes::GraphicsOptions extendedOpt = options.at(0);
DispatchTypes::GraphicsOptions typeOpt = options.at(1);
if (extendedOpt == DispatchTypes::GraphicsOptions::ForegroundExtended)
{
*pfIsForeground = true;
isForeground = true;
}
else if (extendedOpt == DispatchTypes::GraphicsOptions::BackgroundExtended)
{
*pfIsForeground = false;
isForeground = false;
}
if (typeOpt == DispatchTypes::GraphicsOptions::RGBColorOrFaint && cOptions >= 5)
if (typeOpt == DispatchTypes::GraphicsOptions::RGBColorOrFaint && options.size() >= 5)
{
*pcOptionsConsumed = 5;
optionsConsumed = 5;
// ensure that each value fits in a byte
unsigned int red = rgOptions[2] > 255 ? 255 : rgOptions[2];
unsigned int green = rgOptions[3] > 255 ? 255 : rgOptions[3];
unsigned int blue = rgOptions[4] > 255 ? 255 : rgOptions[4];
unsigned int red = std::min(static_cast<unsigned int>(options.at(2)), 255u);
unsigned int green = std::min(static_cast<unsigned int>(options.at(3)), 255u);
unsigned int blue = std::min(static_cast<unsigned int>(options.at(4)), 255u);
*prgbColor = RGB(red, green, blue);
rgbColor = RGB(red, green, blue);
fSuccess = !!_conApi->SetConsoleRGBTextAttribute(*prgbColor, *pfIsForeground);
success = _pConApi->SetConsoleRGBTextAttribute(rgbColor, isForeground);
}
else if (typeOpt == DispatchTypes::GraphicsOptions::BlinkOrXterm256Index && cOptions >= 3)
else if (typeOpt == DispatchTypes::GraphicsOptions::BlinkOrXterm256Index && options.size() >= 3)
{
*pcOptionsConsumed = 3;
if (rgOptions[2] <= 255) // ensure that the provided index is on the table
optionsConsumed = 3;
if (options.at(2) <= 255) // ensure that the provided index is on the table
{
unsigned int tableIndex = rgOptions[2];
unsigned int tableIndex = options.at(2);
fSuccess = !!_conApi->SetConsoleXtermTextAttribute(tableIndex, *pfIsForeground);
success = _pConApi->SetConsoleXtermTextAttribute(tableIndex, isForeground);
}
}
}
return fSuccess;
return success;
}
bool AdaptDispatch::_SetBoldColorHelper(const DispatchTypes::GraphicsOptions option)
{
const bool bold = (option == DispatchTypes::GraphicsOptions::BoldBright);
return !!_conApi->PrivateBoldText(bold);
return _pConApi->PrivateBoldText(bold);
}
bool AdaptDispatch::_SetDefaultColorHelper(const DispatchTypes::GraphicsOptions option)
@ -405,15 +401,15 @@ bool AdaptDispatch::_SetDefaultColorHelper(const DispatchTypes::GraphicsOptions
const bool fg = option == GraphicsOptions::Off || option == GraphicsOptions::ForegroundDefault;
const bool bg = option == GraphicsOptions::Off || option == GraphicsOptions::BackgroundDefault;
bool success = _conApi->PrivateSetDefaultAttributes(fg, bg);
bool success = _pConApi->PrivateSetDefaultAttributes(fg, bg);
if (success && fg && bg)
{
// If we're resetting both the FG & BG, also reset the meta attributes (underline)
// as well as the boldness
success = _conApi->PrivateSetLegacyAttributes(0, false, false, true) &&
_conApi->PrivateBoldText(false) &&
_conApi->PrivateSetExtendedTextAttributes(ExtendedAttributes::Normal);
success = _pConApi->PrivateSetLegacyAttributes(0, false, false, true) &&
_pConApi->PrivateBoldText(false) &&
_pConApi->PrivateSetExtendedTextAttributes(ExtendedAttributes::Normal);
}
return success;
}
@ -432,7 +428,7 @@ bool AdaptDispatch::_SetExtendedTextAttributeHelper(const DispatchTypes::Graphic
{
ExtendedAttributes attrs{ ExtendedAttributes::Normal };
RETURN_BOOL_IF_FALSE(_conApi->PrivateGetExtendedTextAttributes(&attrs));
RETURN_BOOL_IF_FALSE(_pConApi->PrivateGetExtendedTextAttributes(attrs));
switch (opt)
{
@ -466,7 +462,7 @@ bool AdaptDispatch::_SetExtendedTextAttributeHelper(const DispatchTypes::Graphic
// case DispatchTypes::GraphicsOptions::DoublyUnderlined:
}
return _conApi->PrivateSetExtendedTextAttributes(attrs);
return _pConApi->PrivateSetExtendedTextAttributes(attrs);
}
// Routine Description:
@ -476,13 +472,11 @@ bool AdaptDispatch::_SetExtendedTextAttributeHelper(const DispatchTypes::Graphic
// type options.
// Arguments:
// - rgOptions - An array of options that will be applied from 0 to N, in order,
// - options - An array of options that will be applied from 0 to N, in order,
// one at a time by setting or removing flags in the font style properties.
// - cOptions - The count of options (a.k.a. the N in the above line of comments)
// Return Value:
// - True if handled successfully. False otherwise.
bool AdaptDispatch::SetGraphicsRendition(_In_reads_(cOptions) const DispatchTypes::GraphicsOptions* const rgOptions,
const size_t cOptions)
bool AdaptDispatch::SetGraphicsRendition(const std::basic_string_view<DispatchTypes::GraphicsOptions> options)
{
// We use the private function here to get just the default color attributes
// as a performance optimization. Calling the public
@ -491,62 +485,61 @@ bool AdaptDispatch::SetGraphicsRendition(_In_reads_(cOptions) const DispatchType
// 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 success = _pConApi->PrivateGetConsoleScreenBufferAttributes(attr);
if (fSuccess)
if (success)
{
// Run through the graphics options and apply them
for (size_t i = 0; i < cOptions; i++)
for (size_t i = 0; i < options.size(); i++)
{
DispatchTypes::GraphicsOptions opt = rgOptions[i];
DispatchTypes::GraphicsOptions opt = options.at(i);
if (s_IsDefaultColorOption(opt))
{
fSuccess = _SetDefaultColorHelper(opt);
success = _SetDefaultColorHelper(opt);
}
else if (s_IsBoldColorOption(opt))
{
fSuccess = _SetBoldColorHelper(rgOptions[i]);
success = _SetBoldColorHelper(opt);
}
else if (s_IsExtendedTextAttribute(opt))
{
fSuccess = _SetExtendedTextAttributeHelper(rgOptions[i]);
success = _SetExtendedTextAttributeHelper(opt);
}
else if (s_IsRgbColorOption(opt))
{
COLORREF rgbColor;
bool fIsForeground = true;
bool isForeground = true;
size_t cOptionsConsumed = 0;
size_t optionsConsumed = 0;
// _SetRgbColorsHelper will call the appropriate ConApi function
fSuccess = _SetRgbColorsHelper(&(rgOptions[i]),
cOptions - i,
&rgbColor,
&fIsForeground,
&cOptionsConsumed);
success = _SetRgbColorsHelper(options.substr(i),
rgbColor,
isForeground,
optionsConsumed);
i += (cOptionsConsumed - 1); // cOptionsConsumed includes the opt we're currently on.
i += (optionsConsumed - 1); // cOptionsConsumed includes the opt we're currently on.
}
else
{
_SetGraphicsOptionHelper(opt, &attr);
fSuccess = !!_conApi->PrivateSetLegacyAttributes(attr,
_fChangedForeground,
_fChangedBackground,
_fChangedMetaAttrs);
_SetGraphicsOptionHelper(opt, attr);
success = _pConApi->PrivateSetLegacyAttributes(attr,
_changedForeground,
_changedBackground,
_changedMetaAttrs);
// Make sure we un-bold
if (fSuccess && opt == DispatchTypes::GraphicsOptions::Off)
if (success && opt == DispatchTypes::GraphicsOptions::Off)
{
fSuccess = _SetBoldColorHelper(opt);
success = _SetBoldColorHelper(opt);
}
_fChangedForeground = false;
_fChangedBackground = false;
_fChangedMetaAttrs = false;
_changedForeground = false;
_changedBackground = false;
_changedMetaAttrs = false;
}
}
}
return fSuccess;
return success;
}

View file

@ -27,87 +27,87 @@ namespace Microsoft::Console::VirtualTerminal
class ConGetSet
{
public:
virtual BOOL GetConsoleCursorInfo(_In_ CONSOLE_CURSOR_INFO* const pConsoleCursorInfo) const = 0;
virtual BOOL GetConsoleScreenBufferInfoEx(_Out_ CONSOLE_SCREEN_BUFFER_INFOEX* const pConsoleScreenBufferInfoEx) const = 0;
virtual BOOL SetConsoleScreenBufferInfoEx(const CONSOLE_SCREEN_BUFFER_INFOEX* const pConsoleScreenBufferInfoEx) = 0;
virtual BOOL SetConsoleCursorInfo(const CONSOLE_CURSOR_INFO* const pConsoleCursorInfo) = 0;
virtual BOOL SetConsoleCursorPosition(const COORD coordCursorPosition) = 0;
virtual BOOL SetConsoleTextAttribute(const WORD wAttr) = 0;
virtual bool GetConsoleCursorInfo(CONSOLE_CURSOR_INFO& cursorInfo) const = 0;
virtual bool GetConsoleScreenBufferInfoEx(CONSOLE_SCREEN_BUFFER_INFOEX& screenBufferInfo) const = 0;
virtual bool SetConsoleScreenBufferInfoEx(const CONSOLE_SCREEN_BUFFER_INFOEX& screenBufferInfo) = 0;
virtual bool SetConsoleCursorInfo(const CONSOLE_CURSOR_INFO& cursorInfo) = 0;
virtual bool SetConsoleCursorPosition(const COORD position) = 0;
virtual bool SetConsoleTextAttribute(const WORD attr) = 0;
virtual BOOL PrivateSetLegacyAttributes(const WORD wAttr,
const bool fForeground,
const bool fBackground,
const bool fMeta) = 0;
virtual bool PrivateSetLegacyAttributes(const WORD attr,
const bool foreground,
const bool background,
const bool meta) = 0;
virtual BOOL PrivateSetDefaultAttributes(const bool fForeground, const bool fBackground) = 0;
virtual bool PrivateSetDefaultAttributes(const bool foreground, const bool background) = 0;
virtual BOOL SetConsoleXtermTextAttribute(const int iXtermTableEntry,
const bool fIsForeground) = 0;
virtual BOOL SetConsoleRGBTextAttribute(const COLORREF rgbColor, const bool fIsForeground) = 0;
virtual BOOL PrivateBoldText(const bool bolded) = 0;
virtual BOOL PrivateGetExtendedTextAttributes(ExtendedAttributes* const pAttrs) = 0;
virtual BOOL PrivateSetExtendedTextAttributes(const ExtendedAttributes attrs) = 0;
virtual BOOL PrivateGetTextAttributes(TextAttribute* const pAttrs) const = 0;
virtual BOOL PrivateSetTextAttributes(const TextAttribute& attrs) = 0;
virtual bool SetConsoleXtermTextAttribute(const int xtermTableEntry,
const bool isForeground) = 0;
virtual bool SetConsoleRGBTextAttribute(const COLORREF rgbColor, const bool isForeground) = 0;
virtual bool PrivateBoldText(const bool bolded) = 0;
virtual bool PrivateGetExtendedTextAttributes(ExtendedAttributes& attrs) = 0;
virtual bool PrivateSetExtendedTextAttributes(const ExtendedAttributes attrs) = 0;
virtual bool PrivateGetTextAttributes(TextAttribute& attrs) const = 0;
virtual bool PrivateSetTextAttributes(const TextAttribute& attrs) = 0;
virtual BOOL PrivateWriteConsoleInputW(_Inout_ std::deque<std::unique_ptr<IInputEvent>>& events,
_Out_ size_t& eventsWritten) = 0;
virtual BOOL SetConsoleWindowInfo(const BOOL bAbsolute,
const SMALL_RECT* const lpConsoleWindow) = 0;
virtual BOOL PrivateSetCursorKeysMode(const bool fApplicationMode) = 0;
virtual BOOL PrivateSetKeypadMode(const bool fApplicationMode) = 0;
virtual bool PrivateWriteConsoleInputW(std::deque<std::unique_ptr<IInputEvent>>& events,
size_t& eventsWritten) = 0;
virtual bool SetConsoleWindowInfo(const bool absolute,
const SMALL_RECT& window) = 0;
virtual bool PrivateSetCursorKeysMode(const bool applicationMode) = 0;
virtual bool PrivateSetKeypadMode(const bool applicationMode) = 0;
virtual BOOL PrivateShowCursor(const bool show) = 0;
virtual BOOL PrivateAllowCursorBlinking(const bool fEnable) = 0;
virtual bool PrivateShowCursor(const bool show) = 0;
virtual bool PrivateAllowCursorBlinking(const bool enable) = 0;
virtual BOOL PrivateSetScrollingRegion(const SMALL_RECT* const psrScrollMargins) = 0;
virtual BOOL PrivateReverseLineFeed() = 0;
virtual BOOL SetConsoleTitleW(const std::wstring_view title) = 0;
virtual BOOL PrivateUseAlternateScreenBuffer() = 0;
virtual BOOL PrivateUseMainScreenBuffer() = 0;
virtual BOOL PrivateHorizontalTabSet() = 0;
virtual BOOL PrivateForwardTab(const SHORT sNumTabs) = 0;
virtual BOOL PrivateBackwardsTab(const SHORT sNumTabs) = 0;
virtual BOOL PrivateTabClear(const bool fClearAll) = 0;
virtual BOOL PrivateSetDefaultTabStops() = 0;
virtual bool PrivateSetScrollingRegion(const SMALL_RECT& scrollMargins) = 0;
virtual bool PrivateReverseLineFeed() = 0;
virtual bool SetConsoleTitleW(const std::wstring_view title) = 0;
virtual bool PrivateUseAlternateScreenBuffer() = 0;
virtual bool PrivateUseMainScreenBuffer() = 0;
virtual bool PrivateHorizontalTabSet() = 0;
virtual bool PrivateForwardTab(const size_t numTabs) = 0;
virtual bool PrivateBackwardsTab(const size_t numTabs) = 0;
virtual bool PrivateTabClear(const bool clearAll) = 0;
virtual bool PrivateSetDefaultTabStops() = 0;
virtual BOOL PrivateEnableVT200MouseMode(const bool fEnabled) = 0;
virtual BOOL PrivateEnableUTF8ExtendedMouseMode(const bool fEnabled) = 0;
virtual BOOL PrivateEnableSGRExtendedMouseMode(const bool fEnabled) = 0;
virtual BOOL PrivateEnableButtonEventMouseMode(const bool fEnabled) = 0;
virtual BOOL PrivateEnableAnyEventMouseMode(const bool fEnabled) = 0;
virtual BOOL PrivateEnableAlternateScroll(const bool fEnabled) = 0;
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 PrivatePrependConsoleInput(_Inout_ std::deque<std::unique_ptr<IInputEvent>>& events,
_Out_ size_t& eventsWritten) = 0;
virtual BOOL PrivateWriteConsoleControlInput(_In_ KeyEvent key) = 0;
virtual BOOL PrivateRefreshWindow() = 0;
virtual bool PrivateEnableVT200MouseMode(const bool enabled) = 0;
virtual bool PrivateEnableUTF8ExtendedMouseMode(const bool enabled) = 0;
virtual bool PrivateEnableSGRExtendedMouseMode(const bool enabled) = 0;
virtual bool PrivateEnableButtonEventMouseMode(const bool enabled) = 0;
virtual bool PrivateEnableAnyEventMouseMode(const bool enabled) = 0;
virtual bool PrivateEnableAlternateScroll(const bool enabled) = 0;
virtual bool PrivateEraseAll() = 0;
virtual bool SetCursorStyle(const CursorType style) = 0;
virtual bool SetCursorColor(const COLORREF color) = 0;
virtual bool PrivateGetConsoleScreenBufferAttributes(WORD& attributes) = 0;
virtual bool PrivatePrependConsoleInput(std::deque<std::unique_ptr<IInputEvent>>& events,
size_t& eventsWritten) = 0;
virtual bool PrivateWriteConsoleControlInput(const KeyEvent key) = 0;
virtual bool PrivateRefreshWindow() = 0;
virtual BOOL GetConsoleOutputCP(_Out_ unsigned int* const puiOutputCP) = 0;
virtual bool GetConsoleOutputCP(unsigned int& codepage) = 0;
virtual BOOL PrivateSuppressResizeRepaint() = 0;
virtual BOOL IsConsolePty(_Out_ bool* const pIsPty) const = 0;
virtual bool PrivateSuppressResizeRepaint() = 0;
virtual bool IsConsolePty(bool& isPty) const = 0;
virtual BOOL MoveCursorVertically(const short lines) = 0;
virtual bool MoveCursorVertically(const ptrdiff_t lines) = 0;
virtual BOOL DeleteLines(const unsigned int count) = 0;
virtual BOOL InsertLines(const unsigned int count) = 0;
virtual bool DeleteLines(const size_t count) = 0;
virtual bool InsertLines(const size_t count) = 0;
virtual BOOL MoveToBottom() const = 0;
virtual bool MoveToBottom() const = 0;
virtual BOOL PrivateSetColorTableEntry(const short index, const COLORREF value) const = 0;
virtual BOOL PrivateSetDefaultForeground(const COLORREF value) const = 0;
virtual BOOL PrivateSetDefaultBackground(const COLORREF value) const = 0;
virtual bool PrivateSetColorTableEntry(const short index, const COLORREF value) const = 0;
virtual bool PrivateSetDefaultForeground(const COLORREF value) const = 0;
virtual bool PrivateSetDefaultBackground(const COLORREF value) const = 0;
virtual BOOL PrivateFillRegion(const COORD startPosition,
virtual bool PrivateFillRegion(const COORD startPosition,
const size_t fillLength,
const wchar_t fillChar,
const bool standardFillAttrs) = 0;
virtual BOOL PrivateScrollRegion(const SMALL_RECT scrollRect,
virtual bool PrivateScrollRegion(const SMALL_RECT scrollRect,
const std::optional<SMALL_RECT> clipRect,
const COORD destinationOrigin,
const bool standardFillAttrs) = 0;

View file

@ -22,63 +22,60 @@ class Microsoft::Console::VirtualTerminal::TermDispatch : public Microsoft::Cons
public:
void Execute(const wchar_t wchControl) override = 0;
void Print(const wchar_t wchPrintable) override = 0;
void PrintString(const wchar_t* const rgwch, const size_t cch) override = 0;
void PrintString(const std::wstring_view string) override = 0;
bool CursorUp(const unsigned int /*uiDistance*/) override { return false; } // CUU
bool CursorDown(const unsigned int /*uiDistance*/) override { return false; } // CUD
bool CursorForward(const unsigned int /*uiDistance*/) override { return false; } // CUF
bool CursorBackward(const unsigned int /*uiDistance*/) override { return false; } // CUB
bool CursorNextLine(const unsigned int /*uiDistance*/) override { return false; } // CNL
bool CursorPrevLine(const unsigned int /*uiDistance*/) override { return false; } // CPL
bool CursorHorizontalPositionAbsolute(const unsigned int /*uiColumn*/) override { return false; } // CHA
bool VerticalLinePositionAbsolute(const unsigned int /*uiLine*/) override { return false; } // VPA
bool CursorPosition(const unsigned int /*uiLine*/, const unsigned int /*uiColumn*/) override { return false; } // CUP
bool CursorUp(const size_t /*distance*/) override { return false; } // CUU
bool CursorDown(const size_t /*distance*/) override { return false; } // CUD
bool CursorForward(const size_t /*distance*/) override { return false; } // CUF
bool CursorBackward(const size_t /*distance*/) override { return false; } // CUB
bool CursorNextLine(const size_t /*distance*/) override { return false; } // CNL
bool CursorPrevLine(const size_t /*distance*/) override { return false; } // CPL
bool CursorHorizontalPositionAbsolute(const size_t /*column*/) override { return false; } // CHA
bool VerticalLinePositionAbsolute(const size_t /*line*/) override { return false; } // VPA
bool CursorPosition(const size_t /*line*/, const size_t /*column*/) override { return false; } // CUP
bool CursorSaveState() override { return false; } // DECSC
bool CursorRestoreState() override { return false; } // DECRC
bool CursorVisibility(const bool /*fIsVisible*/) override { return false; } // DECTCEM
bool InsertCharacter(const unsigned int /*uiCount*/) override { return false; } // ICH
bool DeleteCharacter(const unsigned int /*uiCount*/) override { return false; } // DCH
bool ScrollUp(const unsigned int /*uiDistance*/) override { return false; } // SU
bool ScrollDown(const unsigned int /*uiDistance*/) override { return false; } // SD
bool InsertLine(const unsigned int /*uiDistance*/) override { return false; } // IL
bool DeleteLine(const unsigned int /*uiDistance*/) override { return false; } // DL
bool SetColumns(const unsigned int /*uiColumns*/) override { return false; } // DECSCPP, DECCOLM
bool SetCursorKeysMode(const bool /*fApplicationMode*/) override { return false; } // DECCKM
bool SetKeypadMode(const bool /*fApplicationMode*/) override { return false; } // DECKPAM, DECKPNM
bool EnableCursorBlinking(const bool /*fEnable*/) override { return false; } // ATT610
bool SetOriginMode(const bool /*fRelativeMode*/) override { return false; }; // DECOM
bool SetTopBottomScrollingMargins(const SHORT /*sTopMargin*/, const SHORT /*sBottomMargin*/) override { return false; } // DECSTBM
bool CursorVisibility(const bool /*isVisible*/) override { return false; } // DECTCEM
bool InsertCharacter(const size_t /*count*/) override { return false; } // ICH
bool DeleteCharacter(const size_t /*count*/) override { return false; } // DCH
bool ScrollUp(const size_t /*distance*/) override { return false; } // SU
bool ScrollDown(const size_t /*distance*/) override { return false; } // SD
bool InsertLine(const size_t /*distance*/) override { return false; } // IL
bool DeleteLine(const size_t /*distance*/) override { return false; } // DL
bool SetColumns(const size_t /*columns*/) override { return false; } // DECSCPP, DECCOLM
bool SetCursorKeysMode(const bool /*applicationMode*/) override { return false; } // DECCKM
bool SetKeypadMode(const bool /*applicationMode*/) override { return false; } // DECKPAM, DECKPNM
bool EnableCursorBlinking(const bool /*enable*/) override { return false; } // ATT610
bool SetOriginMode(const bool /*relativeMode*/) override { return false; }; // DECOM
bool SetTopBottomScrollingMargins(const size_t /*topMargin*/, const size_t /*bottomMargin*/) override { return false; } // DECSTBM
bool ReverseLineFeed() override { return false; } // RI
bool SetWindowTitle(std::wstring_view /*title*/) override { return false; } // OscWindowTitle
bool UseAlternateScreenBuffer() override { return false; } // ASBSET
bool UseMainScreenBuffer() override { return false; } // ASBRST
bool HorizontalTabSet() override { return false; } // HTS
bool ForwardTab(const SHORT /*sNumTabs*/) override { return false; } // CHT
bool BackwardsTab(const SHORT /*sNumTabs*/) override { return false; } // CBT
bool TabClear(const SHORT /*sClearType*/) override { return false; } // TBC
bool EnableDECCOLMSupport(const bool /*fEnabled*/) override { return false; } // ?40
bool EnableVT200MouseMode(const bool /*fEnabled*/) override { return false; } // ?1000
bool EnableUTF8ExtendedMouseMode(const bool /*fEnabled*/) override { return false; } // ?1005
bool EnableSGRExtendedMouseMode(const bool /*fEnabled*/) override { return false; } // ?1006
bool EnableButtonEventMouseMode(const bool /*fEnabled*/) override { return false; } // ?1002
bool EnableAnyEventMouseMode(const bool /*fEnabled*/) override { return false; } // ?1003
bool EnableAlternateScroll(const bool /*fEnabled*/) override { return false; } // ?1007
bool SetColorTableEntry(const size_t /*tableIndex*/, const DWORD /*dwColor*/) override { return false; } // OSCColorTable
bool SetDefaultForeground(const DWORD /*dwColor*/) override { return false; } // OSCDefaultForeground
bool SetDefaultBackground(const DWORD /*dwColor*/) override { return false; } // OSCDefaultBackground
bool ForwardTab(const size_t /*numTabs*/) override { return false; } // CHT
bool BackwardsTab(const size_t /*numTabs*/) override { return false; } // CBT
bool TabClear(const size_t /*clearType*/) override { return false; } // TBC
bool EnableDECCOLMSupport(const bool /*enabled*/) override { return false; } // ?40
bool EnableVT200MouseMode(const bool /*enabled*/) override { return false; } // ?1000
bool EnableUTF8ExtendedMouseMode(const bool /*enabled*/) override { return false; } // ?1005
bool EnableSGRExtendedMouseMode(const bool /*enabled*/) override { return false; } // ?1006
bool EnableButtonEventMouseMode(const bool /*enabled*/) override { return false; } // ?1002
bool EnableAnyEventMouseMode(const bool /*enabled*/) override { return false; } // ?1003
bool EnableAlternateScroll(const bool /*enabled*/) override { return false; } // ?1007
bool SetColorTableEntry(const size_t /*tableIndex*/, const DWORD /*color*/) override { return false; } // OSCColorTable
bool SetDefaultForeground(const DWORD /*color*/) override { return false; } // OSCDefaultForeground
bool SetDefaultBackground(const DWORD /*color*/) override { return false; } // OSCDefaultBackground
bool EraseInDisplay(const DispatchTypes::EraseType /* eraseType*/) override { return false; } // ED
bool EraseInLine(const DispatchTypes::EraseType /* eraseType*/) override { return false; } // EL
bool EraseCharacters(const unsigned int /*uiNumChars*/) override { return false; } // ECH
bool EraseCharacters(const size_t /*numChars*/) override { return false; } // ECH
bool SetGraphicsRendition(_In_reads_(_Param_(2)) const DispatchTypes::GraphicsOptions* const /*rgOptions*/,
const size_t /*cOptions*/) override { return false; } // SGR
bool SetGraphicsRendition(const std::basic_string_view<DispatchTypes::GraphicsOptions> /*options*/) override { return false; } // SGR
bool SetPrivateModes(_In_reads_(_Param_(2)) const DispatchTypes::PrivateModeParams* const /*rgParams*/,
const size_t /*cParams*/) override { return false; } // DECSET
bool SetPrivateModes(const std::basic_string_view<DispatchTypes::PrivateModeParams> /*params*/) override { return false; } // DECSET
bool ResetPrivateModes(_In_reads_(_Param_(2)) const DispatchTypes::PrivateModeParams* const /*rgParams*/,
const size_t /*cParams*/) override { return false; } // DECRST
bool ResetPrivateModes(const std::basic_string_view<DispatchTypes::PrivateModeParams> /*params*/) override { return false; } // DECRST
bool DeviceStatusReport(const DispatchTypes::AnsiStatusType /*statusType*/) override { return false; } // DSR
bool DeviceAttributes() override { return false; } // DA
@ -90,10 +87,9 @@ public:
bool ScreenAlignmentPattern() override { return false; } // DECALN
bool SetCursorStyle(const DispatchTypes::CursorStyle /*cursorStyle*/) override { return false; } // DECSCUSR
bool SetCursorColor(const COLORREF /*Color*/) override { return false; } // OSCSetCursorColor, OSCResetCursorColor
bool SetCursorColor(const COLORREF /*color*/) override { return false; } // OSCSetCursorColor, OSCResetCursorColor
// DTTERM_WindowManipulation
bool WindowManipulation(const DispatchTypes::WindowManipulationType /*uiFunction*/,
_In_reads_(_Param_(3)) const unsigned short* const /*rgusParams*/,
const size_t /*cParams*/) override { return false; }
bool WindowManipulation(const DispatchTypes::WindowManipulationType /*function*/,
const std::basic_string_view<size_t> /*params*/) override { return false; }
};

File diff suppressed because it is too large Load diff

View file

@ -26,33 +26,26 @@ namespace Microsoft::Console::VirtualTerminal
virtual bool ActionExecute(const wchar_t wch) = 0;
virtual bool ActionExecuteFromEscape(const wchar_t wch) = 0;
virtual bool ActionPrint(const wchar_t wch) = 0;
virtual bool ActionPrintString(const wchar_t* const rgwch,
size_t const cch) = 0;
virtual bool ActionPrintString(const std::wstring_view string) = 0;
virtual bool ActionPassThroughString(const wchar_t* const rgwch,
size_t const cch) = 0;
virtual bool ActionPassThroughString(const std::wstring_view string) = 0;
virtual bool ActionEscDispatch(const wchar_t wch,
const unsigned short cIntermediate,
const wchar_t wchIntermediate) = 0;
const std::basic_string_view<wchar_t> intermediates) = 0;
virtual bool ActionCsiDispatch(const wchar_t wch,
const unsigned short cIntermediate,
const wchar_t wchIntermediate,
_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams) = 0;
const std::basic_string_view<wchar_t> intermediates,
const std::basic_string_view<size_t> parameters) = 0;
virtual bool ActionClear() = 0;
virtual bool ActionIgnore() = 0;
virtual bool ActionOscDispatch(const wchar_t wch,
const unsigned short sOscParam,
_Inout_updates_(cchOscString) wchar_t* const pwchOscStringBuffer,
const unsigned short cchOscString) = 0;
const size_t parameter,
const std::wstring_view string) = 0;
virtual bool ActionSs3Dispatch(const wchar_t wch,
_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams) = 0;
const std::basic_string_view<size_t> parameters) = 0;
virtual bool FlushAtEndOfString() const = 0;
virtual bool DispatchControlCharsFromEscape() const = 0;

File diff suppressed because it is too large Load diff

View file

@ -26,8 +26,8 @@ namespace Microsoft::Console::VirtualTerminal
class InputStateMachineEngine : public IStateMachineEngine
{
public:
InputStateMachineEngine(IInteractDispatch* const pDispatch);
InputStateMachineEngine(IInteractDispatch* const pDispatch,
InputStateMachineEngine(std::unique_ptr<IInteractDispatch> pDispatch);
InputStateMachineEngine(std::unique_ptr<IInteractDispatch> pDispatch,
const bool lookingForDSR);
bool ActionExecute(const wchar_t wch) override;
@ -35,34 +35,27 @@ namespace Microsoft::Console::VirtualTerminal
bool ActionPrint(const wchar_t wch) override;
bool ActionPrintString(const wchar_t* const rgwch,
const size_t cch) override;
bool ActionPrintString(const std::wstring_view string) override;
bool ActionPassThroughString(const wchar_t* const rgwch,
size_t const cch) override;
bool ActionPassThroughString(const std::wstring_view string) override;
bool ActionEscDispatch(const wchar_t wch,
const unsigned short cIntermediate,
const wchar_t wchIntermediate) override;
const std::basic_string_view<wchar_t> intermediates) override;
bool ActionCsiDispatch(const wchar_t wch,
const unsigned short cIntermediate,
const wchar_t wchIntermediate,
_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams);
const std::basic_string_view<wchar_t> intermediates,
const std::basic_string_view<size_t> parameters) override;
bool ActionClear() override;
bool ActionIgnore() override;
bool ActionOscDispatch(const wchar_t wch,
const unsigned short sOscParam,
_Inout_updates_(cchOscString) wchar_t* const pwchOscStringBuffer,
const unsigned short cchOscString) override;
const size_t parameter,
const std::wstring_view string) override;
bool ActionSs3Dispatch(const wchar_t wch,
_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams) override;
const std::basic_string_view<size_t> parameters) override;
bool FlushAtEndOfString() const override;
bool DispatchControlCharsFromEscape() const override;
@ -72,121 +65,39 @@ namespace Microsoft::Console::VirtualTerminal
const std::unique_ptr<IInteractDispatch> _pDispatch;
bool _lookingForDSR;
enum CsiActionCodes : wchar_t
{
ArrowUp = L'A',
ArrowDown = L'B',
ArrowRight = L'C',
ArrowLeft = L'D',
Home = L'H',
End = L'F',
Generic = L'~', // Used for a whole bunch of possible keys
CSI_F1 = L'P',
CSI_F2 = L'Q',
CSI_F3 = L'R', // Both F3 and DSR are on R.
// DSR_DeviceStatusReportResponse = L'R',
CSI_F4 = L'S',
DTTERM_WindowManipulation = L't',
CursorBackTab = L'Z',
};
DWORD _GetCursorKeysModifierState(const std::basic_string_view<size_t> parameters);
DWORD _GetGenericKeysModifierState(const std::basic_string_view<size_t> parameters);
bool _GenerateKeyFromChar(const wchar_t wch, short& vkey, DWORD& modifierState);
enum Ss3ActionCodes : wchar_t
{
// The "Cursor Keys" are sometimes sent as a SS3 in "application mode"
// But for now we'll only accept them as Normal Mode sequences, as CSI's.
// ArrowUp = L'A',
// ArrowDown = L'B',
// ArrowRight = L'C',
// ArrowLeft = L'D',
// Home = L'H',
// End = L'F',
SS3_F1 = L'P',
SS3_F2 = L'Q',
SS3_F3 = L'R',
SS3_F4 = L'S',
};
bool _IsModified(const size_t paramCount);
DWORD _GetModifier(const size_t parameter);
// Sequences ending in '~' use these numbers as identifiers.
enum GenericKeyIdentifiers : unsigned short
{
GenericHome = 1,
Insert = 2,
Delete = 3,
GenericEnd = 4,
Prior = 5, //PgUp
Next = 6, //PgDn
F5 = 15,
F6 = 17,
F7 = 18,
F8 = 19,
F9 = 20,
F10 = 21,
F11 = 23,
F12 = 24,
};
bool _GetGenericVkey(const std::basic_string_view<size_t> parameters,
short& vkey) const;
bool _GetCursorKeysVkey(const wchar_t wch, short& vkey) const;
bool _GetSs3KeysVkey(const wchar_t wch, short& vkey) const;
struct CSI_TO_VKEY
{
CsiActionCodes Action;
short vkey;
};
bool _WriteSingleKey(const short vkey, const DWORD modifierState);
bool _WriteSingleKey(const wchar_t wch, const short vkey, const DWORD modifierState);
struct GENERIC_TO_VKEY
{
GenericKeyIdentifiers Identifier;
short vkey;
};
void _GenerateWrappedSequence(const wchar_t wch,
const short vkey,
const DWORD modifierState,
std::vector<INPUT_RECORD>& input);
struct SS3_TO_VKEY
{
Ss3ActionCodes Action;
short vkey;
};
void _GetSingleKeypress(const wchar_t wch,
const short vkey,
const DWORD modifierState,
std::vector<INPUT_RECORD>& input);
static const CSI_TO_VKEY s_rgCsiMap[];
static const GENERIC_TO_VKEY s_rgGenericMap[];
static const SS3_TO_VKEY s_rgSs3Map[];
bool _GetWindowManipulationType(const std::basic_string_view<size_t> parameters,
unsigned int& function) const;
DWORD _GetCursorKeysModifierState(_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams);
DWORD _GetGenericKeysModifierState(_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams);
bool _GenerateKeyFromChar(const wchar_t wch, _Out_ short* const pVkey, _Out_ DWORD* const pdwModifierState);
bool _IsModified(const unsigned short cParams);
DWORD _GetModifier(const unsigned short modifierParam);
bool _GetGenericVkey(_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams,
_Out_ short* const pVkey) const;
bool _GetCursorKeysVkey(const wchar_t wch, _Out_ short* const pVkey) const;
bool _GetSs3KeysVkey(const wchar_t wch, _Out_ short* const pVkey) const;
bool _WriteSingleKey(const short vkey, const DWORD dwModifierState);
bool _WriteSingleKey(const wchar_t wch, const short vkey, const DWORD dwModifierState);
size_t _GenerateWrappedSequence(const wchar_t wch,
const short vkey,
const DWORD dwModifierState,
_Inout_updates_(cInput) INPUT_RECORD* rgInput,
const size_t cInput);
size_t _GetSingleKeypress(const wchar_t wch,
const short vkey,
const DWORD dwModifierState,
_Inout_updates_(cRecords) INPUT_RECORD* const rgInput,
const size_t cRecords);
bool _GetWindowManipulationType(_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams,
_Out_ unsigned int* const puiFunction) const;
static const unsigned int s_uiDefaultLine = 1;
static const unsigned int s_uiDefaultColumn = 1;
bool _GetXYPosition(_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams,
_Out_ unsigned int* const puiLine,
_Out_ unsigned int* const puiColumn) const;
static constexpr size_t DefaultLine = 1;
static constexpr size_t DefaultColumn = 1;
bool _GetXYPosition(const std::basic_string_view<size_t> parameters,
size_t& line,
size_t& column) const;
bool _DoControlCharacter(const wchar_t wch, const bool writeAlt);
};

File diff suppressed because it is too large Load diff

View file

@ -22,7 +22,7 @@ namespace Microsoft::Console::VirtualTerminal
class OutputStateMachineEngine : public IStateMachineEngine
{
public:
OutputStateMachineEngine(ITermDispatch* const pDispatch);
OutputStateMachineEngine(std::unique_ptr<ITermDispatch> pDispatch);
~OutputStateMachineEngine();
bool ActionExecute(const wchar_t wch) override;
@ -30,33 +30,27 @@ namespace Microsoft::Console::VirtualTerminal
bool ActionPrint(const wchar_t wch) override;
bool ActionPrintString(const wchar_t* const rgwch, const size_t cch) override;
bool ActionPrintString(const std::wstring_view string) override;
bool ActionPassThroughString(const wchar_t* const rgwch,
size_t const cch) override;
bool ActionPassThroughString(const std::wstring_view string) override;
bool ActionEscDispatch(const wchar_t wch,
const unsigned short cIntermediate,
const wchar_t wchIntermediate) override;
const std::basic_string_view<wchar_t> intermediates) override;
bool ActionCsiDispatch(const wchar_t wch,
const unsigned short cIntermediate,
const wchar_t wchIntermediate,
_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams);
const std::basic_string_view<wchar_t> intermediates,
const std::basic_string_view<size_t> parameters) override;
bool ActionClear() override;
bool ActionIgnore() override;
bool ActionOscDispatch(const wchar_t wch,
const unsigned short sOscParam,
_Inout_updates_(cchOscString) wchar_t* const pwchOscStringBuffer,
const unsigned short cchOscString) override;
const size_t parameter,
const std::wstring_view string) override;
bool ActionSs3Dispatch(const wchar_t wch,
_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams) override;
const std::basic_string_view<size_t> parameters) override;
bool FlushAtEndOfString() const override;
bool DispatchControlCharsFromEscape() const override;
@ -75,12 +69,10 @@ namespace Microsoft::Console::VirtualTerminal
wchar_t _lastPrintedChar;
bool _IntermediateQuestionMarkDispatch(const wchar_t wchAction,
_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams);
const std::basic_string_view<size_t> parameters);
bool _IntermediateExclamationDispatch(const wchar_t wch);
bool _IntermediateSpaceDispatch(const wchar_t wchAction,
_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams);
const std::basic_string_view<size_t> parameters);
enum VTActionCodes : wchar_t
{
@ -154,110 +146,88 @@ namespace Microsoft::Console::VirtualTerminal
G3
};
static const DispatchTypes::GraphicsOptions s_defaultGraphicsOption = DispatchTypes::GraphicsOptions::Off;
_Success_(return ) bool _GetGraphicsOptions(_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams,
_Out_writes_(*pcOptions) DispatchTypes::GraphicsOptions* const rgGraphicsOptions,
_Inout_ size_t* const pcOptions) const;
static constexpr DispatchTypes::GraphicsOptions DefaultGraphicsOption = DispatchTypes::GraphicsOptions::Off;
bool _GetGraphicsOptions(const std::basic_string_view<size_t> parameters,
std::vector<DispatchTypes::GraphicsOptions>& options) const;
static const DispatchTypes::EraseType s_defaultEraseType = DispatchTypes::EraseType::ToEnd;
_Success_(return ) bool _GetEraseOperation(_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams,
_Out_ DispatchTypes::EraseType* const pEraseType) const;
static constexpr DispatchTypes::EraseType DefaultEraseType = DispatchTypes::EraseType::ToEnd;
bool _GetEraseOperation(const std::basic_string_view<size_t> parameters,
DispatchTypes::EraseType& eraseType) const;
static const unsigned int s_uiDefaultCursorDistance = 1;
_Success_(return ) bool _GetCursorDistance(_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams,
_Out_ unsigned int* const puiDistance) const;
static constexpr size_t DefaultCursorDistance = 1;
bool _GetCursorDistance(const std::basic_string_view<size_t> parameters,
size_t& distance) const;
static const unsigned int s_uiDefaultScrollDistance = 1;
_Success_(return ) bool _GetScrollDistance(_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams,
_Out_ unsigned int* const puiDistance) const;
static constexpr size_t DefaultScrollDistance = 1;
bool _GetScrollDistance(const std::basic_string_view<size_t> parameters,
size_t& distance) const;
static const unsigned int s_uiDefaultConsoleWidth = 80;
_Success_(return ) bool _GetConsoleWidth(_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams,
_Out_ unsigned int* const puiConsoleWidth) const;
static constexpr size_t DefaultConsoleWidth = 80;
bool _GetConsoleWidth(const std::basic_string_view<size_t> parameters,
size_t& consoleWidth) const;
static const unsigned int s_uiDefaultLine = 1;
static const unsigned int s_uiDefaultColumn = 1;
_Success_(return ) bool _GetXYPosition(_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams,
_Out_ unsigned int* const puiLine,
_Out_ unsigned int* const puiColumn) const;
static constexpr size_t DefaultLine = 1;
static constexpr size_t DefaultColumn = 1;
bool _GetXYPosition(const std::basic_string_view<size_t> parameters,
size_t& line,
size_t& column) const;
_Success_(return ) bool _GetDeviceStatusOperation(_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams,
_Out_ DispatchTypes::AnsiStatusType* const pStatusType) const;
bool _GetDeviceStatusOperation(const std::basic_string_view<size_t> parameters,
DispatchTypes::AnsiStatusType& statusType) const;
_Success_(return ) bool _VerifyHasNoParameters(const unsigned short cParams) const;
bool _VerifyHasNoParameters(const std::basic_string_view<size_t> parameters) const;
_Success_(return ) bool _VerifyDeviceAttributesParams(_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams) const;
bool _VerifyDeviceAttributesParams(const std::basic_string_view<size_t> parameters) const;
_Success_(return ) bool _GetPrivateModeParams(_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams,
_Out_writes_(*pcParams) DispatchTypes::PrivateModeParams* const rgPrivateModeParams,
_Inout_ size_t* const pcParams) const;
bool _GetPrivateModeParams(const std::basic_string_view<size_t> parameters,
std::vector<DispatchTypes::PrivateModeParams>& privateModes) const;
static const SHORT s_sDefaultTopMargin = 0;
static const SHORT s_sDefaultBottomMargin = 0;
_Success_(return ) bool _GetTopBottomMargins(_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams,
_Out_ SHORT* const psTopMargin,
_Out_ SHORT* const psBottomMargin) const;
static constexpr size_t DefaultTopMargin = 0;
static constexpr size_t DefaultBottomMargin = 0;
bool _GetTopBottomMargins(const std::basic_string_view<size_t> parameters,
size_t& topMargin,
size_t& bottomMargin) const;
_Success_(return ) bool _GetOscTitle(_Inout_updates_(cchOscString) wchar_t* const pwchOscStringBuffer,
const unsigned short cchOscString,
_Outptr_result_buffer_(*pcchTitle) wchar_t** const ppwchTitle,
_Out_ unsigned short* pcchTitle) const;
bool _GetOscTitle(const std::wstring_view string,
std::wstring& title) const;
static const SHORT s_sDefaultTabDistance = 1;
_Success_(return ) bool _GetTabDistance(_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams,
_Out_ SHORT* const psDistance) const;
static constexpr size_t DefaultTabDistance = 1;
bool _GetTabDistance(const std::basic_string_view<size_t> parameters,
size_t& distance) const;
static const SHORT s_sDefaultTabClearType = 0;
_Success_(return ) bool _GetTabClearType(_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams,
_Out_ SHORT* const psClearType) const;
static constexpr size_t DefaultTabClearType = 0;
bool _GetTabClearType(const std::basic_string_view<size_t> parameters,
size_t& clearType) const;
static const DesignateCharsetTypes s_DefaultDesignateCharsetType = DesignateCharsetTypes::G0;
_Success_(return ) bool _GetDesignateType(const wchar_t wchIntermediate,
_Out_ DesignateCharsetTypes* const pDesignateType) const;
static constexpr DesignateCharsetTypes DefaultDesignateCharsetType = DesignateCharsetTypes::G0;
bool _GetDesignateType(const wchar_t intermediate,
DesignateCharsetTypes& designateType) const;
static const DispatchTypes::WindowManipulationType s_DefaultWindowManipulationType = DispatchTypes::WindowManipulationType::Invalid;
_Success_(return ) bool _GetWindowManipulationType(_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams,
_Out_ unsigned int* const puiFunction) const;
static constexpr DispatchTypes::WindowManipulationType DefaultWindowManipulationType = DispatchTypes::WindowManipulationType::Invalid;
bool _GetWindowManipulationType(const std::basic_string_view<size_t> parameters,
unsigned int& function) const;
static bool s_HexToUint(const wchar_t wch,
_Out_ unsigned int* const puiValue);
unsigned int& value);
static bool s_IsNumber(const wchar_t wch);
static bool s_IsHexNumber(const wchar_t wch);
bool _GetOscSetColorTable(_In_reads_(cchOscString) const wchar_t* const pwchOscStringBuffer,
const size_t cchOscString,
_Out_ size_t* const pTableIndex,
_Out_ DWORD* const pRgb) const;
bool _GetOscSetColorTable(const std::wstring_view string,
size_t& tableIndex,
DWORD& rgb) const;
static bool s_ParseColorSpec(_In_reads_(cchBuffer) const wchar_t* const pwchBuffer,
const size_t cchBuffer,
_Out_ DWORD* const pRgb);
static bool s_ParseColorSpec(const std::wstring_view string,
DWORD& rgb);
bool _GetOscSetColor(_In_reads_(cchOscString) const wchar_t* const pwchOscStringBuffer,
const size_t cchOscString,
_Out_ DWORD* const pRgb) const;
bool _GetOscSetColor(const std::wstring_view string,
DWORD& rgb) const;
static const DispatchTypes::CursorStyle s_defaultCursorStyle = DispatchTypes::CursorStyle::BlinkingBlockDefault;
_Success_(return ) bool _GetCursorStyle(_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams,
_Out_ DispatchTypes::CursorStyle* const pCursorStyle) const;
static constexpr DispatchTypes::CursorStyle DefaultCursorStyle = DispatchTypes::CursorStyle::BlinkingBlockDefault;
bool _GetCursorStyle(const std::basic_string_view<size_t> parameters,
DispatchTypes::CursorStyle& cursorStyle) const;
static const unsigned int s_uiDefaultRepeatCount = 1;
_Success_(return ) bool _GetRepeatCount(_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams,
_Out_ unsigned int* const puiRepeatCount) const noexcept;
static constexpr size_t DefaultRepeatCount = 1;
bool _GetRepeatCount(const std::basic_string_view<size_t> parameters,
size_t& repeatCount) const noexcept;
void _ClearLastChar() noexcept;
};

View file

@ -12,9 +12,10 @@ void EchoDispatch::Print(const wchar_t wchPrintable)
wprintf(L"Print: %c (0x%x)\r\n", wchPrintable, wchPrintable);
}
void EchoDispatch::PrintString(const wchar_t* const rgwch, const size_t cch)
void EchoDispatch::PrintString(const std::wstring_view string)
{
wprintf(L"PrintString: \"%s\" (%zd chars)\r\n", rgwch, cch);
const std::wstring nullTermString(string); // string_view not guaranteed null terminated, but wprintf needs it.
wprintf(L"PrintString: \"%s\" (%zd chars)\r\n", nullTermString.data(), nullTermString.size());
}
void EchoDispatch::Execute(const wchar_t wchControl)

View file

@ -13,7 +13,7 @@ namespace Microsoft
{
public:
void Print(const wchar_t wchPrintable) override;
void PrintString(const wchar_t* const rgwch, const size_t cch) override;
void PrintString(const std::wstring_view string) override;
void Execute(const wchar_t wchControl) override;
};
}

View file

@ -60,8 +60,10 @@ int __cdecl wmain(int argc, wchar_t* argv[])
hFile = _wfopen(argv[1], L"r");
wchar_t wch;
bool fGotChar = GetChar(&wch);
auto dispatch = std::make_unique<EchoDispatch>();
auto engine = std::make_unique<OutputStateMachineEngine>(std::move(dispatch));
StateMachine machine(new OutputStateMachineEngine(new EchoDispatch));
StateMachine machine(std::move(engine));
wprintf(L"Sending characters to state machine...\r\n");
while (fGotChar)

View file

@ -10,37 +10,26 @@
using namespace Microsoft::Console::VirtualTerminal;
//Takes ownership of the pEngine.
StateMachine::StateMachine(IStateMachineEngine* const pEngine) :
_pEngine(THROW_IF_NULL_ALLOC(pEngine)),
StateMachine::StateMachine(std::unique_ptr<IStateMachineEngine> engine) :
_engine(std::move(engine)),
_state(VTStates::Ground),
_trace(Microsoft::Console::VirtualTerminal::ParserTracing()),
_cParams(0),
_pusActiveParam(nullptr),
_cIntermediate(0),
_wchIntermediate(UNICODE_NULL),
_pwchCurr(nullptr),
_iParamAccumulatePos(0),
// pwchOscStringBuffer Initialized below
_pwchSequenceStart(nullptr),
// rgusParams Initialized below
_sOscNextChar(0),
_sOscParam(0),
_currRunLength(0),
_fProcessingIndividually(false)
_intermediates{},
_parameters{},
_oscString{},
_processingIndividually(false)
{
ZeroMemory(_pwchOscStringBuffer, sizeof(_pwchOscStringBuffer));
ZeroMemory(_rgusParams, sizeof(_rgusParams));
_ActionClear();
}
const IStateMachineEngine& StateMachine::Engine() const noexcept
{
return *_pEngine;
return *_engine;
}
IStateMachineEngine& StateMachine::Engine() noexcept
{
return *_pEngine;
return *_engine;
}
// Routine Description:
@ -299,7 +288,7 @@ bool StateMachine::s_IsNumber(const wchar_t wch)
void StateMachine::_ActionExecute(const wchar_t wch)
{
_trace.TraceOnExecute(wch);
_pEngine->ActionExecute(wch);
_engine->ActionExecute(wch);
}
// Routine Description:
@ -313,7 +302,7 @@ void StateMachine::_ActionExecute(const wchar_t wch)
void StateMachine::_ActionExecuteFromEscape(const wchar_t wch)
{
_trace.TraceOnExecuteFromEscape(wch);
_pEngine->ActionExecuteFromEscape(wch);
_engine->ActionExecuteFromEscape(wch);
}
// Routine Description:
@ -325,7 +314,7 @@ void StateMachine::_ActionExecuteFromEscape(const wchar_t wch)
void StateMachine::_ActionPrint(const wchar_t wch)
{
_trace.TraceOnAction(L"Print");
_pEngine->ActionPrint(wch);
_engine->ActionPrint(wch);
}
// Routine Description:
@ -339,12 +328,12 @@ void StateMachine::_ActionEscDispatch(const wchar_t wch)
{
_trace.TraceOnAction(L"EscDispatch");
bool fSuccess = _pEngine->ActionEscDispatch(wch, _cIntermediate, _wchIntermediate);
bool success = _engine->ActionEscDispatch(wch, { _intermediates.data(), _intermediates.size() });
// Trace the result.
_trace.DispatchSequenceTrace(fSuccess);
_trace.DispatchSequenceTrace(success);
if (!fSuccess)
if (!success)
{
// Suppress it and log telemetry on failed cases
TermTelemetry::Instance().LogFailed(wch);
@ -362,12 +351,14 @@ void StateMachine::_ActionCsiDispatch(const wchar_t wch)
{
_trace.TraceOnAction(L"CsiDispatch");
bool fSuccess = _pEngine->ActionCsiDispatch(wch, _cIntermediate, _wchIntermediate, _rgusParams, _cParams);
bool success = _engine->ActionCsiDispatch(wch,
{ _intermediates.data(), _intermediates.size() },
{ _parameters.data(), _parameters.size() });
// Trace the result.
_trace.DispatchSequenceTrace(fSuccess);
_trace.DispatchSequenceTrace(success);
if (!fSuccess)
if (!success)
{
// Suppress it and log telemetry on failed cases
TermTelemetry::Instance().LogFailed(wch);
@ -385,12 +376,7 @@ void StateMachine::_ActionCollect(const wchar_t wch)
_trace.TraceOnAction(L"Collect");
// store collect data
if (_cIntermediate < s_cIntermediateMax)
{
_wchIntermediate = wch;
}
_cIntermediate++;
_intermediates.push_back(wch);
}
// Routine Description:
@ -404,70 +390,24 @@ void StateMachine::_ActionParam(const wchar_t wch)
{
_trace.TraceOnAction(L"Param");
// Verify both the count and that the pointer didn't run off the end of the
// array. If we're past the end, this param is just ignored.
if (_cParams <= s_cParamsMax && _pusActiveParam < &_rgusParams[s_cParamsMax])
// If we have no parameters and we're about to add one, get the 0 value ready here.
if (_parameters.empty())
{
// If we're adding a character to the first parameter,
// then we now have one parameter.
if (_iParamAccumulatePos == 0 && _cParams == 0)
{
_cParams++;
}
_parameters.push_back(0);
}
// On a delimiter, increase the number of params we've seen.
// "Empty" params should still count as a param -
// eg "\x1b[0;;m" should be three "0" params
if (wch == L';')
{
// Move to next param.
// If we're on the last param (_cParams == s_cParamsMax),
// then _pusActiveParam will now be past the end of _rgusParams,
// and any future params will be ignored.
_pusActiveParam++;
// clear out the accumulator count to prepare for the next one
_iParamAccumulatePos = 0;
// Don't increment the _cParams to be greater than s_cParamsMax.
// We're using _pusActiveParam to make sure we don't fill too
// many params.
if (_cParams < s_cParamsMax)
{
_cParams++;
}
}
else
{
// don't bother accumulating if we're storing more than 4 digits (since we're putting it into a short)
if (_iParamAccumulatePos < 5)
{
// convert character into digit.
unsigned short const usDigit = wch - L'0'; // convert character into value
// multiply existing values by 10 to make space in the 1s digit
*_pusActiveParam *= 10;
// store the digit in the 1s place.
*_pusActiveParam += usDigit;
// if the total is zero, it must be a leading zero digit, so we don't count it.
if (*_pusActiveParam != 0)
{
// otherwise mark that we've now stored another digit.
_iParamAccumulatePos++;
}
if (*_pusActiveParam > SHORT_MAX)
{
*_pusActiveParam = SHORT_MAX;
}
}
else
{
*_pusActiveParam = SHORT_MAX;
}
}
// On a delimiter, increase the number of params we've seen.
// "Empty" params should still count as a param -
// eg "\x1b[0;;m" should be three "0" params
if (wch == L';')
{
// Move to next param.
_parameters.push_back(0);
}
else
{
// Accumulate the character given into the last (current) parameter
_AccumulateTo(wch, _parameters.back());
}
}
@ -482,22 +422,14 @@ void StateMachine::_ActionClear()
_trace.TraceOnAction(L"Clear");
// clear all internal stored state.
_wchIntermediate = 0;
_cIntermediate = 0;
_intermediates.clear();
for (unsigned short i = 0; i < s_cParamsMax; i++)
{
_rgusParams[i] = 0;
}
_parameters.clear();
_cParams = 0;
_iParamAccumulatePos = 0;
_pusActiveParam = _rgusParams; // set pointer back to beginning of array
_oscString.clear();
_oscParameter = 0;
_sOscParam = 0;
_sOscNextChar = 0;
_pEngine->ActionClear();
_engine->ActionClear();
}
// Routine Description:
@ -522,34 +454,7 @@ void StateMachine::_ActionOscParam(const wchar_t wch)
{
_trace.TraceOnAction(L"OscParamCollect");
// don't bother accumulating if we're storing more than 4 digits (since we're putting it into a short)
if (_iParamAccumulatePos < 5)
{
// convert character into digit.
unsigned short const usDigit = wch - L'0'; // convert character into value
// multiply existing values by 10 to make space in the 1s digit
_sOscParam *= 10;
// store the digit in the 1s place.
_sOscParam += usDigit;
// if the total is zero, it must be a leading zero digit, so we don't count it.
if (_sOscParam != 0)
{
// otherwise mark that we've now stored another digit.
_iParamAccumulatePos++;
}
if (_sOscParam > SHORT_MAX)
{
_sOscParam = SHORT_MAX;
}
}
else
{
_sOscParam = SHORT_MAX;
}
_AccumulateTo(wch, _oscParameter);
}
// Routine Description:
@ -562,14 +467,7 @@ void StateMachine::_ActionOscPut(const wchar_t wch)
{
_trace.TraceOnAction(L"OscPut");
// if we're past the end, this param is just ignored.
// need to leave one char for \0 at end
if (_sOscNextChar < s_cOscStringMaxLength - 1)
{
_pwchOscStringBuffer[_sOscNextChar] = wch;
_sOscNextChar++;
//we'll place the null at the end of the string when we send the actual action.
}
_oscString.push_back(wch);
}
// Routine Description:
@ -583,12 +481,12 @@ void StateMachine::_ActionOscDispatch(const wchar_t wch)
{
_trace.TraceOnAction(L"OscDispatch");
bool fSuccess = _pEngine->ActionOscDispatch(wch, _sOscParam, _pwchOscStringBuffer, _sOscNextChar);
bool success = _engine->ActionOscDispatch(wch, _oscParameter, _oscString);
// Trace the result.
_trace.DispatchSequenceTrace(fSuccess);
_trace.DispatchSequenceTrace(success);
if (!fSuccess)
if (!success)
{
// Suppress it and log telemetry on failed cases
TermTelemetry::Instance().LogFailed(wch);
@ -606,12 +504,12 @@ void StateMachine::_ActionSs3Dispatch(const wchar_t wch)
{
_trace.TraceOnAction(L"Ss3Dispatch");
bool fSuccess = _pEngine->ActionSs3Dispatch(wch, _rgusParams, _cParams);
bool success = _engine->ActionSs3Dispatch(wch, { _parameters.data(), _parameters.size() });
// Trace the result.
_trace.DispatchSequenceTrace(fSuccess);
_trace.DispatchSequenceTrace(success);
if (!fSuccess)
if (!success)
{
// Suppress it and log telemetry on failed cases
TermTelemetry::Instance().LogFailed(wch);
@ -838,7 +736,7 @@ void StateMachine::_EventEscape(const wchar_t wch)
_trace.TraceOnEvent(L"Escape");
if (s_IsC0Code(wch))
{
if (_pEngine->DispatchControlCharsFromEscape())
if (_engine->DispatchControlCharsFromEscape())
{
_ActionExecuteFromEscape(wch);
_EnterGround();
@ -854,7 +752,7 @@ void StateMachine::_EventEscape(const wchar_t wch)
}
else if (s_IsIntermediate(wch))
{
if (_pEngine->DispatchIntermediatesFromEscape())
if (_engine->DispatchIntermediatesFromEscape())
{
_ActionEscDispatch(wch);
_EnterGround();
@ -1327,8 +1225,7 @@ bool StateMachine::FlushToTerminal()
// that pwchCurr was processed.
// However, if we're here, then the processing of pwchChar triggered the
// engine to request the entire sequence get passed through, including pwchCurr.
return _pEngine->ActionPassThroughString(_pwchSequenceStart,
_pwchCurr - _pwchSequenceStart + 1);
return _engine->ActionPassThroughString(_run);
}
// Routine Description:
@ -1337,64 +1234,56 @@ bool StateMachine::FlushToTerminal()
// a escape sequence, then feed characters into the state machine one at a
// time until we return to the ground state.
// Arguments:
// - rgwch - Array of new characters to operate upon
// - cch - Count of characters in array
// - string - Characters to operate upon
// Return Value:
// - <none>
void StateMachine::ProcessString(const wchar_t* const rgwch, const size_t cch)
void StateMachine::ProcessString(const std::wstring_view string)
{
_pwchCurr = rgwch;
_pwchSequenceStart = rgwch;
_currRunLength = 0;
size_t start = 0;
size_t current = start;
for (size_t cchCharsRemaining = cch; cchCharsRemaining > 0; cchCharsRemaining--)
while (current < string.size())
{
if (_fProcessingIndividually)
_run = string.substr(start, current - start);
if (_processingIndividually)
{
// If we're processing characters individually, send it to the state machine.
ProcessCharacter(*_pwchCurr);
_pwchCurr++;
ProcessCharacter(string.at(current));
++current;
if (_state == VTStates::Ground) // Then check if we're back at ground. If we are, the next character (pwchCurr)
{ // is the start of the next run of characters that might be printable.
_fProcessingIndividually = false;
_pwchSequenceStart = _pwchCurr;
_currRunLength = 0;
_processingIndividually = false;
start = current;
}
}
else
{
if (s_IsActionableFromGround(*_pwchCurr)) // If the current char is the start of an escape sequence, or should be executed in ground state...
if (s_IsActionableFromGround(string.at(current))) // If the current char is the start of an escape sequence, or should be executed in ground state...
{
FAIL_FAST_IF(!(_pwchSequenceStart + _currRunLength <= rgwch + cch));
_pEngine->ActionPrintString(_pwchSequenceStart, _currRunLength); // ... print all the chars leading up to it as part of the run...
_trace.DispatchPrintRunTrace(_pwchSequenceStart, _currRunLength);
_fProcessingIndividually = true; // begin processing future characters individually...
_currRunLength = 0;
_pwchSequenceStart = _pwchCurr;
ProcessCharacter(*_pwchCurr); // ... Then process the character individually.
if (_state == VTStates::Ground) // If the character took us right back to ground, start another run after it.
{
_fProcessingIndividually = false;
_pwchSequenceStart = _pwchCurr + 1;
_currRunLength = 0;
}
_engine->ActionPrintString(_run); // ... print all the chars leading up to it as part of the run...
_trace.DispatchPrintRunTrace(_run);
_processingIndividually = true; // begin processing future characters individually...
start = current;
continue;
}
else
{
_currRunLength++; // Otherwise, add this char to the current run to be printed.
++current; // Otherwise, add this char to the current run to be printed.
}
_pwchCurr++;
}
}
_run = string.substr(start, current - start);
// If we're at the end of the string and have remaining un-printed characters,
if (!_fProcessingIndividually && _currRunLength > 0)
if (!_processingIndividually && !_run.empty())
{
// print the rest of the characters in the string
_pEngine->ActionPrintString(_pwchSequenceStart, _currRunLength);
_trace.DispatchPrintRunTrace(_pwchSequenceStart, _currRunLength);
_engine->ActionPrintString(_run);
_trace.DispatchPrintRunTrace(_run);
}
else if (_fProcessingIndividually)
else if (_processingIndividually)
{
// One of the "weird things" in VT input is the case of something like
// <kbd>alt+[</kbd>. In VT, that's encoded as `\x1b[`. However, that's
@ -1415,40 +1304,41 @@ void StateMachine::ProcessString(const wchar_t* const rgwch, const size_t cch)
// means we'll make sure to call `_ActionEscDispatch('[')`., which will
// properly decode the string as <kbd>alt+[</kbd>.
if (_pEngine->FlushAtEndOfString())
if (_engine->FlushAtEndOfString())
{
// Reset our state, and put all but the last char in again.
ResetState();
// Chars to flush are [pwchSequenceStart, pwchCurr)
const wchar_t* pwch = _pwchSequenceStart;
for (; pwch < _pwchCurr - 1; pwch++)
auto wchIter = _run.cbegin();
while (wchIter < _run.cend() - 1)
{
ProcessCharacter(*pwch);
ProcessCharacter(*wchIter);
wchIter++;
}
// Manually execute the last char [pwchCurr]
switch (_state)
{
case VTStates::Ground:
_ActionExecute(*pwch);
_ActionExecute(*wchIter);
break;
case VTStates::Escape:
case VTStates::EscapeIntermediate:
_ActionEscDispatch(*pwch);
_ActionEscDispatch(*wchIter);
break;
case VTStates::CsiEntry:
case VTStates::CsiIntermediate:
case VTStates::CsiIgnore:
case VTStates::CsiParam:
_ActionCsiDispatch(*pwch);
_ActionCsiDispatch(*wchIter);
break;
case VTStates::OscParam:
case VTStates::OscString:
case VTStates::OscTermination:
_ActionOscDispatch(*pwch);
_ActionOscDispatch(*wchIter);
break;
case VTStates::Ss3Entry:
case VTStates::Ss3Param:
_ActionSs3Dispatch(*pwch);
_ActionSs3Dispatch(*wchIter);
break;
}
// microsoft/terminal#2746: Make sure to return to the ground state
@ -1458,11 +1348,6 @@ void StateMachine::ProcessString(const wchar_t* const rgwch, const size_t cch)
}
}
void StateMachine::ProcessString(const std::wstring& wstr)
{
return ProcessString(wstr.c_str(), wstr.length());
}
// Routine Description:
// - Wherever the state machine is, whatever it's going, go back to ground.
// This is used by conhost to "jiggle the handle" - when VT support is
@ -1475,3 +1360,26 @@ void StateMachine::ResetState()
{
_EnterGround();
}
// Routine Description:
// - Takes the given printable character and accumulates it as the new ones digit
// into the given size_t. All existing value is moved up by 10.
// - For example, if your value had 437 and you put in the printable number 2,
// this function will update value to 4372.
// - Clamps to size_t max if it gets too big.
// Arguments:
// - wch - Printable character to accumulate into the value (after conversion to number, of course)
// - value - The value to update with the printable character. See example above.
// Return Value:
// - <none> - But really it's the update to the given value parameter.
void StateMachine::_AccumulateTo(const wchar_t wch, size_t& value)
{
const size_t digit = wch - L'0';
// If we overflow while multiplying and adding, the value is just size_t max.
if (FAILED(SizeTMult(value, 10, &value)) ||
FAILED(SizeTAdd(value, digit, &value)))
{
value = std::numeric_limits<size_t>().max();
}
}

View file

@ -29,11 +29,10 @@ namespace Microsoft::Console::VirtualTerminal
#endif
public:
StateMachine(IStateMachineEngine* const pEngine);
StateMachine(std::unique_ptr<IStateMachineEngine> engine);
void ProcessCharacter(const wchar_t wch);
void ProcessString(const wchar_t* const rgwch, const size_t cch);
void ProcessString(const std::wstring& wstr);
void ProcessString(const std::wstring_view string);
void ResetState();
@ -42,10 +41,6 @@ namespace Microsoft::Console::VirtualTerminal
const IStateMachineEngine& Engine() const noexcept;
IStateMachineEngine& Engine() noexcept;
static const short s_cIntermediateMax = 1;
static const short s_cParamsMax = 16;
static const short s_cOscStringMaxLength = 256;
private:
static bool s_IsActionableFromGround(const wchar_t wch);
static bool s_IsC0Code(const wchar_t wch);
@ -64,8 +59,6 @@ namespace Microsoft::Console::VirtualTerminal
static bool s_IsOscInvalid(const wchar_t wch);
static bool s_IsOscTerminator(const wchar_t wch);
static bool s_IsOscTerminationInitiator(const wchar_t wch);
static bool s_IsDesignateCharsetIndicator(const wchar_t wch);
static bool s_IsCharsetCode(const wchar_t wch);
static bool s_IsNumber(const wchar_t wch);
static bool s_IsSs3Indicator(const wchar_t wch);
@ -110,6 +103,8 @@ namespace Microsoft::Console::VirtualTerminal
void _EventSs3Entry(const wchar_t wch);
void _EventSs3Param(const wchar_t wch);
void _AccumulateTo(const wchar_t wch, size_t& value);
enum class VTStates
{
Ground,
@ -128,31 +123,20 @@ namespace Microsoft::Console::VirtualTerminal
Microsoft::Console::VirtualTerminal::ParserTracing _trace;
std::unique_ptr<IStateMachineEngine> _pEngine;
std::unique_ptr<IStateMachineEngine> _engine;
VTStates _state;
wchar_t _wchIntermediate;
unsigned short _cIntermediate;
std::wstring_view _run;
unsigned short _rgusParams[s_cParamsMax];
unsigned short _cParams;
unsigned short* _pusActiveParam;
unsigned short _iParamAccumulatePos;
std::vector<wchar_t> _intermediates;
std::vector<size_t> _parameters;
unsigned short _sOscParam;
unsigned short _sOscNextChar;
wchar_t _pwchOscStringBuffer[s_cOscStringMaxLength];
// These members track out state in the parsing of a single string.
// FlushToTerminal uses these, so that an engine can force a string
// we're parsing to go straight through to the engine's ActionPassThroughString
const wchar_t* _pwchCurr;
const wchar_t* _pwchSequenceStart;
size_t _currRunLength;
std::wstring _oscString;
size_t _oscParameter;
// This is tracked per state machine instance so that separate calls to Process*
// can start and finish a sequence.
bool _fProcessingIndividually;
bool _processingIndividually;
};
}

View file

@ -15,19 +15,19 @@ ParserTracing::~ParserTracing()
{
}
void ParserTracing::TraceStateChange(_In_ PCWSTR const pwszName) const
void ParserTracing::TraceStateChange(const std::wstring_view name) const
{
TraceLoggingWrite(g_hConsoleVirtTermParserEventTraceProvider,
"StateMachine_EnterState",
TraceLoggingWideString(pwszName),
TraceLoggingCountedWideString(name.data(), gsl::narrow_cast<ULONG>(name.size())),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
}
void ParserTracing::TraceOnAction(_In_ PCWSTR const pwszName) const
void ParserTracing::TraceOnAction(const std::wstring_view name) const
{
TraceLoggingWrite(g_hConsoleVirtTermParserEventTraceProvider,
"StateMachine_Action",
TraceLoggingWideString(pwszName),
TraceLoggingCountedWideString(name.data(), gsl::narrow_cast<ULONG>(name.size())),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
}
@ -51,11 +51,11 @@ void ParserTracing::TraceOnExecuteFromEscape(const wchar_t wch) const
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
}
void ParserTracing::TraceOnEvent(_In_ PCWSTR const pwszName) const
void ParserTracing::TraceOnEvent(const std::wstring_view name) const
{
TraceLoggingWrite(g_hConsoleVirtTermParserEventTraceProvider,
"StateMachine_Event",
TraceLoggingWideString(pwszName),
TraceLoggingCountedWideString(name.data(), gsl::narrow_cast<ULONG>(name.size())),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
}
@ -73,12 +73,7 @@ void ParserTracing::TraceCharInput(const wchar_t wch)
void ParserTracing::AddSequenceTrace(const wchar_t wch)
{
// -1 to always leave the last character as null/0.
if (_cchSequenceTrace < s_cMaxSequenceTrace - 1)
{
_rgwchSequenceTrace[_cchSequenceTrace] = wch;
_cchSequenceTrace++;
}
_sequenceTrace.push_back(wch);
}
void ParserTracing::DispatchSequenceTrace(const bool fSuccess)
@ -87,14 +82,14 @@ void ParserTracing::DispatchSequenceTrace(const bool fSuccess)
{
TraceLoggingWrite(g_hConsoleVirtTermParserEventTraceProvider,
"StateMachine_Sequence_OK",
TraceLoggingWideString(_rgwchSequenceTrace),
TraceLoggingWideString(_sequenceTrace.c_str()),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
}
else
{
TraceLoggingWrite(g_hConsoleVirtTermParserEventTraceProvider,
"StateMachine_Sequence_FAIL",
TraceLoggingWideString(_rgwchSequenceTrace),
TraceLoggingWideString(_sequenceTrace.c_str()),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
}
@ -103,19 +98,15 @@ void ParserTracing::DispatchSequenceTrace(const bool fSuccess)
void ParserTracing::ClearSequenceTrace()
{
ZeroMemory(_rgwchSequenceTrace, sizeof(_rgwchSequenceTrace));
_cchSequenceTrace = 0;
_sequenceTrace.clear();
}
// NOTE: I'm expecting this to not be null terminated
void ParserTracing::DispatchPrintRunTrace(const wchar_t* const pwsString, const size_t cchString) const
void ParserTracing::DispatchPrintRunTrace(const std::wstring_view string) const
{
size_t charsRemaining = cchString;
wchar_t str[BYTE_MAX + 4 + sizeof(wchar_t) + sizeof('\0')];
if (cchString == 1)
if (string.size() == 1)
{
wchar_t wch = *pwsString;
wchar_t wch = string.front();
INT16 sch = (INT16)wch;
TraceLoggingWrite(g_hConsoleVirtTermParserEventTraceProvider,
"StateMachine_PrintRun",
@ -125,27 +116,12 @@ void ParserTracing::DispatchPrintRunTrace(const wchar_t* const pwsString, const
}
else
{
while (charsRemaining > 0)
{
size_t strLen = 0;
if (charsRemaining > ARRAYSIZE(str) - 1)
{
strLen = ARRAYSIZE(str) - 1;
}
else
{
strLen = charsRemaining;
}
charsRemaining -= strLen;
const auto length = gsl::narrow_cast<ULONG>(string.size());
memcpy(str, pwsString, sizeof(wchar_t) * strLen);
str[strLen] = '\0';
TraceLoggingWrite(g_hConsoleVirtTermParserEventTraceProvider,
"StateMachine_PrintRun",
TraceLoggingWideString(str),
TraceLoggingValue(strLen),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
}
TraceLoggingWrite(g_hConsoleVirtTermParserEventTraceProvider,
"StateMachine_PrintRun",
TraceLoggingCountedWideString(string.data(), length),
TraceLoggingValue(length),
TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
}
}

View file

@ -24,22 +24,19 @@ namespace Microsoft::Console::VirtualTerminal
ParserTracing();
~ParserTracing();
void TraceStateChange(_In_ PCWSTR const pwszName) const;
void TraceOnAction(_In_ PCWSTR const pwszName) const;
void TraceStateChange(const std::wstring_view name) const;
void TraceOnAction(const std::wstring_view name) const;
void TraceOnExecute(const wchar_t wch) const;
void TraceOnExecuteFromEscape(const wchar_t wch) const;
void TraceOnEvent(_In_ PCWSTR const pwszName) const;
void TraceOnEvent(const std::wstring_view name) const;
void TraceCharInput(const wchar_t wch);
void AddSequenceTrace(const wchar_t wch);
void DispatchSequenceTrace(const bool fSuccess);
void ClearSequenceTrace();
void DispatchPrintRunTrace(const wchar_t* const pwsString, const size_t cchString) const;
void DispatchPrintRunTrace(const std::wstring_view string) const;
private:
static const size_t s_cMaxSequenceTrace = 32;
wchar_t _rgwchSequenceTrace[s_cMaxSequenceTrace];
size_t _cchSequenceTrace;
std::wstring _sequenceTrace;
};
}

View file

@ -94,7 +94,7 @@ public:
Log::Comment(
NoThrowString().Format(L"\tvtseq: \"%s\"(%zu)", vtseq.c_str(), vtseq.length()));
_stateMachine->ProcessString(&vtseq[0], vtseq.length());
_stateMachine->ProcessString(vtseq);
Log::Comment(L"String processed");
}
@ -242,14 +242,12 @@ public:
_In_ TestState* testState);
virtual bool WriteInput(_In_ std::deque<std::unique_ptr<IInputEvent>>& inputEvents) override;
virtual bool WriteCtrlC() override;
virtual bool WindowManipulation(const DispatchTypes::WindowManipulationType uiFunction,
_In_reads_(cParams) const unsigned short* const rgusParams,
const size_t cParams) override; // DTTERM_WindowManipulation
virtual bool WriteString(_In_reads_(cch) const wchar_t* const pws,
const size_t cch) override;
virtual bool WindowManipulation(const DispatchTypes::WindowManipulationType function,
const std::basic_string_view<size_t> parameters) override; // DTTERM_WindowManipulation
virtual bool WriteString(const std::wstring_view string) override;
virtual bool MoveCursor(const unsigned int row,
const unsigned int col) override;
virtual bool MoveCursor(const size_t row,
const size_t col) override;
private:
std::function<void(std::deque<std::unique_ptr<IInputEvent>>&)> _pfnWriteInputCallback;
@ -278,27 +276,26 @@ bool TestInteractDispatch::WriteCtrlC()
return WriteInput(inputEvents);
}
bool TestInteractDispatch::WindowManipulation(const DispatchTypes::WindowManipulationType uiFunction,
_In_reads_(cParams) const unsigned short* const rgusParams,
const size_t cParams)
bool TestInteractDispatch::WindowManipulation(const DispatchTypes::WindowManipulationType function,
const std::basic_string_view<size_t> parameters)
{
VERIFY_ARE_EQUAL(true, _testState->_expectedToCallWindowManipulation);
VERIFY_ARE_EQUAL(_testState->_expectedWindowManipulation, uiFunction);
for (size_t i = 0; i < cParams; i++)
VERIFY_ARE_EQUAL(_testState->_expectedWindowManipulation, function);
for (size_t i = 0; i < parameters.size(); i++)
{
VERIFY_ARE_EQUAL(_testState->_expectedParams[i], rgusParams[i]);
unsigned short actual;
VERIFY_SUCCEEDED(SizeTToUShort(parameters.at(i), &actual));
VERIFY_ARE_EQUAL(_testState->_expectedParams[i], actual);
}
return true;
}
bool TestInteractDispatch::WriteString(_In_reads_(cch) const wchar_t* const pws,
const size_t cch)
bool TestInteractDispatch::WriteString(const std::wstring_view string)
{
std::deque<std::unique_ptr<IInputEvent>> keyEvents;
for (size_t i = 0; i < cch; ++i)
for (const auto& wch : string)
{
const wchar_t wch = pws[i];
// We're forcing the translation to CP_USA, so that it'll be constant
// regardless of the CP the test is running in
std::deque<std::unique_ptr<KeyEvent>> convertedEvents = CharToKeyEvents(wch, CP_USA);
@ -310,8 +307,7 @@ bool TestInteractDispatch::WriteString(_In_reads_(cch) const wchar_t* const pws,
return WriteInput(keyEvents);
}
bool TestInteractDispatch::MoveCursor(const unsigned int row,
const unsigned int col)
bool TestInteractDispatch::MoveCursor(const size_t row, const size_t col)
{
VERIFY_IS_TRUE(_testState->_expectCursorPosition);
COORD received = { static_cast<short>(col), static_cast<short>(row) };
@ -324,8 +320,9 @@ void InputEngineTest::C0Test()
TestState testState;
auto pfn = std::bind(&TestState::TestInputCallback, &testState, std::placeholders::_1);
auto inputEngine = std::make_unique<InputStateMachineEngine>(new TestInteractDispatch(pfn, &testState));
auto _stateMachine = std::make_unique<StateMachine>(inputEngine.release());
auto dispatch = std::make_unique<TestInteractDispatch>(pfn, &testState);
auto inputEngine = std::make_unique<InputStateMachineEngine>(std::move(dispatch));
auto _stateMachine = std::make_unique<StateMachine>(std::move(inputEngine));
VERIFY_IS_NOT_NULL(_stateMachine);
testState._stateMachine = _stateMachine.get();
@ -412,7 +409,7 @@ void InputEngineTest::C0Test()
testState.vExpectedInput.push_back(inputRec);
_stateMachine->ProcessString(&inputSeq[0], inputSeq.length());
_stateMachine->ProcessString(inputSeq);
}
}
@ -420,9 +417,9 @@ void InputEngineTest::AlphanumericTest()
{
TestState testState;
auto pfn = std::bind(&TestState::TestInputCallback, &testState, std::placeholders::_1);
auto inputEngine = std::make_unique<InputStateMachineEngine>(new TestInteractDispatch(pfn, &testState));
auto _stateMachine = std::make_unique<StateMachine>(inputEngine.release());
auto dispatch = std::make_unique<TestInteractDispatch>(pfn, &testState);
auto inputEngine = std::make_unique<InputStateMachineEngine>(std::move(dispatch));
auto _stateMachine = std::make_unique<StateMachine>(std::move(inputEngine));
VERIFY_IS_NOT_NULL(_stateMachine);
testState._stateMachine = _stateMachine.get();
@ -457,7 +454,7 @@ void InputEngineTest::AlphanumericTest()
testState.vExpectedInput.push_back(inputRec);
_stateMachine->ProcessString(&inputSeq[0], inputSeq.length());
_stateMachine->ProcessString(inputSeq);
}
}
@ -465,8 +462,9 @@ void InputEngineTest::RoundTripTest()
{
TestState testState;
auto pfn = std::bind(&TestState::TestInputCallback, &testState, std::placeholders::_1);
auto inputEngine = std::make_unique<InputStateMachineEngine>(new TestInteractDispatch(pfn, &testState));
auto _stateMachine = std::make_unique<StateMachine>(inputEngine.release());
auto dispatch = std::make_unique<TestInteractDispatch>(pfn, &testState);
auto inputEngine = std::make_unique<InputStateMachineEngine>(std::move(dispatch));
auto _stateMachine = std::make_unique<StateMachine>(std::move(inputEngine));
VERIFY_IS_NOT_NULL(_stateMachine);
testState._stateMachine = _stateMachine.get();
@ -525,9 +523,9 @@ void InputEngineTest::WindowManipulationTest()
{
TestState testState;
auto pfn = std::bind(&TestState::TestInputCallback, &testState, std::placeholders::_1);
auto inputEngine = std::make_unique<InputStateMachineEngine>(new TestInteractDispatch(pfn, &testState));
auto _stateMachine = std::make_unique<StateMachine>(inputEngine.release());
auto dispatch = std::make_unique<TestInteractDispatch>(pfn, &testState);
auto inputEngine = std::make_unique<InputStateMachineEngine>(std::move(dispatch));
auto _stateMachine = std::make_unique<StateMachine>(std::move(inputEngine));
VERIFY_IS_NOT_NULL(_stateMachine.get());
testState._stateMachine = _stateMachine.get();
@ -584,7 +582,7 @@ void InputEngineTest::WindowManipulationTest()
std::wstring seq = seqBuilder.str();
Log::Comment(NoThrowString().Format(
L"Processing \"%s\"", seq.c_str()));
_stateMachine->ProcessString(&seq[0], seq.length());
_stateMachine->ProcessString(seq);
}
}
@ -592,9 +590,9 @@ void InputEngineTest::NonAsciiTest()
{
TestState testState;
auto pfn = std::bind(&TestState::TestInputStringCallback, &testState, std::placeholders::_1);
auto inputEngine = std::make_unique<InputStateMachineEngine>(new TestInteractDispatch(pfn, &testState));
auto _stateMachine = std::make_unique<StateMachine>(inputEngine.release());
auto dispatch = std::make_unique<TestInteractDispatch>(pfn, &testState);
auto inputEngine = std::make_unique<InputStateMachineEngine>(std::move(dispatch));
auto _stateMachine = std::make_unique<StateMachine>(std::move(inputEngine));
VERIFY_IS_NOT_NULL(_stateMachine.get());
testState._stateMachine = _stateMachine.get();
Log::Comment(L"Sending various non-ascii strings, and seeing what we get out");
@ -625,7 +623,7 @@ void InputEngineTest::NonAsciiTest()
testState.vExpectedInput.push_back(test);
test.Event.KeyEvent.bKeyDown = FALSE;
testState.vExpectedInput.push_back(test);
_stateMachine->ProcessString(&utf8Input[0], utf8Input.length());
_stateMachine->ProcessString(utf8Input);
// "旅", UTF-16: 0x65C5, utf8: "0xE6 0x97 0x85"
utf8Input = L"\u65C5";
@ -639,7 +637,7 @@ void InputEngineTest::NonAsciiTest()
testState.vExpectedInput.push_back(test);
test.Event.KeyEvent.bKeyDown = FALSE;
testState.vExpectedInput.push_back(test);
_stateMachine->ProcessString(&utf8Input[0], utf8Input.length());
_stateMachine->ProcessString(utf8Input);
}
void InputEngineTest::CursorPositioningTest()
@ -649,9 +647,9 @@ void InputEngineTest::CursorPositioningTest()
auto dispatch = std::make_unique<TestInteractDispatch>(pfn, &testState);
VERIFY_IS_NOT_NULL(dispatch.get());
auto inputEngine = std::make_unique<InputStateMachineEngine>(dispatch.release(), true);
auto inputEngine = std::make_unique<InputStateMachineEngine>(std::move(dispatch), true);
VERIFY_IS_NOT_NULL(inputEngine.get());
auto _stateMachine = std::make_unique<StateMachine>(inputEngine.release());
auto _stateMachine = std::make_unique<StateMachine>(std::move(inputEngine));
VERIFY_IS_NOT_NULL(_stateMachine);
testState._stateMachine = _stateMachine.get();
@ -667,7 +665,7 @@ void InputEngineTest::CursorPositioningTest()
Log::Comment(NoThrowString().Format(
L"Processing \"%s\"", seq.c_str()));
_stateMachine->ProcessString(&seq[0], seq.length());
_stateMachine->ProcessString(seq);
testState._expectCursorPosition = false;
@ -683,16 +681,16 @@ void InputEngineTest::CursorPositioningTest()
testState.vExpectedInput.push_back(inputRec);
Log::Comment(NoThrowString().Format(
L"Processing \"%s\"", seq.c_str()));
_stateMachine->ProcessString(&seq[0], seq.length());
_stateMachine->ProcessString(seq);
}
void InputEngineTest::CSICursorBackTabTest()
{
TestState testState;
auto pfn = std::bind(&TestState::TestInputCallback, &testState, std::placeholders::_1);
auto inputEngine = std::make_unique<InputStateMachineEngine>(new TestInteractDispatch(pfn, &testState));
auto _stateMachine = std::make_unique<StateMachine>(inputEngine.release());
auto dispatch = std::make_unique<TestInteractDispatch>(pfn, &testState);
auto inputEngine = std::make_unique<InputStateMachineEngine>(std::move(dispatch));
auto _stateMachine = std::make_unique<StateMachine>(std::move(inputEngine));
VERIFY_IS_NOT_NULL(_stateMachine);
testState._stateMachine = _stateMachine.get();
@ -711,16 +709,16 @@ void InputEngineTest::CSICursorBackTabTest()
const std::wstring seq = L"\x1b[Z";
Log::Comment(NoThrowString().Format(
L"Processing \"%s\"", seq.c_str()));
_stateMachine->ProcessString(&seq[0], seq.length());
_stateMachine->ProcessString(seq);
}
void InputEngineTest::AltBackspaceTest()
{
TestState testState;
auto pfn = std::bind(&TestState::TestInputCallback, &testState, std::placeholders::_1);
auto inputEngine = std::make_unique<InputStateMachineEngine>(new TestInteractDispatch(pfn, &testState));
auto _stateMachine = std::make_unique<StateMachine>(inputEngine.release());
auto dispatch = std::make_unique<TestInteractDispatch>(pfn, &testState);
auto inputEngine = std::make_unique<InputStateMachineEngine>(std::move(dispatch));
auto _stateMachine = std::make_unique<StateMachine>(std::move(inputEngine));
VERIFY_IS_NOT_NULL(_stateMachine);
testState._stateMachine = _stateMachine.get();
@ -745,9 +743,9 @@ void InputEngineTest::AltCtrlDTest()
{
TestState testState;
auto pfn = std::bind(&TestState::TestInputCallback, &testState, std::placeholders::_1);
auto inputEngine = std::make_unique<InputStateMachineEngine>(new TestInteractDispatch(pfn, &testState));
auto _stateMachine = std::make_unique<StateMachine>(inputEngine.release());
auto dispatch = std::make_unique<TestInteractDispatch>(pfn, &testState);
auto inputEngine = std::make_unique<InputStateMachineEngine>(std::move(dispatch));
auto _stateMachine = std::make_unique<StateMachine>(std::move(inputEngine));
VERIFY_IS_NOT_NULL(_stateMachine);
testState._stateMachine = _stateMachine.get();
@ -809,8 +807,9 @@ void InputEngineTest::AltIntermediateTest()
terminalInput.HandleKey(ev.get());
}
};
auto inputEngine = std::make_unique<InputStateMachineEngine>(new TestInteractDispatch(pfnInputStateMachineCallback, &testState));
auto stateMachine = std::make_unique<StateMachine>(inputEngine.release());
auto dispatch = std::make_unique<TestInteractDispatch>(pfnInputStateMachineCallback, &testState);
auto inputEngine = std::make_unique<InputStateMachineEngine>(std::move(dispatch));
auto stateMachine = std::make_unique<StateMachine>(std::move(inputEngine));
VERIFY_IS_NOT_NULL(stateMachine);
testState._stateMachine = stateMachine.get();
@ -837,9 +836,9 @@ void InputEngineTest::AltBackspaceEnterTest()
TestState testState;
auto pfn = std::bind(&TestState::TestInputCallback, &testState, std::placeholders::_1);
auto inputEngine = std::make_unique<InputStateMachineEngine>(new TestInteractDispatch(pfn, &testState));
auto _stateMachine = std::make_unique<StateMachine>(inputEngine.release());
auto dispatch = std::make_unique<TestInteractDispatch>(pfn, &testState);
auto inputEngine = std::make_unique<InputStateMachineEngine>(std::move(dispatch));
auto _stateMachine = std::make_unique<StateMachine>(std::move(inputEngine));
VERIFY_IS_NOT_NULL(_stateMachine);
testState._stateMachine = _stateMachine.get();

File diff suppressed because it is too large Load diff

View file

@ -31,46 +31,39 @@ public:
bool ActionExecute(const wchar_t /* wch */) override { return true; };
bool ActionExecuteFromEscape(const wchar_t /* wch */) override { return true; };
bool ActionPrint(const wchar_t /* wch */) override { return true; };
bool ActionPrintString(const wchar_t* const /* rgwch */,
size_t const /* cch */) override { return true; };
bool ActionPrintString(const std::wstring_view /* string */) override { return true; };
bool ActionPassThroughString(const wchar_t* const /* rgwch */,
size_t const /* cch */) override { return true; };
bool ActionPassThroughString(const std::wstring_view /* string */) override { return true; };
bool ActionEscDispatch(const wchar_t /* wch */,
const unsigned short /* cIntermediate */,
const wchar_t /* wchIntermediate */) override { return true; };
const std::basic_string_view<wchar_t> /* intermediates */) override { return true; };
bool ActionClear() override { return true; };
bool ActionIgnore() override { return true; };
bool ActionOscDispatch(const wchar_t /* wch */,
const unsigned short /* sOscParam */,
wchar_t* const /* pwchOscStringBuffer */,
const unsigned short /* cchOscString */) override { return true; };
const size_t /* parameter */,
const std::wstring_view /* string */) override { return true; };
bool ActionSs3Dispatch(const wchar_t /* wch */,
const unsigned short* const /* rgusParams */,
const unsigned short /* cParams */) override { return true; };
const std::basic_string_view<size_t> /* parameters */) override { return true; };
bool FlushAtEndOfString() const override { return false; };
bool DispatchControlCharsFromEscape() const override { return false; };
bool DispatchIntermediatesFromEscape() const override { return false; };
// ActionCsiDispatch is the only method that's actually implemented.
bool ActionCsiDispatch(const wchar_t /* wch */,
const unsigned short /* cIntermediate */,
const wchar_t /* wchIntermediate */,
_In_reads_(cParams) const unsigned short* const rgusParams,
const unsigned short cParams) override
bool ActionCsiDispatch(const wchar_t /*wch*/,
const std::basic_string_view<wchar_t> /*intermediates*/,
const std::basic_string_view<size_t> parameters) override
{
csiParams.emplace(rgusParams, rgusParams + cParams);
csiParams.emplace(parameters.cbegin(), parameters.cend());
return true;
}
// This will only be populated if ActionCsiDispatch is called.
std::optional<std::vector<unsigned short>> csiParams;
std::optional<std::vector<size_t>> csiParams;
};
class Microsoft::Console::VirtualTerminal::StateMachineTest
@ -95,18 +88,18 @@ void StateMachineTest::TwoStateMachinesDoNotInterfereWithEachother()
auto firstEnginePtr{ std::make_unique<TestStateMachineEngine>() };
// this dance is required because StateMachine presumes to take ownership of its engine.
const auto& firstEngine{ *firstEnginePtr.get() };
StateMachine firstStateMachine{ firstEnginePtr.release() };
StateMachine firstStateMachine{ std::move(firstEnginePtr) };
auto secondEnginePtr{ std::make_unique<TestStateMachineEngine>() };
const auto& secondEngine{ *secondEnginePtr.get() };
StateMachine secondStateMachine{ secondEnginePtr.release() };
StateMachine secondStateMachine{ std::move(secondEnginePtr) };
firstStateMachine.ProcessString(L"\x1b[12"); // partial sequence
secondStateMachine.ProcessString(L"\x1b[3C"); // full sequence on second parser
firstStateMachine.ProcessString(L";34m"); // completion to previous partial sequence on first parser
std::vector<unsigned short> expectedFirstCsi{ 12u, 34u };
std::vector<unsigned short> expectedSecondCsi{ 3u };
std::vector<size_t> expectedFirstCsi{ 12u, 34u };
std::vector<size_t> expectedSecondCsi{ 3u };
VERIFY_ARE_EQUAL(expectedFirstCsi, firstEngine.csiParams);
VERIFY_ARE_EQUAL(expectedSecondCsi, secondEngine.csiParams);