2019-05-03 00:29:04 +02:00
|
|
|
// Copyright (c) Microsoft Corporation.
|
|
|
|
// Licensed under the MIT license.
|
|
|
|
|
|
|
|
#include "pch.h"
|
|
|
|
#include "TerminalDispatch.hpp"
|
|
|
|
using namespace ::Microsoft::Terminal::Core;
|
|
|
|
using namespace ::Microsoft::Console::VirtualTerminal;
|
|
|
|
|
|
|
|
// NOTE:
|
|
|
|
// Functions related to Set Graphics Renditions (SGR) are in
|
|
|
|
// TerminalDispatchGraphics.cpp, not this file
|
|
|
|
|
2020-01-03 19:44:27 +01:00
|
|
|
TerminalDispatch::TerminalDispatch(ITerminalApi& terminalApi) noexcept :
|
2019-05-03 00:29:04 +02:00
|
|
|
_terminalApi{ terminalApi }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-01-03 19:44:27 +01:00
|
|
|
void TerminalDispatch::Execute(const wchar_t wchControl) noexcept
|
2019-05-03 00:29:04 +02:00
|
|
|
{
|
|
|
|
_terminalApi.ExecuteChar(wchControl);
|
|
|
|
}
|
|
|
|
|
2020-01-03 19:44:27 +01:00
|
|
|
void TerminalDispatch::Print(const wchar_t wchPrintable) noexcept
|
2019-05-03 00:29:04 +02:00
|
|
|
{
|
|
|
|
_terminalApi.PrintString({ &wchPrintable, 1 });
|
|
|
|
}
|
|
|
|
|
2020-01-03 19:44:27 +01:00
|
|
|
void TerminalDispatch::PrintString(const std::wstring_view string) noexcept
|
2019-05-03 00:29:04 +02:00
|
|
|
{
|
2019-12-19 23:12:53 +01:00
|
|
|
_terminalApi.PrintString(string);
|
2019-05-03 00:29:04 +02:00
|
|
|
}
|
|
|
|
|
2019-12-19 23:12:53 +01:00
|
|
|
bool TerminalDispatch::CursorPosition(const size_t line,
|
2020-01-03 15:25:21 +01:00
|
|
|
const size_t column) noexcept
|
2020-01-03 19:44:27 +01:00
|
|
|
try
|
2019-05-03 00:29:04 +02:00
|
|
|
{
|
2020-01-03 19:44:27 +01:00
|
|
|
SHORT x{ 0 };
|
|
|
|
SHORT y{ 0 };
|
|
|
|
|
|
|
|
RETURN_BOOL_IF_FALSE(FAILED(SizeTToShort(column, &x)) ||
|
|
|
|
FAILED(SizeTToShort(line, &y)));
|
|
|
|
|
|
|
|
RETURN_BOOL_IF_FALSE(FAILED(ShortSub(x, 1, &x)) ||
|
|
|
|
FAILED(ShortSub(y, 1, &y)));
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
return _terminalApi.SetCursorPosition(x, y);
|
|
|
|
}
|
2020-01-03 19:44:27 +01:00
|
|
|
CATCH_LOG_RETURN_FALSE()
|
2019-05-03 00:29:04 +02:00
|
|
|
|
2020-01-03 15:25:21 +01:00
|
|
|
bool TerminalDispatch::CursorForward(const size_t distance) noexcept
|
2020-01-03 19:44:27 +01:00
|
|
|
try
|
2019-05-03 00:29:04 +02:00
|
|
|
{
|
|
|
|
const auto cursorPos = _terminalApi.GetCursorPosition();
|
2019-12-19 23:12:53 +01:00
|
|
|
const COORD newCursorPos{ cursorPos.X + gsl::narrow<short>(distance), cursorPos.Y };
|
2019-05-03 00:29:04 +02:00
|
|
|
return _terminalApi.SetCursorPosition(newCursorPos.X, newCursorPos.Y);
|
|
|
|
}
|
2020-01-03 19:44:27 +01:00
|
|
|
CATCH_LOG_RETURN_FALSE()
|
2019-05-03 00:29:04 +02:00
|
|
|
|
2020-01-03 15:25:21 +01:00
|
|
|
bool TerminalDispatch::CursorBackward(const size_t distance) noexcept
|
2020-01-03 19:44:27 +01:00
|
|
|
try
|
2019-07-31 01:28:28 +02:00
|
|
|
{
|
|
|
|
const auto cursorPos = _terminalApi.GetCursorPosition();
|
2019-12-19 23:12:53 +01:00
|
|
|
const COORD newCursorPos{ cursorPos.X - gsl::narrow<short>(distance), cursorPos.Y };
|
2019-07-31 01:28:28 +02:00
|
|
|
return _terminalApi.SetCursorPosition(newCursorPos.X, newCursorPos.Y);
|
|
|
|
}
|
2020-01-03 19:44:27 +01:00
|
|
|
CATCH_LOG_RETURN_FALSE()
|
2019-07-31 01:28:28 +02:00
|
|
|
|
2020-01-03 15:25:21 +01:00
|
|
|
bool TerminalDispatch::CursorUp(const size_t distance) noexcept
|
2020-01-03 19:44:27 +01:00
|
|
|
try
|
2019-07-31 01:28:28 +02:00
|
|
|
{
|
|
|
|
const auto cursorPos = _terminalApi.GetCursorPosition();
|
2019-12-19 23:12:53 +01:00
|
|
|
const COORD newCursorPos{ cursorPos.X, cursorPos.Y + gsl::narrow<short>(distance) };
|
2019-07-31 01:28:28 +02:00
|
|
|
return _terminalApi.SetCursorPosition(newCursorPos.X, newCursorPos.Y);
|
|
|
|
}
|
2020-01-03 19:44:27 +01:00
|
|
|
CATCH_LOG_RETURN_FALSE()
|
2019-07-31 01:28:28 +02:00
|
|
|
|
2020-01-03 15:25:21 +01:00
|
|
|
bool TerminalDispatch::EraseCharacters(const size_t numChars) noexcept
|
2020-01-03 19:44:27 +01:00
|
|
|
try
|
2019-05-03 00:29:04 +02:00
|
|
|
{
|
2019-12-19 23:12:53 +01:00
|
|
|
return _terminalApi.EraseCharacters(numChars);
|
2019-05-03 00:29:04 +02:00
|
|
|
}
|
2020-01-03 19:44:27 +01:00
|
|
|
CATCH_LOG_RETURN_FALSE()
|
2019-05-03 00:29:04 +02:00
|
|
|
|
2020-01-03 15:25:21 +01:00
|
|
|
bool TerminalDispatch::SetWindowTitle(std::wstring_view title) noexcept
|
2020-01-03 19:44:27 +01:00
|
|
|
try
|
2019-05-03 00:29:04 +02:00
|
|
|
{
|
|
|
|
return _terminalApi.SetWindowTitle(title);
|
|
|
|
}
|
2020-01-03 19:44:27 +01:00
|
|
|
CATCH_LOG_RETURN_FALSE()
|
2019-05-03 00:29:04 +02:00
|
|
|
|
|
|
|
// Method Description:
|
|
|
|
// - Sets a single entry of the colortable to a new value
|
|
|
|
// Arguments:
|
|
|
|
// - tableIndex: The VT color table index
|
2019-12-19 23:12:53 +01:00
|
|
|
// - color: The new RGB color value to use.
|
2019-05-03 00:29:04 +02:00
|
|
|
// Return Value:
|
2019-05-24 18:53:00 +02:00
|
|
|
// True if handled successfully. False otherwise.
|
2019-05-03 00:29:04 +02:00
|
|
|
bool TerminalDispatch::SetColorTableEntry(const size_t tableIndex,
|
2020-01-03 15:25:21 +01:00
|
|
|
const DWORD color) noexcept
|
2020-01-03 19:44:27 +01:00
|
|
|
try
|
2019-05-03 00:29:04 +02:00
|
|
|
{
|
2019-12-19 23:12:53 +01:00
|
|
|
return _terminalApi.SetColorTableEntry(tableIndex, color);
|
2019-05-03 00:29:04 +02:00
|
|
|
}
|
2020-01-03 19:44:27 +01:00
|
|
|
CATCH_LOG_RETURN_FALSE()
|
2019-05-23 19:44:27 +02:00
|
|
|
|
2020-01-03 15:25:21 +01:00
|
|
|
bool TerminalDispatch::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle) noexcept
|
2020-01-03 19:44:27 +01:00
|
|
|
try
|
2019-05-23 19:44:27 +02:00
|
|
|
{
|
|
|
|
return _terminalApi.SetCursorStyle(cursorStyle);
|
|
|
|
}
|
2020-01-03 19:44:27 +01:00
|
|
|
CATCH_LOG_RETURN_FALSE()
|
2019-05-24 18:53:00 +02:00
|
|
|
|
|
|
|
// Method Description:
|
|
|
|
// - Sets the default foreground color to a new value
|
|
|
|
// Arguments:
|
2019-12-19 23:12:53 +01:00
|
|
|
// - color: The new RGB color value to use, in 0x00BBGGRR form
|
2019-05-24 18:53:00 +02:00
|
|
|
// Return Value:
|
|
|
|
// True if handled successfully. False otherwise.
|
2020-01-03 15:25:21 +01:00
|
|
|
bool TerminalDispatch::SetDefaultForeground(const DWORD color) noexcept
|
2020-01-03 19:44:27 +01:00
|
|
|
try
|
2019-05-24 18:53:00 +02:00
|
|
|
{
|
2019-12-19 23:12:53 +01:00
|
|
|
return _terminalApi.SetDefaultForeground(color);
|
2019-05-24 18:53:00 +02:00
|
|
|
}
|
2020-01-03 19:44:27 +01:00
|
|
|
CATCH_LOG_RETURN_FALSE()
|
2019-05-24 18:53:00 +02:00
|
|
|
|
|
|
|
// Method Description:
|
|
|
|
// - Sets the default background color to a new value
|
|
|
|
// Arguments:
|
2019-12-19 23:12:53 +01:00
|
|
|
// - color: The new RGB color value to use, in 0x00BBGGRR form
|
2019-05-24 18:53:00 +02:00
|
|
|
// Return Value:
|
|
|
|
// True if handled successfully. False otherwise.
|
2020-01-03 15:25:21 +01:00
|
|
|
bool TerminalDispatch::SetDefaultBackground(const DWORD color) noexcept
|
2020-01-03 19:44:27 +01:00
|
|
|
try
|
2019-05-24 18:53:00 +02:00
|
|
|
{
|
2019-12-19 23:12:53 +01:00
|
|
|
return _terminalApi.SetDefaultBackground(color);
|
2019-05-24 18:53:00 +02:00
|
|
|
}
|
2020-01-03 19:44:27 +01:00
|
|
|
CATCH_LOG_RETURN_FALSE()
|
2019-07-25 22:31:41 +02:00
|
|
|
|
|
|
|
// Method Description:
|
2019-07-31 01:28:28 +02:00
|
|
|
// - Erases characters in the buffer depending on the erase type
|
|
|
|
// Arguments:
|
|
|
|
// - eraseType: the erase type (from beginning, to end, or all)
|
|
|
|
// Return Value:
|
|
|
|
// True if handled successfully. False otherwise.
|
2020-01-03 15:25:21 +01:00
|
|
|
bool TerminalDispatch::EraseInLine(const DispatchTypes::EraseType eraseType) noexcept
|
2020-01-03 19:44:27 +01:00
|
|
|
try
|
2019-07-31 01:28:28 +02:00
|
|
|
{
|
|
|
|
return _terminalApi.EraseInLine(eraseType);
|
|
|
|
}
|
2020-01-03 19:44:27 +01:00
|
|
|
CATCH_LOG_RETURN_FALSE()
|
2019-07-31 01:28:28 +02:00
|
|
|
|
|
|
|
// Method Description:
|
2019-12-19 23:12:53 +01:00
|
|
|
// - Deletes count number of characters starting from where the cursor is currently
|
2019-07-31 01:28:28 +02:00
|
|
|
// Arguments:
|
2019-12-19 23:12:53 +01:00
|
|
|
// - count, the number of characters to delete
|
2019-07-31 01:28:28 +02:00
|
|
|
// Return Value:
|
|
|
|
// True if handled successfully. False otherwise.
|
2020-01-03 15:25:21 +01:00
|
|
|
bool TerminalDispatch::DeleteCharacter(const size_t count) noexcept
|
2020-01-03 19:44:27 +01:00
|
|
|
try
|
2019-07-31 01:28:28 +02:00
|
|
|
{
|
2019-12-19 23:12:53 +01:00
|
|
|
return _terminalApi.DeleteCharacter(count);
|
2019-07-31 01:28:28 +02:00
|
|
|
}
|
2020-01-03 19:44:27 +01:00
|
|
|
CATCH_LOG_RETURN_FALSE()
|
2019-07-31 01:28:28 +02:00
|
|
|
|
|
|
|
// Method Description:
|
2019-12-19 23:12:53 +01:00
|
|
|
// - Adds count number of spaces starting from where the cursor is currently
|
2019-07-31 01:28:28 +02:00
|
|
|
// Arguments:
|
2019-12-19 23:12:53 +01:00
|
|
|
// - count, the number of spaces to add
|
2019-07-31 01:28:28 +02:00
|
|
|
// Return Value:
|
|
|
|
// True if handled successfully, false otherwise
|
2020-01-03 15:25:21 +01:00
|
|
|
bool TerminalDispatch::InsertCharacter(const size_t count) noexcept
|
2020-01-03 19:44:27 +01:00
|
|
|
try
|
2019-07-31 01:28:28 +02:00
|
|
|
{
|
2019-12-19 23:12:53 +01:00
|
|
|
return _terminalApi.InsertCharacter(count);
|
2019-07-31 01:28:28 +02:00
|
|
|
}
|
2020-01-03 19:44:27 +01:00
|
|
|
CATCH_LOG_RETURN_FALSE()
|
2019-07-31 01:28:28 +02:00
|
|
|
|
|
|
|
// Method Description:
|
|
|
|
// - Moves the viewport and erases text from the buffer depending on the eraseType
|
|
|
|
// Arguments:
|
|
|
|
// - eraseType: the desired erase type
|
|
|
|
// Return Value:
|
|
|
|
// True if handled successfully. False otherwise
|
2020-01-03 15:25:21 +01:00
|
|
|
bool TerminalDispatch::EraseInDisplay(const DispatchTypes::EraseType eraseType) noexcept
|
2020-01-03 19:44:27 +01:00
|
|
|
try
|
2019-07-25 22:31:41 +02:00
|
|
|
{
|
2019-07-31 01:28:28 +02:00
|
|
|
return _terminalApi.EraseInDisplay(eraseType);
|
2019-07-25 22:31:41 +02:00
|
|
|
}
|
2020-01-03 19:44:27 +01:00
|
|
|
CATCH_LOG_RETURN_FALSE()
|