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
|
|
|
|
|
|
|
|
TerminalDispatch::TerminalDispatch(ITerminalApi& terminalApi) :
|
|
|
|
_terminalApi{ terminalApi }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void TerminalDispatch::Execute(const wchar_t wchControl)
|
|
|
|
{
|
|
|
|
_terminalApi.ExecuteChar(wchControl);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TerminalDispatch::Print(const wchar_t wchPrintable)
|
|
|
|
{
|
|
|
|
_terminalApi.PrintString({ &wchPrintable, 1 });
|
|
|
|
}
|
|
|
|
|
2019-12-19 23:12:53 +01:00
|
|
|
void TerminalDispatch::PrintString(const std::wstring_view string)
|
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,
|
|
|
|
const size_t column)
|
2019-05-03 00:29:04 +02:00
|
|
|
{
|
2019-12-19 23:12:53 +01:00
|
|
|
const auto columnInBufferSpace = column - 1;
|
|
|
|
const auto lineInBufferSpace = line - 1;
|
|
|
|
short x = static_cast<short>(column - 1);
|
|
|
|
short y = static_cast<short>(line - 1);
|
2019-05-03 00:29:04 +02:00
|
|
|
return _terminalApi.SetCursorPosition(x, y);
|
|
|
|
}
|
|
|
|
|
2019-12-19 23:12:53 +01:00
|
|
|
bool TerminalDispatch::CursorForward(const size_t distance)
|
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);
|
|
|
|
}
|
|
|
|
|
2019-12-19 23:12:53 +01:00
|
|
|
bool TerminalDispatch::CursorBackward(const size_t distance)
|
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);
|
|
|
|
}
|
|
|
|
|
2019-12-19 23:12:53 +01:00
|
|
|
bool TerminalDispatch::CursorUp(const size_t distance)
|
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);
|
|
|
|
}
|
|
|
|
|
2019-12-19 23:12:53 +01:00
|
|
|
bool TerminalDispatch::EraseCharacters(const size_t numChars)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
bool TerminalDispatch::SetWindowTitle(std::wstring_view title)
|
|
|
|
{
|
|
|
|
return _terminalApi.SetWindowTitle(title);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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,
|
2019-12-19 23:12:53 +01:00
|
|
|
const DWORD color)
|
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
|
|
|
}
|
2019-05-23 19:44:27 +02:00
|
|
|
|
|
|
|
bool TerminalDispatch::SetCursorStyle(const DispatchTypes::CursorStyle cursorStyle)
|
|
|
|
{
|
|
|
|
return _terminalApi.SetCursorStyle(cursorStyle);
|
|
|
|
}
|
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.
|
2019-12-19 23:12:53 +01:00
|
|
|
bool TerminalDispatch::SetDefaultForeground(const DWORD color)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2019-12-19 23:12:53 +01:00
|
|
|
bool TerminalDispatch::SetDefaultBackground(const DWORD color)
|
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
|
|
|
}
|
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.
|
|
|
|
bool TerminalDispatch::EraseInLine(const DispatchTypes::EraseType eraseType)
|
|
|
|
{
|
|
|
|
return _terminalApi.EraseInLine(eraseType);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2019-12-19 23:12:53 +01:00
|
|
|
bool TerminalDispatch::DeleteCharacter(const size_t count)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2019-12-19 23:12:53 +01:00
|
|
|
bool TerminalDispatch::InsertCharacter(const size_t count)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
bool TerminalDispatch::EraseInDisplay(const DispatchTypes::EraseType eraseType)
|
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
|
|
|
}
|