diff --git a/.github/actions/spelling/allow/apis.txt b/.github/actions/spelling/allow/apis.txt index e0cc7550095..ce36d8d2a2b 100644 --- a/.github/actions/spelling/allow/apis.txt +++ b/.github/actions/spelling/allow/apis.txt @@ -55,6 +55,8 @@ GETMOUSEHOVERTIME Hashtable HIGHCONTRASTON HIGHCONTRASTW +hinternet +HINTERNET hotkeys href hrgn @@ -214,6 +216,8 @@ Viewbox virtualalloc wcsstr wcstoui +WDJ +winhttp winmain winsta winstamin @@ -221,6 +225,7 @@ wmemcmp wpc WSF wsregex +WWH wwinmain xchg XDocument diff --git a/.github/actions/spelling/expect/expect.txt b/.github/actions/spelling/expect/expect.txt index 9c7ef11a7d7..0c46903dbe8 100644 --- a/.github/actions/spelling/expect/expect.txt +++ b/.github/actions/spelling/expect/expect.txt @@ -311,7 +311,6 @@ CPLINFO cplusplus CPPCORECHECK cppcorecheckrules -cpprest cpprestsdk cppwinrt CProc @@ -1437,7 +1436,6 @@ PPEB ppf ppguid ppidl -pplx PPROC PPROCESS ppropvar @@ -2114,7 +2112,6 @@ WDDMCONSOLECONTEXT wdm webpage websites -websockets wekyb wex wextest diff --git a/build/config/ESRPSigning_Terminal.json b/build/config/ESRPSigning_Terminal.json index 715848a42c4..01780c2df3c 100644 --- a/build/config/ESRPSigning_Terminal.json +++ b/build/config/ESRPSigning_Terminal.json @@ -67,51 +67,6 @@ } ] } - }, - { - // THIRD PARTY SOFTWARE - "MatchedPath": [ - "cpprest*.dll" - ], - "SigningInfo": { - "Operations": [ - { - "KeyCode": "CP-231522", - "OperationSetCode": "SigntoolSign", - "Parameters": [ - { - "parameterName": "OpusName", - "parameterValue": "Microsoft" - }, - { - "parameterName": "OpusInfo", - "parameterValue": "http://www.microsoft.com" - }, - { - "parameterName": "FileDigest", - "parameterValue": "/fd \"SHA256\"" - }, - { - "parameterName": "PageHash", - "parameterValue": "/NPH" - }, - { - "parameterName": "TimeStamp", - "parameterValue": "/tr \"http://rfc3161.gtm.corp.microsoft.com/TSS/HttpTspServer\" /td sha256" - } - ], - "ToolName": "sign", - "ToolVersion": "1.0" - }, - { - "KeyCode": "CP-231522", - "OperationSetCode": "SigntoolVerify", - "Parameters": [], - "ToolName": "sign", - "ToolVersion": "1.0" - } - ] - } } ] } diff --git a/build/pipelines/release.yml b/build/pipelines/release.yml index 2f3c6992c5e..2fd0f8757db 100644 --- a/build/pipelines/release.yml +++ b/build/pipelines/release.yml @@ -64,7 +64,7 @@ parameters: variables: MakeAppxPath: 'C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x86\MakeAppx.exe' - TerminalInternalPackageVersion: "0.0.7" + TerminalInternalPackageVersion: "0.0.8" # If we are building a branch called "release-*", change the NuGet suffix # to "preview". If we don't do that, XES will set the suffix to "release1" # because it truncates the value after the first period. diff --git a/build/pipelines/templates/build-console-compliance-job.yml b/build/pipelines/templates/build-console-compliance-job.yml index d5042cdb177..0f885cfcce7 100644 --- a/build/pipelines/templates/build-console-compliance-job.yml +++ b/build/pipelines/templates/build-console-compliance-job.yml @@ -144,7 +144,7 @@ jobs: inputs: TargetPattern: guardianGlob # See https://aka.ms/gdn-globs for how to do match patterns - AnalyzeTargetGlob: $(Build.SourcesDirectory)\bin\**\*.dll;$(Build.SourcesDirectory)\bin\**\*.exe;-:file|**\Microsoft.UI.Xaml.dll;-:file|**\Microsoft.Toolkit.Win32.UI.XamlHost.dll;-:file|**\vcruntime*.dll;-:file|**\vcomp*.dll;-:file|**\vccorlib*.dll;-:file|**\vcamp*.dll;-:file|**\msvcp*.dll;-:file|**\concrt*.dll;-:file|**\TerminalThemeHelpers*.dll;-:file|**\cpprest*.dll + AnalyzeTargetGlob: $(Build.SourcesDirectory)\bin\**\*.dll;$(Build.SourcesDirectory)\bin\**\*.exe;-:file|**\Microsoft.UI.Xaml.dll;-:file|**\Microsoft.Toolkit.Win32.UI.XamlHost.dll;-:file|**\vcruntime*.dll;-:file|**\vcomp*.dll;-:file|**\vccorlib*.dll;-:file|**\vcamp*.dll;-:file|**\msvcp*.dll;-:file|**\concrt*.dll;-:file|**\TerminalThemeHelpers*.dll continueOnError: true # Set XES_SERIALPOSTBUILDREADY to run Security and Compliance task once per build diff --git a/build/scripts/Test-WindowsTerminalPackage.ps1 b/build/scripts/Test-WindowsTerminalPackage.ps1 index aa9cca6d107..a33329c26cd 100644 --- a/build/scripts/Test-WindowsTerminalPackage.ps1 +++ b/build/scripts/Test-WindowsTerminalPackage.ps1 @@ -96,11 +96,6 @@ Try { Throw "Failed to find App.xbf (TerminalApp project) in resources.pri" } - If (($null -eq (Get-Item "$AppxPackageRootPath\cpprest142_2_10.dll" -EA:Ignore)) -And - ($null -eq (Get-Item "$AppxPackageRootPath\cpprest142_2_10d.dll" -EA:Ignore))) { - Throw "Failed to find cpprest142_2_10.dll -- check the WAP packaging project" - } - If (($null -eq (Get-Item "$AppxPackageRootPath\wtd.exe" -EA:Ignore)) -And ($null -eq (Get-Item "$AppxPackageRootPath\wt.exe" -EA:Ignore))) { Throw "Failed to find wt.exe/wtd.exe -- check the WAP packaging project" diff --git a/dep/nuget/packages.config b/dep/nuget/packages.config index 0a62482b487..935d004a72d 100644 --- a/dep/nuget/packages.config +++ b/dep/nuget/packages.config @@ -5,7 +5,6 @@ - diff --git a/scratch/ScratchIslandApp/WindowExe/WindowExe.vcxproj b/scratch/ScratchIslandApp/WindowExe/WindowExe.vcxproj index e17243bfc6e..de4c7a34351 100644 --- a/scratch/ScratchIslandApp/WindowExe/WindowExe.vcxproj +++ b/scratch/ScratchIslandApp/WindowExe/WindowExe.vcxproj @@ -197,26 +197,6 @@ - - - - <_TerminalConnectionDlls Include="$(OpenConsoleCommonOutDir)\TerminalConnection\*.dll" /> - - - $(ProjectName) - BuiltProjectOutputGroup - %(Filename)%(Extension) - - - - <_WindowsTerminalExe Include="$(OpenConsoleCommonOutDir)\WindowsTerminal\*.exe" /> diff --git a/src/buffer/out/OutputCellIterator.cpp b/src/buffer/out/OutputCellIterator.cpp index 616d36c4a82..8c5247bb410 100644 --- a/src/buffer/out/OutputCellIterator.cpp +++ b/src/buffer/out/OutputCellIterator.cpp @@ -113,7 +113,7 @@ OutputCellIterator::OutputCellIterator(const std::wstring_view utf16Text, const // - This is an iterator over legacy colors only. The text is not modified. // Arguments: // - legacyAttrs - One legacy color item per cell -OutputCellIterator::OutputCellIterator(const gsl::span legacyAttrs) noexcept : +OutputCellIterator::OutputCellIterator(const std::span legacyAttrs) noexcept : _mode(Mode::LegacyAttr), _currentView(s_GenerateViewLegacyAttr(til::at(legacyAttrs, 0))), _run(legacyAttrs), @@ -128,7 +128,7 @@ OutputCellIterator::OutputCellIterator(const gsl::span legacyAttrs) // - This is an iterator over legacy cell data. We will use the unicode text and the legacy color attribute. // Arguments: // - charInfos - Multiple cell with unicode text and legacy color data. -OutputCellIterator::OutputCellIterator(const gsl::span charInfos) noexcept : +OutputCellIterator::OutputCellIterator(const std::span charInfos) noexcept : _mode(Mode::CharInfo), _currentView(s_GenerateView(til::at(charInfos, 0))), _run(charInfos), @@ -143,7 +143,7 @@ OutputCellIterator::OutputCellIterator(const gsl::span charInfo // - This is an iterator over existing OutputCells with full text and color data. // Arguments: // - cells - Multiple cells in a run -OutputCellIterator::OutputCellIterator(const gsl::span cells) : +OutputCellIterator::OutputCellIterator(const std::span cells) : _mode(Mode::Cell), _currentView(s_GenerateView(til::at(cells, 0))), _run(cells), @@ -181,15 +181,15 @@ OutputCellIterator::operator bool() const noexcept } case Mode::Cell: { - return _pos < std::get>(_run).size(); + return _pos < std::get>(_run).size(); } case Mode::CharInfo: { - return _pos < std::get>(_run).size(); + return _pos < std::get>(_run).size(); } case Mode::LegacyAttr: { - return _pos < std::get>(_run).size(); + return _pos < std::get>(_run).size(); } default: FAIL_FAST_HR(E_NOTIMPL); @@ -263,7 +263,7 @@ OutputCellIterator& OutputCellIterator::operator++() _pos++; if (operator bool()) { - _currentView = s_GenerateView(til::at(std::get>(_run), _pos)); + _currentView = s_GenerateView(til::at(std::get>(_run), _pos)); } break; } @@ -273,7 +273,7 @@ OutputCellIterator& OutputCellIterator::operator++() _pos++; if (operator bool()) { - _currentView = s_GenerateView(til::at(std::get>(_run), _pos)); + _currentView = s_GenerateView(til::at(std::get>(_run), _pos)); } break; } @@ -283,7 +283,7 @@ OutputCellIterator& OutputCellIterator::operator++() _pos++; if (operator bool()) { - _currentView = s_GenerateViewLegacyAttr(til::at(std::get>(_run), _pos)); + _currentView = s_GenerateViewLegacyAttr(til::at(std::get>(_run), _pos)); } break; } diff --git a/src/buffer/out/OutputCellIterator.hpp b/src/buffer/out/OutputCellIterator.hpp index 2229dca25a8..8f59ac2eb81 100644 --- a/src/buffer/out/OutputCellIterator.hpp +++ b/src/buffer/out/OutputCellIterator.hpp @@ -39,9 +39,9 @@ class OutputCellIterator final OutputCellIterator(const CHAR_INFO& charInfo, const size_t fillLimit = 0) noexcept; OutputCellIterator(const std::wstring_view utf16Text) noexcept; OutputCellIterator(const std::wstring_view utf16Text, const TextAttribute& attribute, const size_t fillLimit = 0) noexcept; - OutputCellIterator(const gsl::span legacyAttributes) noexcept; - OutputCellIterator(const gsl::span charInfos) noexcept; - OutputCellIterator(const gsl::span cells); + OutputCellIterator(const std::span legacyAttributes) noexcept; + OutputCellIterator(const std::span charInfos) noexcept; + OutputCellIterator(const std::span cells); ~OutputCellIterator() = default; OutputCellIterator& operator=(const OutputCellIterator& it) = default; @@ -86,13 +86,13 @@ class OutputCellIterator final }; Mode _mode; - gsl::span _legacyAttrs; + std::span _legacyAttrs; std::variant< std::wstring_view, - gsl::span, - gsl::span, - gsl::span, + std::span, + std::span, + std::span, std::monostate> _run; diff --git a/src/buffer/out/OutputCellRect.cpp b/src/buffer/out/OutputCellRect.cpp index 6b789298d3a..18ea859568a 100644 --- a/src/buffer/out/OutputCellRect.cpp +++ b/src/buffer/out/OutputCellRect.cpp @@ -34,9 +34,9 @@ OutputCellRect::OutputCellRect(const til::CoordType rows, const til::CoordType c // - row - The Y position or row index in the buffer. // Return Value: // - Read/write span of OutputCells -gsl::span OutputCellRect::GetRow(const til::CoordType row) +std::span OutputCellRect::GetRow(const til::CoordType row) { - return gsl::span(_FindRowOffset(row), _cols); + return std::span(_FindRowOffset(row), _cols); } // Routine Description: @@ -47,7 +47,7 @@ gsl::span OutputCellRect::GetRow(const til::CoordType row) // - Read-only iterator of OutputCells OutputCellIterator OutputCellRect::GetRowIter(const til::CoordType row) const { - const gsl::span view(_FindRowOffset(row), _cols); + const std::span view(_FindRowOffset(row), _cols); return OutputCellIterator(view); } diff --git a/src/buffer/out/OutputCellRect.hpp b/src/buffer/out/OutputCellRect.hpp index 4e5d38cf813..fd3fc080127 100644 --- a/src/buffer/out/OutputCellRect.hpp +++ b/src/buffer/out/OutputCellRect.hpp @@ -32,7 +32,7 @@ class OutputCellRect final OutputCellRect() noexcept; OutputCellRect(const til::CoordType rows, const til::CoordType cols); - gsl::span GetRow(const til::CoordType row); + std::span GetRow(const til::CoordType row); OutputCellIterator GetRowIter(const til::CoordType row) const; til::CoordType Height() const noexcept; diff --git a/src/cascadia/LocalTests_SettingsModel/ColorSchemeTests.cpp b/src/cascadia/LocalTests_SettingsModel/ColorSchemeTests.cpp index b266064977a..4789cfa7e93 100644 --- a/src/cascadia/LocalTests_SettingsModel/ColorSchemeTests.cpp +++ b/src/cascadia/LocalTests_SettingsModel/ColorSchemeTests.cpp @@ -79,7 +79,7 @@ namespace SettingsModelLocalTests VERIFY_ARE_EQUAL(til::color(0xFF, 0xFF, 0xFF, 255), til::color{ scheme->CursorColor() }); std::array expectedCampbellTable; - const auto campbellSpan = gsl::make_span(expectedCampbellTable); + const auto campbellSpan = std::span{ expectedCampbellTable }; Utils::InitializeColorTable(campbellSpan); for (size_t i = 0; i < expectedCampbellTable.size(); i++) diff --git a/src/cascadia/TerminalApp/AppLogic.cpp b/src/cascadia/TerminalApp/AppLogic.cpp index 2717cec205d..3b1a1c0e33a 100644 --- a/src/cascadia/TerminalApp/AppLogic.cpp +++ b/src/cascadia/TerminalApp/AppLogic.cpp @@ -684,6 +684,7 @@ namespace winrt::TerminalApp::implementation { return _settings.GlobalSettings().ShouldUsePersistedLayout(); } + void AppLogic::SaveWindowLayoutJsons(const Windows::Foundation::Collections::IVector& layouts) { std::vector converted; @@ -704,6 +705,6 @@ namespace winrt::TerminalApp::implementation { ::TerminalApp::AppCommandlineArgs _appArgs; const auto r = _appArgs.ParseArgs(args); - return TerminalApp::ParseCommandlineResult{ winrt::to_hstring(_appArgs.GetExitMessage()), r}; + return TerminalApp::ParseCommandlineResult{ winrt::to_hstring(_appArgs.GetExitMessage()), r }; } } diff --git a/src/cascadia/TerminalApp/TabManagement.cpp b/src/cascadia/TerminalApp/TabManagement.cpp index 0b4c54d1e6f..f1134efbd36 100644 --- a/src/cascadia/TerminalApp/TabManagement.cpp +++ b/src/cascadia/TerminalApp/TabManagement.cpp @@ -1102,6 +1102,13 @@ namespace winrt::TerminalApp::implementation } _rearranging = false; + + if (to.has_value()) + { + // Selecting the dropped tab + TabRow().TabView().SelectedIndex(to.value()); + } + from = std::nullopt; to = std::nullopt; } diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index d473669d0a2..575479aa978 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -307,7 +307,7 @@ namespace winrt::TerminalApp::implementation // GH#12267: Don't forget about defterm handoff here. If we're being // created for embedding, then _yea_, we don't need to handoff to an // elevated window. - if (!_startupActions || IsElevated() || _shouldStartInboundListener) + if (!_startupActions || IsElevated() || _shouldStartInboundListener || _startupActions.Size() == 0) { // there aren't startup actions, or we're elevated. In that case, go for it. return false; @@ -1171,10 +1171,17 @@ namespace winrt::TerminalApp::implementation if (connectionType == TerminalConnection::AzureConnection::ConnectionType() && TerminalConnection::AzureConnection::IsAzureConnectionAvailable()) { - // TODO GH#4661: Replace this with directly using the AzCon when our VT is better std::filesystem::path azBridgePath{ wil::GetModuleFileNameW(nullptr) }; azBridgePath.replace_filename(L"TerminalAzBridge.exe"); - connection = TerminalConnection::ConptyConnection(); + if constexpr (Feature_AzureConnectionInProc::IsEnabled()) + { + connection = TerminalConnection::AzureConnection{}; + } + else + { + connection = TerminalConnection::ConptyConnection{}; + } + auto valueSet = TerminalConnection::ConptyConnection::CreateSettings(azBridgePath.wstring(), L".", L"Azure", @@ -4263,5 +4270,4 @@ namespace winrt::TerminalApp::implementation } } } - } diff --git a/src/cascadia/TerminalApp/TerminalPage.idl b/src/cascadia/TerminalApp/TerminalPage.idl index 38ab490162e..494b61506bf 100644 --- a/src/cascadia/TerminalApp/TerminalPage.idl +++ b/src/cascadia/TerminalApp/TerminalPage.idl @@ -19,8 +19,13 @@ namespace TerminalApp interface IWindowProperties { +<<<<<<< HEAD String WindowName; UInt64 WindowId; +======= + String WindowName { get; }; + UInt64 WindowId { get; }; +>>>>>>> dev/migrie/oop/3/foreword String WindowNameForDisplay { get; }; String WindowIdForDisplay { get; }; Boolean IsQuakeWindow(); @@ -38,8 +43,10 @@ namespace TerminalApp Boolean Fullscreen { get; }; Boolean AlwaysOnTop { get; }; + IWindowProperties WindowProperties { get; }; void IdentifyWindow(); void RenameFailed(); + IWindowProperties WindowProperties { get; }; // We cannot use the default XAML APIs because we want to make sure diff --git a/src/cascadia/TerminalApp/TerminalWindow.cpp b/src/cascadia/TerminalApp/TerminalWindow.cpp index d5554082952..eec45606d17 100644 --- a/src/cascadia/TerminalApp/TerminalWindow.cpp +++ b/src/cascadia/TerminalApp/TerminalWindow.cpp @@ -624,7 +624,7 @@ namespace winrt::TerminalApp::implementation // reserve exactly what we'd need. // // We can't do that anymore, because this is now called _before_ - // we've initilized XAML for this thread. We can't start XAML till + // we've initialized XAML for this thread. We can't start XAML till // we have an HWND, and we can't finish creating the window till we // know how big it should be. // @@ -763,6 +763,7 @@ namespace winrt::TerminalApp::implementation } _RefreshThemeRoutine(); } + void TerminalWindow::_OpenSettingsUI() { _root->OpenSettingsUI(); @@ -984,9 +985,8 @@ namespace winrt::TerminalApp::implementation // or 0. (see TerminalWindow::_ParseArgs) int32_t TerminalWindow::SetStartupCommandline(array_view args) { - // This is called in Apphost::ctor(), before we've created the window + // This is called in AppHost::ctor(), before we've created the window // (or called TerminalWindow::Initialize) - const auto result = _appArgs.ParseArgs(args); if (result == 0) { @@ -1150,22 +1150,18 @@ namespace winrt::TerminalApp::implementation } } - // WindowName is a otherwise generic WINRT_OBSERVABLE_PROPERTY, but it needs - // to raise a PropertyChanged for WindowNameForDisplay, instead of - // WindowName. winrt::hstring TerminalWindow::WindowName() const noexcept { return _WindowName; } - - void TerminalWindow::WindowName(const winrt::hstring& value) + void TerminalWindow::WindowName(const winrt::hstring& name) { const auto oldIsQuakeMode = IsQuakeWindow(); - const auto changed = _WindowName != value; + const auto changed = _WindowName != name; if (changed) { - _WindowName = value; + _WindowName = name; if (_root) { _root->WindowNameChanged(); @@ -1182,19 +1178,15 @@ namespace winrt::TerminalApp::implementation } } } - - // WindowId is a otherwise generic WINRT_OBSERVABLE_PROPERTY, but it needs - // to raise a PropertyChanged for WindowIdForDisplay, instead of - // WindowId. uint64_t TerminalWindow::WindowId() const noexcept { return _WindowId; } - void TerminalWindow::WindowId(const uint64_t& value) + void TerminalWindow::WindowId(const uint64_t& id) { - if (_WindowId != value) + if (_WindowId != id) { - _WindowId = value; + _WindowId = id; if (_root) { _root->WindowNameChanged(); @@ -1227,12 +1219,10 @@ namespace winrt::TerminalApp::implementation winrt::hstring{ fmt::format(L"<{}>", RS_(L"UnnamedWindowName")) } : _WindowName; } - bool TerminalWindow::IsQuakeWindow() const noexcept { - return WindowName() == QuakeWindowName; + return _WindowName == QuakeWindowName; } - //////////////////////////////////////////////////////////////////////////// bool TerminalWindow::ShouldImmediatelyHandoffToElevated() @@ -1265,5 +1255,4 @@ namespace winrt::TerminalApp::implementation } } - //////////////////////////////////////////////////////////////////////////// }; diff --git a/src/cascadia/TerminalApp/TerminalWindow.h b/src/cascadia/TerminalApp/TerminalWindow.h index 719d87814ce..c627b1ec83b 100644 --- a/src/cascadia/TerminalApp/TerminalWindow.h +++ b/src/cascadia/TerminalApp/TerminalWindow.h @@ -6,6 +6,7 @@ #include "TerminalWindow.g.h" #include "SystemMenuChangeArgs.g.h" +#include "SettingsLoadEventArgs.h" #include "TerminalPage.h" #include "SettingsLoadEventArgs.h" @@ -73,6 +74,7 @@ namespace winrt::TerminalApp::implementation std::optional LoadPersistedLayoutIdx() const; winrt::Microsoft::Terminal::Settings::Model::WindowLayout LoadPersistedLayout() const; + void SetPersistedLayoutIdx(const uint32_t idx); void SetNumberOfOpenWindows(const uint64_t num); bool ShouldUsePersistedLayout() const; diff --git a/src/cascadia/TerminalApp/TerminalWindow.idl b/src/cascadia/TerminalApp/TerminalWindow.idl index ff23cb76dbe..f6297482356 100644 --- a/src/cascadia/TerminalApp/TerminalWindow.idl +++ b/src/cascadia/TerminalApp/TerminalWindow.idl @@ -107,9 +107,13 @@ namespace TerminalApp Boolean RequestsTrayIcon(); Boolean GetShowTitleInTitlebar(); + // These already have accessort as a part of IWindowProperties, but we + // also want to be able to set them. + String WindowName { set; }; + UInt64 WindowId { set; }; + // See IDialogPresenter and TerminalPage's DialogPresenter for more // information. - Windows.Foundation.IAsyncOperation ShowDialog(Windows.UI.Xaml.Controls.ContentDialog dialog); void DismissDialog(); event Windows.Foundation.TypedEventHandler SetTitleBarContent; @@ -133,5 +137,6 @@ namespace TerminalApp event Windows.Foundation.TypedEventHandler ShowWindowChanged; event Windows.Foundation.TypedEventHandler SettingsChanged; + } } diff --git a/src/cascadia/TerminalConnection/AzureClient.h b/src/cascadia/TerminalConnection/AzureClient.h index a0362125559..f8ca9c08235 100644 --- a/src/cascadia/TerminalConnection/AzureClient.h +++ b/src/cascadia/TerminalConnection/AzureClient.h @@ -3,8 +3,6 @@ #pragma once -#include "cpprest/json.h" - namespace Microsoft::Terminal::Azure { class AzureException : public std::runtime_error @@ -12,14 +10,24 @@ namespace Microsoft::Terminal::Azure std::wstring _code; public: - static bool IsErrorPayload(const web::json::value& errorObject) + static bool IsErrorPayload(const winrt::Windows::Data::Json::JsonObject& errorObject) { - return errorObject.has_string_field(L"error"); + if (!errorObject.HasKey(L"error")) + { + return false; + } + + if (errorObject.GetNamedValue(L"error").ValueType() != winrt::Windows::Data::Json::JsonValueType::String) + { + return false; + } + + return true; } - AzureException(const web::json::value& errorObject) : - runtime_error(til::u16u8(errorObject.at(L"error_description").as_string())), // surface the human-readable description as .what() - _code(errorObject.at(L"error").as_string()) + AzureException(const winrt::Windows::Data::Json::JsonObject& errorObject) : + runtime_error(til::u16u8(errorObject.GetNamedString(L"error_description"))), // surface the human-readable description as .what() + _code(errorObject.GetNamedString(L"error")) { } diff --git a/src/cascadia/TerminalConnection/AzureConnection.cpp b/src/cascadia/TerminalConnection/AzureConnection.cpp index f04e08bd74b..3844979b488 100644 --- a/src/cascadia/TerminalConnection/AzureConnection.cpp +++ b/src/cascadia/TerminalConnection/AzureConnection.cpp @@ -15,22 +15,24 @@ #include "winrt/Windows.System.UserProfile.h" #include "../../types/inc/Utils.hpp" +#include "winrt/Windows.Web.Http.Filters.h" + using namespace ::Microsoft::Console; using namespace ::Microsoft::Terminal::Azure; - -using namespace web; -using namespace web::http; -using namespace web::http::client; -using namespace web::websockets::client; using namespace winrt::Windows::Security::Credentials; -static constexpr int CurrentCredentialVersion = 1; -static constexpr auto PasswordVaultResourceName = L"Terminal"; -static constexpr auto HttpUserAgent = L"Terminal/0.0"; +static constexpr int CurrentCredentialVersion = 2; +static constexpr std::wstring_view PasswordVaultResourceName = L"Terminal"; +static constexpr std::wstring_view HttpUserAgent = L"Mozilla/5.0 (Windows NT 10.0) Terminal/1.0"; static constexpr int USER_INPUT_COLOR = 93; // yellow - the color of something the user can type static constexpr int USER_INFO_COLOR = 97; // white - the color of clarifying information +using namespace winrt::Windows::Foundation; +namespace WDJ = ::winrt::Windows::Data::Json; +namespace WSS = ::winrt::Windows::Storage::Streams; +namespace WWH = ::winrt::Windows::Web::Http; + static constexpr winrt::guid AzureConnectionType = { 0xd9fcfdfa, 0xa479, 0x412c, { 0x83, 0xb7, 0xc5, 0x64, 0xe, 0x61, 0xcd, 0x62 } }; static inline std::wstring _colorize(const unsigned int colorCode, const std::wstring_view text) @@ -115,6 +117,8 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation // - creates the output thread (where we will do the authentication and actually connect to Azure) void AzureConnection::Start() { + _httpClient = winrt::Windows::Web::Http::HttpClient{}; + _httpClient.DefaultRequestHeaders().UserAgent().TryParseAdd(HttpUserAgent); // Create our own output handling thread // Each connection needs to make sure to drain the output from its backing host. _hOutputThread.reset(CreateThread( @@ -126,7 +130,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation { return pInstance->_OutputThread(); } - return gsl::narrow_cast(E_INVALIDARG); + return gsl::narrow(E_INVALIDARG); }, this, 0, @@ -183,12 +187,8 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation if (_state == AzureState::TermConnected) { - // If we're connected, we don't need to do any fun input shenanigans. - websocket_outgoing_message msg; - const auto str = winrt::to_string(data); - msg.set_utf8_message(str); - - _cloudShellSocket.send(msg).get(); + auto buff{ winrt::to_string(data) }; + WinHttpWebSocketSend(_webSocket.get(), WINHTTP_WEB_SOCKET_UTF8_MESSAGE_BUFFER_TYPE, buff.data(), gsl::narrow(buff.size())); return; } @@ -238,16 +238,17 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation } else // We only transition to Connected when we've established the websocket. { - // Initialize client - http_client terminalClient(_cloudShellUri); + auto uri{ fmt::format(L"{}terminals/{}/size?cols={}&rows={}&version=2019-01-01", _cloudShellUri, _terminalID, columns, rows) }; - // Initialize the request - http_request terminalRequest(L"POST"); - terminalRequest.set_request_uri(fmt::format(L"terminals/{}/size?cols={}&rows={}&version=2019-01-01", _terminalID, columns, rows)); - terminalRequest.set_body(json::value::null()); + WWH::HttpStringContent content{ + L"", + WSS::UnicodeEncoding::Utf8, + // LOAD-BEARING. the API returns "'content-type' should be 'application/json' or 'multipart/form-data'" + L"application/json" + }; // Send the request (don't care about the response) - (void)_SendAuthenticatedRequestReturningJson(terminalClient, terminalRequest); + std::ignore = _SendRequestReturningJson(uri, content); } } CATCH_LOG(); @@ -264,7 +265,10 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation if (_state == AzureState::TermConnected) { // Close the websocket connection - _cloudShellSocket.close(); + std::ignore = WinHttpWebSocketClose(_webSocket.get(), WINHTTP_WEB_SOCKET_SUCCESS_CLOSE_STATUS, nullptr, 0); // throw away the error + _webSocket.reset(); + _socketConnectionHandle.reset(); + _socketSessionHandle.reset(); } if (_hOutputThread) @@ -287,44 +291,46 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation // - tenant - the unparsed tenant // Return value: // - a tuple containing the ID and display name of the tenant. - static Tenant _crackTenant(const json::value& jsonTenant) + static Tenant _crackTenant(const WDJ::IJsonValue& value) { + auto jsonTenant{ value.GetObjectW() }; + Tenant tenant{}; - if (jsonTenant.has_string_field(L"tenantID")) + if (jsonTenant.HasKey(L"tenantID")) { // for compatibility with version 1 credentials - tenant.ID = jsonTenant.at(L"tenantID").as_string(); + tenant.ID = jsonTenant.GetNamedString(L"tenantID"); } else { // This one comes in off the wire - tenant.ID = jsonTenant.at(L"tenantId").as_string(); + tenant.ID = jsonTenant.GetNamedString(L"tenantId"); } - if (jsonTenant.has_string_field(L"displayName")) + if (jsonTenant.HasKey(L"displayName")) { - tenant.DisplayName = jsonTenant.at(L"displayName").as_string(); + tenant.DisplayName = jsonTenant.GetNamedString(L"displayName"); } - if (jsonTenant.has_string_field(L"defaultDomain")) + if (jsonTenant.HasKey(L"defaultDomain")) { - tenant.DefaultDomain = jsonTenant.at(L"defaultDomain").as_string(); + tenant.DefaultDomain = jsonTenant.GetNamedString(L"defaultDomain"); } return tenant; } - static void _packTenant(json::value& jsonTenant, const Tenant& tenant) + static void _packTenant(const WDJ::JsonObject& jsonTenant, const Tenant& tenant) { - jsonTenant[L"tenantId"] = json::value::string(tenant.ID); + jsonTenant.SetNamedValue(L"tenantId", WDJ::JsonValue::CreateStringValue(tenant.ID)); if (tenant.DisplayName.has_value()) { - jsonTenant[L"displayName"] = json::value::string(*tenant.DisplayName); + jsonTenant.SetNamedValue(L"displayName", WDJ::JsonValue::CreateStringValue(*tenant.DisplayName)); } if (tenant.DefaultDomain.has_value()) { - jsonTenant[L"defaultDomain"] = json::value::string(*tenant.DefaultDomain); + jsonTenant.SetNamedValue(L"defaultDomain", WDJ::JsonValue::CreateStringValue(*tenant.DefaultDomain)); } } @@ -383,35 +389,42 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation case AzureState::TermConnected: { _transitionToState(ConnectionState::Connected); + while (true) { - // Read from websocket - pplx::task msgT; - try + WINHTTP_WEB_SOCKET_BUFFER_TYPE bufferType{}; + DWORD read{}; + THROW_IF_WIN32_ERROR(WinHttpWebSocketReceive(_webSocket.get(), _buffer.data(), gsl::narrow(_buffer.size()), &read, &bufferType)); + + switch (bufferType) { - msgT = _cloudShellSocket.receive(); - msgT.wait(); - } - catch (...) + case WINHTTP_WEB_SOCKET_UTF8_FRAGMENT_BUFFER_TYPE: + case WINHTTP_WEB_SOCKET_UTF8_MESSAGE_BUFFER_TYPE: { - // Websocket has been closed; consider it a graceful exit? - // This should result in our termination. + const auto result{ til::u8u16(std::string_view{ _buffer.data(), read }, _u16Str, _u8State) }; + if (FAILED(result)) + { + // EXIT POINT + _transitionToState(ConnectionState::Failed); + return gsl::narrow(result); + } + + if (_u16Str.empty()) + { + continue; + } + + // Pass the output to our registered event handlers + _TerminalOutputHandlers(_u16Str); + break; + } + case WINHTTP_WEB_SOCKET_CLOSE_BUFFER_TYPE: + // EXIT POINT if (_transitionToState(ConnectionState::Closed)) { - // End the output thread. return S_FALSE; } } - - auto msg = msgT.get(); - auto msgStringTask = msg.extract_string(); - auto msgString = msgStringTask.get(); - - // Convert to hstring - const auto hstr = winrt::to_hstring(msgString); - - // Pass the output to our registered event handlers - _TerminalOutputHandlers(hstr); } return S_OK; } @@ -449,25 +462,29 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation _tenantList.clear(); for (const auto& entry : credList) { - auto nameJson = json::value::parse(entry.UserName().c_str()); - std::optional credentialVersion; - if (nameJson.has_integer_field(U("ver"))) + try { - credentialVersion = nameJson.at(U("ver")).as_integer(); - } + auto nameJson = WDJ::JsonObject::Parse(entry.UserName()); + std::optional credentialVersion; + if (nameJson.HasKey(L"ver")) + { + credentialVersion = static_cast(nameJson.GetNamedNumber(L"ver")); + } - if (!credentialVersion.has_value() || credentialVersion.value() != CurrentCredentialVersion) - { - // ignore credentials that aren't from the latest credential revision - vault.Remove(entry); - oldVersionEncountered = true; - continue; - } + if (!credentialVersion.has_value() || credentialVersion.value() != CurrentCredentialVersion) + { + // ignore credentials that aren't from the latest credential revision + vault.Remove(entry); + oldVersionEncountered = true; + continue; + } - auto newTenant{ _tenantList.emplace_back(_crackTenant(nameJson)) }; + auto newTenant{ _tenantList.emplace_back(_crackTenant(nameJson)) }; - _WriteStringWithNewline(_formatTenant(numTenants, newTenant)); - numTenants++; + _WriteStringWithNewline(_formatTenant(numTenants, newTenant)); + numTenants++; + } + CATCH_LOG(); } if (!numTenants) @@ -533,11 +550,11 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation // User wants to login with one of the saved connection settings auto desiredCredential = credList.GetAt(selectedTenant); desiredCredential.RetrievePassword(); - auto passWordJson = json::value::parse(desiredCredential.Password().c_str()); + auto passWordJson = WDJ::JsonObject::Parse(desiredCredential.Password()); _currentTenant = til::at(_tenantList, selectedTenant); // we already unpacked the name info, so we should just use it - _accessToken = passWordJson.at(L"accessToken").as_string(); - _refreshToken = passWordJson.at(L"refreshToken").as_string(); - _expiry = std::stoi(passWordJson.at(L"expiry").as_string()); + _setAccessToken(passWordJson.GetNamedString(L"accessToken")); + _refreshToken = passWordJson.GetNamedString(L"refreshToken"); + _expiry = std::stoi(winrt::to_string(passWordJson.GetNamedString(L"expiry"))); const auto t1 = std::chrono::system_clock::now(); const auto timeNow = std::chrono::duration_cast(t1.time_since_epoch()).count(); @@ -577,17 +594,17 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation const auto deviceCodeResponse = _GetDeviceCode(); // Print the message and store the device code, polling interval and expiry - const auto message = winrt::to_hstring(deviceCodeResponse.at(L"message").as_string().c_str()); + const auto message{ deviceCodeResponse.GetNamedString(L"message") }; _WriteStringWithNewline(message); _WriteStringWithNewline(RS_(L"AzureCodeExpiry")); - const auto devCode = deviceCodeResponse.at(L"device_code").as_string(); - const auto pollInterval = std::stoi(deviceCodeResponse.at(L"interval").as_string()); - const auto expiresIn = std::stoi(deviceCodeResponse.at(L"expires_in").as_string()); + const auto devCode = deviceCodeResponse.GetNamedString(L"device_code"); + const auto pollInterval = std::stoi(winrt::to_string(deviceCodeResponse.GetNamedString(L"interval"))); + const auto expiresIn = std::stoi(winrt::to_string(deviceCodeResponse.GetNamedString(L"expires_in"))); // Wait for user authentication and obtain the access/refresh tokens auto authenticatedResponse = _WaitForUser(devCode, pollInterval, expiresIn); - _accessToken = authenticatedResponse.at(L"access_token").as_string(); - _refreshToken = authenticatedResponse.at(L"refresh_token").as_string(); + _setAccessToken(authenticatedResponse.GetNamedString(L"access_token")); + _refreshToken = authenticatedResponse.GetNamedString(L"refresh_token"); // Get the tenants and the required tenant id _PopulateTenantList(); @@ -696,19 +713,18 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation // - Helper function to parse the preferred shell type from user settings returned by cloud console API. // We need this function because the field might be missing in the settings // created with old versions of cloud console API. - std::optional AzureConnection::_ParsePreferredShellType(const web::json::value& settingsResponse) + winrt::hstring AzureConnection::_ParsePreferredShellType(const WDJ::JsonObject& settingsResponse) { - if (settingsResponse.has_object_field(L"properties")) + if (settingsResponse.HasKey(L"properties")) { - const auto userSettings = settingsResponse.at(L"properties"); - if (userSettings.has_string_field(L"preferredShellType")) + const auto userSettings = settingsResponse.GetNamedObject(L"properties"); + if (userSettings.HasKey(L"preferredShellType")) { - const auto preferredShellTypeValue = userSettings.at(L"preferredShellType"); - return preferredShellTypeValue.as_string(); + return userSettings.GetNamedString(L"preferredShellType"); } } - return std::nullopt; + return L"pwsh"; } // Method description: @@ -717,7 +733,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation { // Get user's cloud shell settings const auto settingsResponse = _GetCloudShellUserSettings(); - if (settingsResponse.has_field(L"error")) + if (settingsResponse.HasKey(L"error")) { _WriteStringWithNewline(RS_(L"AzureNoCloudAccount")); _transitionToState(ConnectionState::Failed); @@ -732,12 +748,36 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation // Request for a terminal for said cloud shell const auto shellType = _ParsePreferredShellType(settingsResponse); _WriteStringWithNewline(RS_(L"AzureRequestingTerminal")); - const auto socketUri = _GetTerminal(shellType.value_or(L"pwsh")); + const auto socketUri = _GetTerminal(shellType); _TerminalOutputHandlers(L"\r\n"); - // Step 8: connecting to said terminal - const auto connReqTask = _cloudShellSocket.connect(socketUri); - connReqTask.wait(); + //// Step 8: connecting to said terminal + { + wil::unique_winhttp_hinternet sessionHandle, connectionHandle, requestHandle, socketHandle; + Uri parsedUri{ socketUri }; + sessionHandle.reset(WinHttpOpen(HttpUserAgent.data(), WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY, nullptr, nullptr, 0)); + THROW_LAST_ERROR_IF(!sessionHandle); + + connectionHandle.reset(WinHttpConnect(sessionHandle.get(), parsedUri.Host().c_str(), INTERNET_DEFAULT_HTTPS_PORT, 0)); + THROW_LAST_ERROR_IF(!connectionHandle); + + requestHandle.reset(WinHttpOpenRequest(connectionHandle.get(), L"GET", parsedUri.Path().c_str(), nullptr, nullptr, nullptr, WINHTTP_FLAG_SECURE)); + THROW_LAST_ERROR_IF(!requestHandle); + + THROW_IF_WIN32_BOOL_FALSE(WinHttpSetOption(requestHandle.get(), WINHTTP_OPTION_UPGRADE_TO_WEB_SOCKET, nullptr, 0)); +#pragma warning(suppress : 26477) // WINHTTP_NO_ADDITIONAL_HEADERS expands to NULL rather than nullptr (who would have thought?) + THROW_IF_WIN32_BOOL_FALSE(WinHttpSendRequest(requestHandle.get(), WINHTTP_NO_ADDITIONAL_HEADERS, 0, nullptr, 0, 0, 0)); + THROW_IF_WIN32_BOOL_FALSE(WinHttpReceiveResponse(requestHandle.get(), nullptr)); + + socketHandle.reset(WinHttpWebSocketCompleteUpgrade(requestHandle.get(), 0)); + THROW_LAST_ERROR_IF(!socketHandle); + + requestHandle.reset(); // We no longer need the request once we've upgraded it. + // We have to keep the socket session and connection handles. + _socketSessionHandle = std::move(sessionHandle); + _socketConnectionHandle = std::move(connectionHandle); + _webSocket = std::move(socketHandle); + } _state = AzureState::TermConnected; @@ -752,58 +792,52 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation // Method description: // - helper function to send requests with default headers and extract responses as json values // Arguments: - // - a http_client - // - a http_request for the client to send + // - the URI + // - optional body content + // - an optional HTTP method (defaults to POST if content is present, GET otherwise) // Return value: // - the response from the server as a json value - json::value AzureConnection::_SendRequestReturningJson(http_client& theClient, http_request theRequest) + WDJ::JsonObject AzureConnection::_SendRequestReturningJson(std::wstring_view uri, const WWH::IHttpContent& content, WWH::HttpMethod method) { - auto& headers{ theRequest.headers() }; - headers.add(L"User-Agent", HttpUserAgent); - headers.add(L"Accept", L"application/json"); - - json::value jsonResult; - const auto responseTask = theClient.request(theRequest); - responseTask.wait(); - const auto response = responseTask.get(); - const auto responseJsonTask = response.extract_json(); - responseJsonTask.wait(); - jsonResult = responseJsonTask.get(); + if (!method) + { + method = content == nullptr ? WWH::HttpMethod::Get() : WWH::HttpMethod::Post(); + } + + WWH::HttpRequestMessage request{ method, Uri{ uri } }; + request.Content(content); + + auto headers{ request.Headers() }; + headers.Accept().TryParseAdd(L"application/json"); + + const auto response{ _httpClient.SendRequestAsync(request).get() }; + const auto string{ response.Content().ReadAsStringAsync().get() }; + const auto jsonResult{ WDJ::JsonObject::Parse(string) }; THROW_IF_AZURE_ERROR(jsonResult); return jsonResult; } - // Method description: - // - helper function to send _authenticated_ requests with json bodies whose responses are expected - // to be json. builds on _SendRequestReturningJson. - // Arguments: - // - the http_request - json::value AzureConnection::_SendAuthenticatedRequestReturningJson(http_client& theClient, http_request theRequest) + void AzureConnection::_setAccessToken(std::wstring_view accessToken) { - auto& headers{ theRequest.headers() }; - headers.add(L"Authorization", L"Bearer " + _accessToken); - - return _SendRequestReturningJson(theClient, std::move(theRequest)); + _accessToken = accessToken; + _httpClient.DefaultRequestHeaders().Authorization(WWH::Headers::HttpCredentialsHeaderValue{ L"Bearer", _accessToken }); } // Method description: // - helper function to start the device code flow // Return value: // - the response to the device code flow initiation - json::value AzureConnection::_GetDeviceCode() + WDJ::JsonObject AzureConnection::_GetDeviceCode() { - // Initialize the client - http_client loginClient(_loginUri); - - // Initialize the request - http_request commonRequest(L"POST"); - commonRequest.set_request_uri(L"common/oauth2/devicecode"); - const auto body{ fmt::format(L"client_id={}&resource={}", AzureClientID, _wantedResource) }; - commonRequest.set_body(body.c_str(), L"application/x-www-form-urlencoded"); - - // Send the request and receive the response as a json value - return _SendRequestReturningJson(loginClient, commonRequest); + auto uri{ fmt::format(L"{}common/oauth2/devicecode", _loginUri) }; + WWH::HttpFormUrlEncodedContent content{ + std::unordered_map{ + { winrt::hstring{ L"client_id" }, winrt::hstring{ AzureClientID } }, + { winrt::hstring{ L"resource" }, winrt::hstring{ _wantedResource } }, + } + }; + return _SendRequestReturningJson(uri, content); } // Method description: @@ -815,14 +849,17 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation // Return value: // - if authentication is done successfully, then return the response from the server // - else, throw an exception - json::value AzureConnection::_WaitForUser(const utility::string_t deviceCode, int pollInterval, int expiresIn) + WDJ::JsonObject AzureConnection::_WaitForUser(const winrt::hstring& deviceCode, int pollInterval, int expiresIn) { - // Initialize the client - http_client pollingClient(_loginUri); - - // Continuously send a poll request until the user authenticates - const auto body{ fmt::format(L"grant_type=device_code&resource={}&client_id={}&code={}", _wantedResource, AzureClientID, deviceCode) }; - const auto requestUri = L"common/oauth2/token"; + auto uri{ fmt::format(L"{}common/oauth2/token", _loginUri) }; + WWH::HttpFormUrlEncodedContent content{ + std::unordered_map{ + { winrt::hstring{ L"grant_type" }, winrt::hstring{ L"device_code" } }, + { winrt::hstring{ L"client_id" }, winrt::hstring{ AzureClientID } }, + { winrt::hstring{ L"resource" }, winrt::hstring{ _wantedResource } }, + { winrt::hstring{ L"code" }, deviceCode }, + } + }; // use a steady clock here so it's not impacted by local time discontinuities const auto tokenExpiry{ std::chrono::steady_clock::now() + std::chrono::seconds(expiresIn) }; @@ -837,14 +874,11 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation break; } - http_request pollRequest(L"POST"); - pollRequest.set_request_uri(requestUri); - pollRequest.set_body(body.c_str(), L"application/x-www-form-urlencoded"); - try { - auto response{ _SendRequestReturningJson(pollingClient, pollRequest) }; + auto response = _SendRequestReturningJson(uri, content); _WriteStringWithNewline(RS_(L"AzureSuccessfullyAuthenticated")); + // Got a valid response: we're done return response; } @@ -859,7 +893,7 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation } // uncaught exceptions bubble up to the caller } - return json::value::null(); + return nullptr; } // Method description: @@ -868,16 +902,11 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation // - the response which contains a list of the user's Azure tenants void AzureConnection::_PopulateTenantList() { - // Initialize the client - http_client tenantClient(_resourceUri); - - // Initialize the request - http_request tenantRequest(L"GET"); - tenantRequest.set_request_uri(L"tenants?api-version=2020-01-01"); + auto uri{ fmt::format(L"{}tenants?api-version=2020-01-01", _resourceUri) }; // Send the request and return the response as a json value - auto tenantResponse{ _SendAuthenticatedRequestReturningJson(tenantClient, tenantRequest) }; - auto tenantList{ tenantResponse.at(L"value").as_array() }; + auto tenantResponse{ _SendRequestReturningJson(uri, nullptr) }; + auto tenantList{ tenantResponse.GetNamedArray(L"value") }; _tenantList.clear(); std::transform(tenantList.begin(), tenantList.end(), std::back_inserter(_tenantList), _crackTenant); @@ -889,82 +918,73 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation // - the response with the new tokens void AzureConnection::_RefreshTokens() { - // Initialize the client - http_client refreshClient(_loginUri); - - // Initialize the request - http_request refreshRequest(L"POST"); - refreshRequest.set_request_uri(_currentTenant->ID + L"/oauth2/token"); - const auto body{ fmt::format(L"client_id={}&resource={}&grant_type=refresh_token&refresh_token={}", AzureClientID, _wantedResource, _refreshToken) }; - refreshRequest.set_body(body.c_str(), L"application/x-www-form-urlencoded"); + auto uri{ fmt::format(L"{}{}/oauth2/token", _loginUri, _currentTenant->ID) }; + WWH::HttpFormUrlEncodedContent content{ + std::unordered_map{ + { winrt::hstring{ L"grant_type" }, winrt::hstring{ L"refresh_token" } }, + { winrt::hstring{ L"client_id" }, winrt::hstring{ AzureClientID } }, + { winrt::hstring{ L"resource" }, winrt::hstring{ _wantedResource } }, + { winrt::hstring{ L"refresh_token" }, winrt::hstring{ _refreshToken } }, + } + }; // Send the request and return the response as a json value - auto refreshResponse{ _SendRequestReturningJson(refreshClient, refreshRequest) }; - _accessToken = refreshResponse.at(L"access_token").as_string(); - _refreshToken = refreshResponse.at(L"refresh_token").as_string(); - _expiry = std::stoi(refreshResponse.at(L"expires_on").as_string()); + auto refreshResponse{ _SendRequestReturningJson(uri, content) }; + _setAccessToken(refreshResponse.GetNamedString(L"access_token")); + _refreshToken = refreshResponse.GetNamedString(L"refresh_token"); + _expiry = std::stoi(winrt::to_string(refreshResponse.GetNamedString(L"expires_on"))); } // Method description: // - helper function to get the user's cloud shell settings // Return value: // - the user's cloud shell settings - json::value AzureConnection::_GetCloudShellUserSettings() + WDJ::JsonObject AzureConnection::_GetCloudShellUserSettings() { - // Initialize client - http_client settingsClient(_resourceUri); - - // Initialize request - http_request settingsRequest(L"GET"); - settingsRequest.set_request_uri(L"providers/Microsoft.Portal/userSettings/cloudconsole?api-version=2018-10-01"); - - return _SendAuthenticatedRequestReturningJson(settingsClient, settingsRequest); + auto uri{ fmt::format(L"{}providers/Microsoft.Portal/userSettings/cloudconsole?api-version=2020-04-01-preview", _resourceUri) }; + return _SendRequestReturningJson(uri, nullptr); } // Method description: // - helper function to request for a cloud shell // Return value: // - the uri for the cloud shell - utility::string_t AzureConnection::_GetCloudShell() + winrt::hstring AzureConnection::_GetCloudShell() { - // Initialize client - http_client cloudShellClient(_resourceUri); + auto uri{ fmt::format(L"{}providers/Microsoft.Portal/consoles/default?api-version=2020-04-01-preview", _resourceUri) }; - // Initialize request - http_request shellRequest(L"PUT"); - shellRequest.set_request_uri(L"providers/Microsoft.Portal/consoles/default?api-version=2018-10-01"); - // { "properties": { "osType": "linux" } } - auto body = json::value::object({ { U("properties"), json::value::object({ { U("osType"), json::value::string(U("linux")) } }) } }); - shellRequest.set_body(body); + WWH::HttpStringContent content{ + LR"-({"properties": {"osType": "linux"}})-", + WSS::UnicodeEncoding::Utf8, + L"application/json" + }; - // Send the request and get the response as a json value - const auto cloudShell = _SendAuthenticatedRequestReturningJson(cloudShellClient, shellRequest); + const auto cloudShell = _SendRequestReturningJson(uri, content, WWH::HttpMethod::Put()); // Return the uri - return cloudShell.at(L"properties").at(L"uri").as_string() + L"/"; + return winrt::hstring{ std::wstring{ cloudShell.GetNamedObject(L"properties").GetNamedString(L"uri") } + L"/" }; } // Method description: // - helper function to request for a terminal // Return value: // - the uri for the terminal - utility::string_t AzureConnection::_GetTerminal(utility::string_t shellType) + winrt::hstring AzureConnection::_GetTerminal(const winrt::hstring& shellType) { - // Initialize client - http_client terminalClient(_cloudShellUri); + auto uri{ fmt::format(L"{}terminals?cols={}&rows={}&version=2019-01-01&shell={}", _cloudShellUri, _initialCols, _initialRows, shellType) }; - // Initialize the request - http_request terminalRequest(L"POST"); - terminalRequest.set_request_uri(fmt::format(L"terminals?cols={}&rows={}&version=2019-01-01&shell={}", _initialCols, _initialRows, shellType)); - // LOAD-BEARING. the API returns "'content-type' should be 'application/json' or 'multipart/form-data'" - terminalRequest.set_body(json::value::null()); + WWH::HttpStringContent content{ + L"", + WSS::UnicodeEncoding::Utf8, + // LOAD-BEARING. the API returns "'content-type' should be 'application/json' or 'multipart/form-data'" + L"application/json" + }; - // Send the request and get the response as a json value - const auto terminalResponse = _SendAuthenticatedRequestReturningJson(terminalClient, terminalRequest); - _terminalID = terminalResponse.at(L"id").as_string(); + const auto terminalResponse = _SendRequestReturningJson(uri, content); + _terminalID = terminalResponse.GetNamedString(L"id"); // Return the uri - return terminalResponse.at(L"socketUri").as_string(); + return terminalResponse.GetNamedString(L"socketUri"); } // Method description: @@ -972,16 +992,17 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation // - we store the display name, tenant ID, access/refresh tokens, and token expiry void AzureConnection::_StoreCredential() { - json::value userName; - userName[U("ver")] = CurrentCredentialVersion; + WDJ::JsonObject userName; + userName.SetNamedValue(L"ver", WDJ::JsonValue::CreateNumberValue(CurrentCredentialVersion)); _packTenant(userName, *_currentTenant); - json::value passWord; - passWord[U("accessToken")] = json::value::string(_accessToken); - passWord[U("refreshToken")] = json::value::string(_refreshToken); - passWord[U("expiry")] = json::value::string(std::to_wstring(_expiry)); + + WDJ::JsonObject passWord; + passWord.SetNamedValue(L"accessToken", WDJ::JsonValue::CreateStringValue(_accessToken)); + passWord.SetNamedValue(L"refreshToken", WDJ::JsonValue::CreateStringValue(_refreshToken)); + passWord.SetNamedValue(L"expiry", WDJ::JsonValue::CreateStringValue(std::to_wstring(_expiry))); PasswordVault vault; - PasswordCredential newCredential{ PasswordVaultResourceName, userName.serialize(), passWord.serialize() }; + PasswordCredential newCredential{ PasswordVaultResourceName, userName.Stringify(), passWord.Stringify() }; vault.Add(newCredential); } diff --git a/src/cascadia/TerminalConnection/AzureConnection.h b/src/cascadia/TerminalConnection/AzureConnection.h index 22c62699ca9..cedd76757af 100644 --- a/src/cascadia/TerminalConnection/AzureConnection.h +++ b/src/cascadia/TerminalConnection/AzureConnection.h @@ -5,9 +5,6 @@ #include "AzureConnection.g.h" -#include -#include -#include #include #include @@ -56,30 +53,30 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation void _RunStoreState(); void _RunConnectState(); - const utility::string_t _loginUri{ U("https://login.microsoftonline.com/") }; - const utility::string_t _resourceUri{ U("https://management.azure.com/") }; - const utility::string_t _wantedResource{ U("https://management.core.windows.net/") }; + static constexpr std::wstring_view _loginUri{ L"https://login.microsoftonline.com/" }; + static constexpr std::wstring_view _resourceUri{ L"https://management.azure.com/" }; + static constexpr std::wstring_view _wantedResource{ L"https://management.core.windows.net/" }; const int _expireLimit{ 2700 }; - utility::string_t _accessToken; - utility::string_t _refreshToken; + winrt::hstring _accessToken; + winrt::hstring _refreshToken; int _expiry{ 0 }; - utility::string_t _cloudShellUri; - utility::string_t _terminalID; + winrt::hstring _cloudShellUri; + winrt::hstring _terminalID; std::vector<::Microsoft::Terminal::Azure::Tenant> _tenantList; std::optional<::Microsoft::Terminal::Azure::Tenant> _currentTenant; void _WriteStringWithNewline(const std::wstring_view str); void _WriteCaughtExceptionRecord(); - web::json::value _SendRequestReturningJson(web::http::client::http_client& theClient, web::http::http_request theRequest); - web::json::value _SendAuthenticatedRequestReturningJson(web::http::client::http_client& theClient, web::http::http_request theRequest); - web::json::value _GetDeviceCode(); - web::json::value _WaitForUser(utility::string_t deviceCode, int pollInterval, int expiresIn); + winrt::Windows::Data::Json::JsonObject _SendRequestReturningJson(std::wstring_view uri, const winrt::Windows::Web::Http::IHttpContent& content = nullptr, winrt::Windows::Web::Http::HttpMethod method = nullptr); + void _setAccessToken(std::wstring_view accessToken); + winrt::Windows::Data::Json::JsonObject _GetDeviceCode(); + winrt::Windows::Data::Json::JsonObject _WaitForUser(const winrt::hstring& deviceCode, int pollInterval, int expiresIn); void _PopulateTenantList(); void _RefreshTokens(); - web::json::value _GetCloudShellUserSettings(); - utility::string_t _GetCloudShell(); - utility::string_t _GetTerminal(utility::string_t shellType); + winrt::Windows::Data::Json::JsonObject _GetCloudShellUserSettings(); + winrt::hstring _GetCloudShell(); + winrt::hstring _GetTerminal(const winrt::hstring& shellType); void _StoreCredential(); void _RemoveCredentials(); @@ -95,9 +92,16 @@ namespace winrt::Microsoft::Terminal::TerminalConnection::implementation std::optional _ReadUserInput(InputMode mode); - web::websockets::client::websocket_client _cloudShellSocket; + winrt::Windows::Web::Http::HttpClient _httpClient{ nullptr }; + wil::unique_winhttp_hinternet _socketSessionHandle; + wil::unique_winhttp_hinternet _socketConnectionHandle; + wil::unique_winhttp_hinternet _webSocket; - static std::optional _ParsePreferredShellType(const web::json::value& settingsResponse); + til::u8state _u8State{}; + std::wstring _u16Str; + std::array _buffer{}; + + static winrt::hstring _ParsePreferredShellType(const winrt::Windows::Data::Json::JsonObject& settingsResponse); }; } diff --git a/src/cascadia/TerminalConnection/TerminalConnection.vcxproj b/src/cascadia/TerminalConnection/TerminalConnection.vcxproj index 5668399a404..3f7ee847294 100644 --- a/src/cascadia/TerminalConnection/TerminalConnection.vcxproj +++ b/src/cascadia/TerminalConnection/TerminalConnection.vcxproj @@ -11,7 +11,6 @@ true - true @@ -99,39 +98,4 @@ - - - - - - - - - diff --git a/src/cascadia/TerminalConnection/pch.h b/src/cascadia/TerminalConnection/pch.h index 847f8971bca..124397ca3b7 100644 --- a/src/cascadia/TerminalConnection/pch.h +++ b/src/cascadia/TerminalConnection/pch.h @@ -24,8 +24,14 @@ #include "winrt/Windows.Security.Credentials.h" #include "winrt/Windows.Foundation.Collections.h" +#include "winrt/Windows.Web.Http.h" +#include "winrt/Windows.Web.Http.Headers.h" +#include "winrt/Windows.Data.Json.h" #include +#include +#include + #include TRACELOGGING_DECLARE_PROVIDER(g_hTerminalConnectionProvider); #include diff --git a/src/cascadia/TerminalSettingsModel/CascadiaSettings.h b/src/cascadia/TerminalSettingsModel/CascadiaSettings.h index e0cf1e96202..bfd21ee3390 100644 --- a/src/cascadia/TerminalSettingsModel/CascadiaSettings.h +++ b/src/cascadia/TerminalSettingsModel/CascadiaSettings.h @@ -80,7 +80,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation static void _rethrowSerializationExceptionWithLocationInfo(const JsonUtils::DeserializationError& e, const std::string_view& settingsString); static Json::Value _parseJSON(const std::string_view& content); static const Json::Value& _getJSONValue(const Json::Value& json, const std::string_view& key) noexcept; - gsl::span> _getNonUserOriginProfiles() const; + std::span> _getNonUserOriginProfiles() const; void _parse(const OriginTag origin, const winrt::hstring& source, const std::string_view& content, ParsedSettings& settings); void _parseFragment(const winrt::hstring& source, const std::string_view& content, ParsedSettings& settings); static JsonSettings _parseJson(const std::string_view& content); diff --git a/src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp b/src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp index bc597926773..aaa3f63a66d 100644 --- a/src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp +++ b/src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp @@ -531,10 +531,10 @@ const Json::Value& SettingsLoader::_getJSONValue(const Json::Value& json, const // Thus no matter how many profiles are added later on, the following condition holds true: // The userSettings.profiles in the range [0, _userProfileCount) contain all profiles specified by the user. // In turn all profiles in the range [_userProfileCount, ∞) contain newly generated/added profiles. -// gsl::make_span(userSettings.profiles).subspan(_userProfileCount) gets us the latter range. -gsl::span> SettingsLoader::_getNonUserOriginProfiles() const +// std::span{ userSettings.profiles }.subspan(_userProfileCount) gets us the latter range. +std::span> SettingsLoader::_getNonUserOriginProfiles() const { - return gsl::make_span(userSettings.profiles).subspan(_userProfileCount); + return std::span{ userSettings.profiles }.subspan(_userProfileCount); } // Parses the given JSON string ("content") and fills a ParsedSettings instance with it. @@ -791,7 +791,7 @@ void SettingsLoader::_executeGenerator(const IDynamicProfileGenerator& generator { const winrt::hstring source{ generatorNamespace }; - for (const auto& profile : gsl::span(inboxSettings.profiles).subspan(previousSize)) + for (const auto& profile : std::span(inboxSettings.profiles).subspan(previousSize)) { profile->Origin(OriginTag::Generated); profile->Source(source); @@ -954,9 +954,9 @@ void CascadiaSettings::_researchOnLoad() // dark: 2 // a custom theme: 3 const auto themeChoice = themeInUse == L"system" ? 0 : - themeInUse == L"light" ? 1 : - themeInUse == L"dark" ? 2 : - 3; + themeInUse == L"light" ? 1 : + themeInUse == L"dark" ? 2 : + 3; TraceLoggingWrite( g_hSettingsModelProvider, diff --git a/src/cascadia/TerminalSettingsModel/DynamicProfileUtils.cpp b/src/cascadia/TerminalSettingsModel/DynamicProfileUtils.cpp index 57f2e49f61f..0df405a5a14 100644 --- a/src/cascadia/TerminalSettingsModel/DynamicProfileUtils.cpp +++ b/src/cascadia/TerminalSettingsModel/DynamicProfileUtils.cpp @@ -17,7 +17,7 @@ static constexpr std::wstring_view PACKAGED_PROFILE_ICON_EXTENSION{ L".png" }; // - A Profile, ready to be filled in winrt::com_ptr CreateDynamicProfile(const std::wstring_view& name) { - const auto profileGuid = Microsoft::Console::Utils::CreateV5Uuid(TERMINAL_PROFILE_NAMESPACE_GUID, gsl::as_bytes(gsl::make_span(name))); + const auto profileGuid = Microsoft::Console::Utils::CreateV5Uuid(TERMINAL_PROFILE_NAMESPACE_GUID, std::as_bytes(std::span{ name })); std::wstring iconPath{ PACKAGED_PROFILE_ICON_PATH }; iconPath.append(Microsoft::Console::Utils::GuidToString(profileGuid)); diff --git a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.h b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.h index b14134167ee..e3bb9e0cd19 100644 --- a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.h +++ b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.h @@ -62,6 +62,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation Windows::Foundation::Collections::IMapView Themes() noexcept; void AddTheme(const Model::Theme& theme); Model::Theme CurrentTheme() noexcept; + bool ShouldUsePersistedLayout() const; bool ShouldUsePersistedLayout() const; diff --git a/src/cascadia/TerminalSettingsModel/Profile.cpp b/src/cascadia/TerminalSettingsModel/Profile.cpp index 9db6741703e..ee33e57daea 100644 --- a/src/cascadia/TerminalSettingsModel/Profile.cpp +++ b/src/cascadia/TerminalSettingsModel/Profile.cpp @@ -283,12 +283,12 @@ winrt::guid Profile::_GenerateGuidForProfile(const std::wstring_view& name, cons // our source to build the namespace guid, instead of using the default GUID. const auto namespaceGuid = !source.empty() ? - Utils::CreateV5Uuid(RUNTIME_GENERATED_PROFILE_NAMESPACE_GUID, gsl::as_bytes(gsl::make_span(source))) : + Utils::CreateV5Uuid(RUNTIME_GENERATED_PROFILE_NAMESPACE_GUID, std::as_bytes(std::span{ source })) : RUNTIME_GENERATED_PROFILE_NAMESPACE_GUID; // Always use the name to generate the temporary GUID. That way, across // reloads, we'll generate the same static GUID. - return { Utils::CreateV5Uuid(namespaceGuid, gsl::as_bytes(gsl::make_span(name))) }; + return { Utils::CreateV5Uuid(namespaceGuid, std::as_bytes(std::span{ name })) }; } // Method Description: diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp index ce281f5e2c2..ce6076e7cea 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp @@ -395,11 +395,11 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation return colorTable; } - gsl::span TerminalSettings::_getColorTableImpl() + std::span TerminalSettings::_getColorTableImpl() { if (_ColorTable.has_value()) { - return gsl::make_span(*_ColorTable); + return std::span{ *_ColorTable }; } for (auto&& parent : _parents) { diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.h b/src/cascadia/TerminalSettingsModel/TerminalSettings.h index e92ce3aeed9..08ea820fd2e 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.h +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.h @@ -163,7 +163,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation private: std::optional> _ColorTable; - gsl::span _getColorTableImpl(); + std::span _getColorTableImpl(); static winrt::com_ptr _CreateWithProfileCommon(const Model::CascadiaSettings& appSettings, const Model::Profile& profile); void _ApplyProfileSettings(const Model::Profile& profile); diff --git a/src/cascadia/TerminalSettingsModel/VsDevCmdGenerator.cpp b/src/cascadia/TerminalSettingsModel/VsDevCmdGenerator.cpp index e00f9f3841f..2b3f04e277d 100644 --- a/src/cascadia/TerminalSettingsModel/VsDevCmdGenerator.cpp +++ b/src/cascadia/TerminalSettingsModel/VsDevCmdGenerator.cpp @@ -17,7 +17,7 @@ void VsDevCmdGenerator::GenerateProfiles(const VsSetupConfiguration::VsSetupInst } const auto seed = GetProfileGuidSeed(instance); - const winrt::guid profileGuid{ ::Microsoft::Console::Utils::CreateV5Uuid(TERMINAL_PROFILE_NAMESPACE_GUID, gsl::as_bytes(gsl::make_span(seed))) }; + const winrt::guid profileGuid{ ::Microsoft::Console::Utils::CreateV5Uuid(TERMINAL_PROFILE_NAMESPACE_GUID, std::as_bytes(std::span{ seed })) }; auto profile = winrt::make_self(profileGuid); profile->Name(winrt::hstring{ GetProfileName(instance) }); profile->Commandline(winrt::hstring{ GetProfileCommandLine(instance) }); diff --git a/src/cascadia/TerminalSettingsModel/VsDevShellGenerator.cpp b/src/cascadia/TerminalSettingsModel/VsDevShellGenerator.cpp index a1b4ac67a1a..22c17cd98ab 100644 --- a/src/cascadia/TerminalSettingsModel/VsDevShellGenerator.cpp +++ b/src/cascadia/TerminalSettingsModel/VsDevShellGenerator.cpp @@ -18,7 +18,7 @@ void VsDevShellGenerator::GenerateProfiles(const VsSetupConfiguration::VsSetupIn } const auto seed = GetProfileGuidSeed(instance); - const winrt::guid profileGuid{ ::Microsoft::Console::Utils::CreateV5Uuid(TERMINAL_PROFILE_NAMESPACE_GUID, gsl::as_bytes(gsl::make_span(seed))) }; + const winrt::guid profileGuid{ ::Microsoft::Console::Utils::CreateV5Uuid(TERMINAL_PROFILE_NAMESPACE_GUID, std::as_bytes(std::span{ seed })) }; auto profile = winrt::make_self(profileGuid); profile->Name(winrt::hstring{ GetProfileName(instance) }); profile->Commandline(winrt::hstring{ GetProfileCommandLine(instance) }); diff --git a/src/cascadia/UnitTests_TerminalCore/ScrollTest.cpp b/src/cascadia/UnitTests_TerminalCore/ScrollTest.cpp index 04220b8b1d5..7a30714f42e 100644 --- a/src/cascadia/UnitTests_TerminalCore/ScrollTest.cpp +++ b/src/cascadia/UnitTests_TerminalCore/ScrollTest.cpp @@ -56,7 +56,7 @@ namespace HRESULT InvalidateAll() noexcept { return S_OK; } HRESULT InvalidateCircling(_Out_ bool* /*pForcePaint*/) noexcept { return S_OK; } HRESULT PaintBackground() noexcept { return S_OK; } - HRESULT PaintBufferLine(gsl::span /*clusters*/, til::point /*coord*/, bool /*fTrimLeft*/, bool /*lineWrapped*/) noexcept { return S_OK; } + HRESULT PaintBufferLine(std::span /*clusters*/, til::point /*coord*/, bool /*fTrimLeft*/, bool /*lineWrapped*/) noexcept { return S_OK; } HRESULT PaintBufferGridLines(GridLineSet /*lines*/, COLORREF /*color*/, size_t /*cchLine*/, til::point /*coordTarget*/) noexcept { return S_OK; } HRESULT PaintSelection(const til::rect& /*rect*/) noexcept { return S_OK; } HRESULT PaintCursor(const CursorOptions& /*options*/) noexcept { return S_OK; } @@ -65,7 +65,7 @@ namespace HRESULT UpdateDpi(int /*iDpi*/) noexcept { return S_OK; } HRESULT UpdateViewport(const til::inclusive_rect& /*srNewViewport*/) noexcept { return S_OK; } HRESULT GetProposedFont(const FontInfoDesired& /*FontInfoDesired*/, _Out_ FontInfo& /*FontInfo*/, int /*iDpi*/) noexcept { return S_OK; } - HRESULT GetDirtyArea(gsl::span& /*area*/) noexcept { return S_OK; } + HRESULT GetDirtyArea(std::span& /*area*/) noexcept { return S_OK; } HRESULT GetFontSize(_Out_ til::size* /*pFontSize*/) noexcept { return S_OK; } HRESULT IsGlyphWideByFont(std::wstring_view /*glyph*/, _Out_ bool* /*pResult*/) noexcept { return S_OK; } diff --git a/src/cascadia/WindowsTerminal/AppHost.h b/src/cascadia/WindowsTerminal/AppHost.h index 1195e7a0e8b..d54d9644823 100644 --- a/src/cascadia/WindowsTerminal/AppHost.h +++ b/src/cascadia/WindowsTerminal/AppHost.h @@ -22,6 +22,7 @@ class AppHost void SetTaskbarProgress(const winrt::Windows::Foundation::IInspectable& sender, const winrt::Windows::Foundation::IInspectable& args); bool HasWindow(); + winrt::TerminalApp::TerminalWindow Logic(); static void s_DisplayMessageBox(const winrt::TerminalApp::ParseCommandlineResult& message); diff --git a/src/common.build.pre.props b/src/common.build.pre.props index 6cc8877c2ed..a670249bf4b 100644 --- a/src/common.build.pre.props +++ b/src/common.build.pre.props @@ -103,7 +103,7 @@ Conhost code converts DWORDs to HANDLEs for instance. C4467: usage of ATL attributes is deprecated Conhost code still uses ATL. - C26445: Do not assign gsl::span or std::string_view to a reference. They are cheap to construct and are not owners of the underlying data. (gsl.view). + C26445: Do not assign std::span or std::string_view to a reference. They are cheap to construct and are not owners of the underlying data. (gsl.view). Even for MSVC v19.32 this is actually far from true. Copying (as opposed to referencing) larger than register-sized structures is fairly expensive. Example: https://godbolt.org/z/oPco88PaP C26813: Use 'bitwise and' to check if a flag is set. diff --git a/src/common.nugetversions.targets b/src/common.nugetversions.targets index 78c37d86330..04cda21acbc 100644 --- a/src/common.nugetversions.targets +++ b/src/common.nugetversions.targets @@ -43,9 +43,6 @@ - - - @@ -79,9 +76,6 @@ - - - diff --git a/src/features.xml b/src/features.xml index e26c217d3bf..13925a66157 100644 --- a/src/features.xml +++ b/src/features.xml @@ -145,4 +145,14 @@ AlwaysDisabled + + Feature_AzureConnectionInProc + Host the AzureConnection inside Terminal rather than via TerminalAzBridge + 4661 + AlwaysDisabled + + Dev + + + diff --git a/src/host/ApiRoutines.h b/src/host/ApiRoutines.h index 457aaee9f00..c89c0455d16 100644 --- a/src/host/ApiRoutines.h +++ b/src/host/ApiRoutines.h @@ -74,7 +74,7 @@ class ApiRoutines : public IApiRoutines std::unique_ptr& waiter) noexcept override; [[nodiscard]] HRESULT ReadConsoleAImpl(IConsoleInputObject& context, - gsl::span buffer, + std::span buffer, size_t& written, std::unique_ptr& waiter, const std::string_view initialData, @@ -85,7 +85,7 @@ class ApiRoutines : public IApiRoutines DWORD& controlKeyState) noexcept override; [[nodiscard]] HRESULT ReadConsoleWImpl(IConsoleInputObject& context, - gsl::span buffer, + std::span buffer, size_t& written, std::unique_ptr& waiter, const std::string_view initialData, @@ -194,41 +194,41 @@ class ApiRoutines : public IApiRoutines [[nodiscard]] HRESULT ReadConsoleOutputAttributeImpl(const SCREEN_INFORMATION& context, const til::point origin, - gsl::span buffer, + std::span buffer, size_t& written) noexcept override; [[nodiscard]] HRESULT ReadConsoleOutputCharacterAImpl(const SCREEN_INFORMATION& context, const til::point origin, - gsl::span buffer, + std::span buffer, size_t& written) noexcept override; [[nodiscard]] HRESULT ReadConsoleOutputCharacterWImpl(const SCREEN_INFORMATION& context, const til::point origin, - gsl::span buffer, + std::span buffer, size_t& written) noexcept override; [[nodiscard]] HRESULT WriteConsoleInputAImpl(InputBuffer& context, - const gsl::span buffer, + const std::span buffer, size_t& written, const bool append) noexcept override; [[nodiscard]] HRESULT WriteConsoleInputWImpl(InputBuffer& context, - const gsl::span buffer, + const std::span buffer, size_t& written, const bool append) noexcept override; [[nodiscard]] HRESULT WriteConsoleOutputAImpl(SCREEN_INFORMATION& context, - gsl::span buffer, + std::span buffer, const Microsoft::Console::Types::Viewport& requestRectangle, Microsoft::Console::Types::Viewport& writtenRectangle) noexcept override; [[nodiscard]] HRESULT WriteConsoleOutputWImpl(SCREEN_INFORMATION& context, - gsl::span buffer, + std::span buffer, const Microsoft::Console::Types::Viewport& requestRectangle, Microsoft::Console::Types::Viewport& writtenRectangle) noexcept override; [[nodiscard]] HRESULT WriteConsoleOutputAttributeImpl(IConsoleOutputObject& OutContext, - const gsl::span attrs, + const std::span attrs, const til::point target, size_t& used) noexcept override; @@ -243,28 +243,28 @@ class ApiRoutines : public IApiRoutines size_t& used) noexcept override; [[nodiscard]] HRESULT ReadConsoleOutputAImpl(const SCREEN_INFORMATION& context, - gsl::span buffer, + std::span buffer, const Microsoft::Console::Types::Viewport& sourceRectangle, Microsoft::Console::Types::Viewport& readRectangle) noexcept override; [[nodiscard]] HRESULT ReadConsoleOutputWImpl(const SCREEN_INFORMATION& context, - gsl::span buffer, + std::span buffer, const Microsoft::Console::Types::Viewport& sourceRectangle, Microsoft::Console::Types::Viewport& readRectangle) noexcept override; - [[nodiscard]] HRESULT GetConsoleTitleAImpl(gsl::span title, + [[nodiscard]] HRESULT GetConsoleTitleAImpl(std::span title, size_t& written, size_t& needed) noexcept override; - [[nodiscard]] HRESULT GetConsoleTitleWImpl(gsl::span title, + [[nodiscard]] HRESULT GetConsoleTitleWImpl(std::span title, size_t& written, size_t& needed) noexcept override; - [[nodiscard]] HRESULT GetConsoleOriginalTitleAImpl(gsl::span title, + [[nodiscard]] HRESULT GetConsoleOriginalTitleAImpl(std::span title, size_t& written, size_t& needed) noexcept override; - [[nodiscard]] HRESULT GetConsoleOriginalTitleWImpl(gsl::span title, + [[nodiscard]] HRESULT GetConsoleOriginalTitleWImpl(std::span title, size_t& written, size_t& needed) noexcept override; @@ -301,12 +301,12 @@ class ApiRoutines : public IApiRoutines const std::wstring_view exeName) noexcept override; [[nodiscard]] HRESULT GetConsoleAliasAImpl(const std::string_view source, - gsl::span target, + std::span target, size_t& written, const std::string_view exeName) noexcept override; [[nodiscard]] HRESULT GetConsoleAliasWImpl(const std::wstring_view source, - gsl::span target, + std::span target, size_t& written, const std::wstring_view exeName) noexcept override; @@ -321,17 +321,17 @@ class ApiRoutines : public IApiRoutines [[nodiscard]] HRESULT GetConsoleAliasExesLengthWImpl(size_t& bufferRequired) noexcept override; [[nodiscard]] HRESULT GetConsoleAliasesAImpl(const std::string_view exeName, - gsl::span alias, + std::span alias, size_t& written) noexcept override; [[nodiscard]] HRESULT GetConsoleAliasesWImpl(const std::wstring_view exeName, - gsl::span alias, + std::span alias, size_t& written) noexcept override; - [[nodiscard]] HRESULT GetConsoleAliasExesAImpl(gsl::span aliasExes, + [[nodiscard]] HRESULT GetConsoleAliasExesAImpl(std::span aliasExes, size_t& written) noexcept override; - [[nodiscard]] HRESULT GetConsoleAliasExesWImpl(gsl::span aliasExes, + [[nodiscard]] HRESULT GetConsoleAliasExesWImpl(std::span aliasExes, size_t& written) noexcept override; #pragma region CMDext Private API @@ -353,11 +353,11 @@ class ApiRoutines : public IApiRoutines size_t& length) noexcept override; [[nodiscard]] HRESULT GetConsoleCommandHistoryAImpl(const std::string_view exeName, - gsl::span commandHistory, + std::span commandHistory, size_t& written) noexcept override; [[nodiscard]] HRESULT GetConsoleCommandHistoryWImpl(const std::wstring_view exeName, - gsl::span commandHistory, + std::span commandHistory, size_t& written) noexcept override; #pragma endregion diff --git a/src/host/VtApiRoutines.cpp b/src/host/VtApiRoutines.cpp index b9f4e457b08..e3d4c59aea4 100644 --- a/src/host/VtApiRoutines.cpp +++ b/src/host/VtApiRoutines.cpp @@ -150,7 +150,7 @@ void VtApiRoutines::_SynchronizeCursor(std::unique_ptr& waiter) no } [[nodiscard]] HRESULT VtApiRoutines::ReadConsoleAImpl(IConsoleInputObject& context, - gsl::span buffer, + std::span buffer, size_t& written, std::unique_ptr& waiter, const std::string_view initialData, @@ -174,7 +174,7 @@ void VtApiRoutines::_SynchronizeCursor(std::unique_ptr& waiter) no } [[nodiscard]] HRESULT VtApiRoutines::ReadConsoleWImpl(IConsoleInputObject& context, - gsl::span buffer, + std::span buffer, size_t& written, std::unique_ptr& waiter, const std::string_view initialData, @@ -433,7 +433,7 @@ void VtApiRoutines::GetLargestConsoleWindowSizeImpl(const SCREEN_INFORMATION& co [[nodiscard]] HRESULT VtApiRoutines::ReadConsoleOutputAttributeImpl(const SCREEN_INFORMATION& context, const til::point origin, - gsl::span buffer, + std::span buffer, size_t& written) noexcept { std::fill_n(buffer.data(), buffer.size(), s_readBackUnicode.Attributes); // should be same as the ascii one. @@ -443,7 +443,7 @@ void VtApiRoutines::GetLargestConsoleWindowSizeImpl(const SCREEN_INFORMATION& co [[nodiscard]] HRESULT VtApiRoutines::ReadConsoleOutputCharacterAImpl(const SCREEN_INFORMATION& context, const til::point origin, - gsl::span buffer, + std::span buffer, size_t& written) noexcept { std::fill_n(buffer.data(), buffer.size(), s_readBackAscii.Char.AsciiChar); @@ -453,7 +453,7 @@ void VtApiRoutines::GetLargestConsoleWindowSizeImpl(const SCREEN_INFORMATION& co [[nodiscard]] HRESULT VtApiRoutines::ReadConsoleOutputCharacterWImpl(const SCREEN_INFORMATION& context, const til::point origin, - gsl::span buffer, + std::span buffer, size_t& written) noexcept { std::fill_n(buffer.data(), buffer.size(), s_readBackUnicode.Char.UnicodeChar); @@ -462,7 +462,7 @@ void VtApiRoutines::GetLargestConsoleWindowSizeImpl(const SCREEN_INFORMATION& co } [[nodiscard]] HRESULT VtApiRoutines::WriteConsoleInputAImpl(InputBuffer& context, - const gsl::span buffer, + const std::span buffer, size_t& written, const bool append) noexcept { @@ -470,7 +470,7 @@ void VtApiRoutines::GetLargestConsoleWindowSizeImpl(const SCREEN_INFORMATION& co } [[nodiscard]] HRESULT VtApiRoutines::WriteConsoleInputWImpl(InputBuffer& context, - const gsl::span buffer, + const std::span buffer, size_t& written, const bool append) noexcept { @@ -478,11 +478,11 @@ void VtApiRoutines::GetLargestConsoleWindowSizeImpl(const SCREEN_INFORMATION& co } extern HRESULT _ConvertCellsToWInplace(const UINT codepage, - gsl::span buffer, + std::span buffer, const Viewport& rectangle) noexcept; [[nodiscard]] HRESULT VtApiRoutines::WriteConsoleOutputAImpl(SCREEN_INFORMATION& context, - gsl::span buffer, + std::span buffer, const Microsoft::Console::Types::Viewport& requestRectangle, Microsoft::Console::Types::Viewport& writtenRectangle) noexcept { @@ -494,7 +494,7 @@ extern HRESULT _ConvertCellsToWInplace(const UINT codepage, } [[nodiscard]] HRESULT VtApiRoutines::WriteConsoleOutputWImpl(SCREEN_INFORMATION& context, - gsl::span buffer, + std::span buffer, const Microsoft::Console::Types::Viewport& requestRectangle, Microsoft::Console::Types::Viewport& writtenRectangle) noexcept { @@ -528,7 +528,7 @@ extern HRESULT _ConvertCellsToWInplace(const UINT codepage, } [[nodiscard]] HRESULT VtApiRoutines::WriteConsoleOutputAttributeImpl(IConsoleOutputObject& OutContext, - const gsl::span attrs, + const std::span attrs, const til::point target, size_t& used) noexcept { @@ -577,7 +577,7 @@ extern HRESULT _ConvertCellsToWInplace(const UINT codepage, } [[nodiscard]] HRESULT VtApiRoutines::ReadConsoleOutputAImpl(const SCREEN_INFORMATION& context, - gsl::span buffer, + std::span buffer, const Microsoft::Console::Types::Viewport& sourceRectangle, Microsoft::Console::Types::Viewport& readRectangle) noexcept { @@ -587,7 +587,7 @@ extern HRESULT _ConvertCellsToWInplace(const UINT codepage, } [[nodiscard]] HRESULT VtApiRoutines::ReadConsoleOutputWImpl(const SCREEN_INFORMATION& context, - gsl::span buffer, + std::span buffer, const Microsoft::Console::Types::Viewport& sourceRectangle, Microsoft::Console::Types::Viewport& readRectangle) noexcept { @@ -596,7 +596,7 @@ extern HRESULT _ConvertCellsToWInplace(const UINT codepage, return S_OK; } -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleTitleAImpl(gsl::span title, +[[nodiscard]] HRESULT VtApiRoutines::GetConsoleTitleAImpl(std::span title, size_t& written, size_t& needed) noexcept { @@ -611,7 +611,7 @@ extern HRESULT _ConvertCellsToWInplace(const UINT codepage, return S_OK; } -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleTitleWImpl(gsl::span title, +[[nodiscard]] HRESULT VtApiRoutines::GetConsoleTitleWImpl(std::span title, size_t& written, size_t& needed) noexcept { @@ -626,7 +626,7 @@ extern HRESULT _ConvertCellsToWInplace(const UINT codepage, return S_OK; } -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleOriginalTitleAImpl(gsl::span title, +[[nodiscard]] HRESULT VtApiRoutines::GetConsoleOriginalTitleAImpl(std::span title, size_t& written, size_t& needed) noexcept { @@ -641,7 +641,7 @@ extern HRESULT _ConvertCellsToWInplace(const UINT codepage, return S_OK; } -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleOriginalTitleWImpl(gsl::span title, +[[nodiscard]] HRESULT VtApiRoutines::GetConsoleOriginalTitleWImpl(std::span title, size_t& written, size_t& needed) noexcept { @@ -719,7 +719,7 @@ void VtApiRoutines::GetConsoleDisplayModeImpl(ULONG& flags) noexcept } [[nodiscard]] HRESULT VtApiRoutines::GetConsoleAliasAImpl(const std::string_view source, - gsl::span target, + std::span target, size_t& written, const std::string_view exeName) noexcept { @@ -727,7 +727,7 @@ void VtApiRoutines::GetConsoleDisplayModeImpl(ULONG& flags) noexcept } [[nodiscard]] HRESULT VtApiRoutines::GetConsoleAliasWImpl(const std::wstring_view source, - gsl::span target, + std::span target, size_t& written, const std::wstring_view exeName) noexcept { @@ -757,26 +757,26 @@ void VtApiRoutines::GetConsoleDisplayModeImpl(ULONG& flags) noexcept } [[nodiscard]] HRESULT VtApiRoutines::GetConsoleAliasesAImpl(const std::string_view exeName, - gsl::span alias, + std::span alias, size_t& written) noexcept { return m_pUsualRoutines->GetConsoleAliasesAImpl(exeName, alias, written); } [[nodiscard]] HRESULT VtApiRoutines::GetConsoleAliasesWImpl(const std::wstring_view exeName, - gsl::span alias, + std::span alias, size_t& written) noexcept { return m_pUsualRoutines->GetConsoleAliasesWImpl(exeName, alias, written); } -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleAliasExesAImpl(gsl::span aliasExes, +[[nodiscard]] HRESULT VtApiRoutines::GetConsoleAliasExesAImpl(std::span aliasExes, size_t& written) noexcept { return m_pUsualRoutines->GetConsoleAliasExesAImpl(aliasExes, written); } -[[nodiscard]] HRESULT VtApiRoutines::GetConsoleAliasExesWImpl(gsl::span aliasExes, +[[nodiscard]] HRESULT VtApiRoutines::GetConsoleAliasExesWImpl(std::span aliasExes, size_t& written) noexcept { return m_pUsualRoutines->GetConsoleAliasExesWImpl(aliasExes, written); @@ -817,14 +817,14 @@ void VtApiRoutines::GetConsoleDisplayModeImpl(ULONG& flags) noexcept } [[nodiscard]] HRESULT VtApiRoutines::GetConsoleCommandHistoryAImpl(const std::string_view exeName, - gsl::span commandHistory, + std::span commandHistory, size_t& written) noexcept { return m_pUsualRoutines->GetConsoleCommandHistoryAImpl(exeName, commandHistory, written); } [[nodiscard]] HRESULT VtApiRoutines::GetConsoleCommandHistoryWImpl(const std::wstring_view exeName, - gsl::span commandHistory, + std::span commandHistory, size_t& written) noexcept { return m_pUsualRoutines->GetConsoleCommandHistoryWImpl(exeName, commandHistory, written); diff --git a/src/host/VtApiRoutines.h b/src/host/VtApiRoutines.h index 79962bc989a..2c95d340c97 100644 --- a/src/host/VtApiRoutines.h +++ b/src/host/VtApiRoutines.h @@ -77,7 +77,7 @@ class VtApiRoutines : public IApiRoutines std::unique_ptr& waiter) noexcept override; [[nodiscard]] HRESULT ReadConsoleAImpl(IConsoleInputObject& context, - gsl::span buffer, + std::span buffer, size_t& written, std::unique_ptr& waiter, const std::string_view initialData, @@ -88,7 +88,7 @@ class VtApiRoutines : public IApiRoutines DWORD& controlKeyState) noexcept override; [[nodiscard]] HRESULT ReadConsoleWImpl(IConsoleInputObject& context, - gsl::span buffer, + std::span buffer, size_t& written, std::unique_ptr& waiter, const std::string_view initialData, @@ -197,41 +197,41 @@ class VtApiRoutines : public IApiRoutines [[nodiscard]] HRESULT ReadConsoleOutputAttributeImpl(const SCREEN_INFORMATION& context, const til::point origin, - gsl::span buffer, + std::span buffer, size_t& written) noexcept override; [[nodiscard]] HRESULT ReadConsoleOutputCharacterAImpl(const SCREEN_INFORMATION& context, const til::point origin, - gsl::span buffer, + std::span buffer, size_t& written) noexcept override; [[nodiscard]] HRESULT ReadConsoleOutputCharacterWImpl(const SCREEN_INFORMATION& context, const til::point origin, - gsl::span buffer, + std::span buffer, size_t& written) noexcept override; [[nodiscard]] HRESULT WriteConsoleInputAImpl(InputBuffer& context, - const gsl::span buffer, + const std::span buffer, size_t& written, const bool append) noexcept override; [[nodiscard]] HRESULT WriteConsoleInputWImpl(InputBuffer& context, - const gsl::span buffer, + const std::span buffer, size_t& written, const bool append) noexcept override; [[nodiscard]] HRESULT WriteConsoleOutputAImpl(SCREEN_INFORMATION& context, - gsl::span buffer, + std::span buffer, const Microsoft::Console::Types::Viewport& requestRectangle, Microsoft::Console::Types::Viewport& writtenRectangle) noexcept override; [[nodiscard]] HRESULT WriteConsoleOutputWImpl(SCREEN_INFORMATION& context, - gsl::span buffer, + std::span buffer, const Microsoft::Console::Types::Viewport& requestRectangle, Microsoft::Console::Types::Viewport& writtenRectangle) noexcept override; [[nodiscard]] HRESULT WriteConsoleOutputAttributeImpl(IConsoleOutputObject& OutContext, - const gsl::span attrs, + const std::span attrs, const til::point target, size_t& used) noexcept override; @@ -246,28 +246,28 @@ class VtApiRoutines : public IApiRoutines size_t& used) noexcept override; [[nodiscard]] HRESULT ReadConsoleOutputAImpl(const SCREEN_INFORMATION& context, - gsl::span buffer, + std::span buffer, const Microsoft::Console::Types::Viewport& sourceRectangle, Microsoft::Console::Types::Viewport& readRectangle) noexcept override; [[nodiscard]] HRESULT ReadConsoleOutputWImpl(const SCREEN_INFORMATION& context, - gsl::span buffer, + std::span buffer, const Microsoft::Console::Types::Viewport& sourceRectangle, Microsoft::Console::Types::Viewport& readRectangle) noexcept override; - [[nodiscard]] HRESULT GetConsoleTitleAImpl(gsl::span title, + [[nodiscard]] HRESULT GetConsoleTitleAImpl(std::span title, size_t& written, size_t& needed) noexcept override; - [[nodiscard]] HRESULT GetConsoleTitleWImpl(gsl::span title, + [[nodiscard]] HRESULT GetConsoleTitleWImpl(std::span title, size_t& written, size_t& needed) noexcept override; - [[nodiscard]] HRESULT GetConsoleOriginalTitleAImpl(gsl::span title, + [[nodiscard]] HRESULT GetConsoleOriginalTitleAImpl(std::span title, size_t& written, size_t& needed) noexcept override; - [[nodiscard]] HRESULT GetConsoleOriginalTitleWImpl(gsl::span title, + [[nodiscard]] HRESULT GetConsoleOriginalTitleWImpl(std::span title, size_t& written, size_t& needed) noexcept override; @@ -304,12 +304,12 @@ class VtApiRoutines : public IApiRoutines const std::wstring_view exeName) noexcept override; [[nodiscard]] HRESULT GetConsoleAliasAImpl(const std::string_view source, - gsl::span target, + std::span target, size_t& written, const std::string_view exeName) noexcept override; [[nodiscard]] HRESULT GetConsoleAliasWImpl(const std::wstring_view source, - gsl::span target, + std::span target, size_t& written, const std::wstring_view exeName) noexcept override; @@ -324,17 +324,17 @@ class VtApiRoutines : public IApiRoutines [[nodiscard]] HRESULT GetConsoleAliasExesLengthWImpl(size_t& bufferRequired) noexcept override; [[nodiscard]] HRESULT GetConsoleAliasesAImpl(const std::string_view exeName, - gsl::span alias, + std::span alias, size_t& written) noexcept override; [[nodiscard]] HRESULT GetConsoleAliasesWImpl(const std::wstring_view exeName, - gsl::span alias, + std::span alias, size_t& written) noexcept override; - [[nodiscard]] HRESULT GetConsoleAliasExesAImpl(gsl::span aliasExes, + [[nodiscard]] HRESULT GetConsoleAliasExesAImpl(std::span aliasExes, size_t& written) noexcept override; - [[nodiscard]] HRESULT GetConsoleAliasExesWImpl(gsl::span aliasExes, + [[nodiscard]] HRESULT GetConsoleAliasExesWImpl(std::span aliasExes, size_t& written) noexcept override; #pragma region CMDext Private API @@ -356,11 +356,11 @@ class VtApiRoutines : public IApiRoutines size_t& length) noexcept override; [[nodiscard]] HRESULT GetConsoleCommandHistoryAImpl(const std::string_view exeName, - gsl::span commandHistory, + std::span commandHistory, size_t& written) noexcept override; [[nodiscard]] HRESULT GetConsoleCommandHistoryWImpl(const std::wstring_view exeName, - gsl::span commandHistory, + std::span commandHistory, size_t& written) noexcept override; #pragma endregion diff --git a/src/host/_output.cpp b/src/host/_output.cpp index bf081ac1786..8ad7117ea0b 100644 --- a/src/host/_output.cpp +++ b/src/host/_output.cpp @@ -66,7 +66,7 @@ void WriteToScreen(SCREEN_INFORMATION& screenInfo, const Viewport& region) // Return Value: // - S_OK, E_INVALIDARG or similar HRESULT error. [[nodiscard]] HRESULT ApiRoutines::WriteConsoleOutputAttributeImpl(IConsoleOutputObject& OutContext, - const gsl::span attrs, + const std::span attrs, const til::point target, size_t& used) noexcept { diff --git a/src/host/alias.cpp b/src/host/alias.cpp index b7c885bc9f4..85fc3d0875b 100644 --- a/src/host/alias.cpp +++ b/src/host/alias.cpp @@ -137,7 +137,7 @@ std::unordered_map> target, + std::optional> target, size_t& writtenOrNeeded, const std::wstring_view exeName) { @@ -195,7 +195,7 @@ std::unordered_map target, + std::span target, size_t& written, const std::string_view exeName) noexcept { @@ -235,7 +235,7 @@ std::unordered_map(targetBuffer.get(), targetNeeded), + std::span(targetBuffer.get(), targetNeeded), targetWritten, exeNameW)); @@ -268,7 +268,7 @@ std::unordered_map target, + std::span target, size_t& written, const std::wstring_view exeName) noexcept { @@ -440,7 +440,7 @@ void Alias::s_ClearCmdExeAliases() // Return Value: // - Check HRESULT with SUCCEEDED. Can return memory, safe math, safe string, or locale conversion errors. [[nodiscard]] HRESULT GetConsoleAliasesWImplHelper(const std::wstring_view exeName, - std::optional> aliasBuffer, + std::optional> aliasBuffer, size_t& writtenOrNeeded) { // Ensure output variables are initialized. @@ -527,7 +527,7 @@ void Alias::s_ClearCmdExeAliases() // Return Value: // - Check HRESULT with SUCCEEDED. Can return memory, safe math, safe string, or locale conversion errors. [[nodiscard]] HRESULT ApiRoutines::GetConsoleAliasesAImpl(const std::string_view exeName, - gsl::span alias, + std::span alias, size_t& written) noexcept { const auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation(); @@ -563,7 +563,7 @@ void Alias::s_ClearCmdExeAliases() // Call the Unicode version of this method size_t bufferWritten; - RETURN_IF_FAILED(GetConsoleAliasesWImplHelper(exeNameW, gsl::span(aliasBuffer.get(), bufferNeeded), bufferWritten)); + RETURN_IF_FAILED(GetConsoleAliasesWImplHelper(exeNameW, std::span(aliasBuffer.get(), bufferNeeded), bufferWritten)); // Convert result to A const auto converted = ConvertToA(codepage, { aliasBuffer.get(), bufferWritten }); @@ -591,7 +591,7 @@ void Alias::s_ClearCmdExeAliases() // Return Value: // - Check HRESULT with SUCCEEDED. Can return memory, safe math, safe string, or locale conversion errors. [[nodiscard]] HRESULT ApiRoutines::GetConsoleAliasesWImpl(const std::wstring_view exeName, - gsl::span alias, + std::span alias, size_t& written) noexcept { LockConsole(); @@ -688,7 +688,7 @@ void Alias::s_ClearCmdExeAliases() // or how many characters would have been needed (if buffer is nullopt). // Return Value: // - Check HRESULT with SUCCEEDED. Can return memory, safe math, safe string, or locale conversion errors. -[[nodiscard]] HRESULT GetConsoleAliasExesWImplHelper(std::optional> aliasExesBuffer, +[[nodiscard]] HRESULT GetConsoleAliasExesWImplHelper(std::optional> aliasExesBuffer, size_t& writtenOrNeeded) { // Ensure output variables are initialized. @@ -745,7 +745,7 @@ void Alias::s_ClearCmdExeAliases() // - written - Specifies how many characters were written // Return Value: // - Check HRESULT with SUCCEEDED. Can return memory, safe math, safe string, or locale conversion errors. -[[nodiscard]] HRESULT ApiRoutines::GetConsoleAliasExesAImpl(gsl::span aliasExes, +[[nodiscard]] HRESULT ApiRoutines::GetConsoleAliasExesAImpl(std::span aliasExes, size_t& written) noexcept { const auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation(); @@ -777,7 +777,7 @@ void Alias::s_ClearCmdExeAliases() // Call the Unicode version of this method size_t bufferWritten; - RETURN_IF_FAILED(GetConsoleAliasExesWImplHelper(gsl::span(targetBuffer.get(), bufferNeeded), bufferWritten)); + RETURN_IF_FAILED(GetConsoleAliasExesWImplHelper(std::span(targetBuffer.get(), bufferNeeded), bufferWritten)); // Convert result to A const auto converted = ConvertToA(codepage, { targetBuffer.get(), bufferWritten }); @@ -804,7 +804,7 @@ void Alias::s_ClearCmdExeAliases() // - pcchAliasExesBufferWrittenOrNeeded - Pointer to space that will specify how many characters were written // Return Value: // - Check HRESULT with SUCCEEDED. Can return memory, safe math, safe string, or locale conversion errors. -[[nodiscard]] HRESULT ApiRoutines::GetConsoleAliasExesWImpl(gsl::span aliasExes, +[[nodiscard]] HRESULT ApiRoutines::GetConsoleAliasExesWImpl(std::span aliasExes, size_t& written) noexcept { LockConsole(); diff --git a/src/host/conareainfo.cpp b/src/host/conareainfo.cpp index 657a85ae498..0699c7bf15c 100644 --- a/src/host/conareainfo.cpp +++ b/src/host/conareainfo.cpp @@ -110,7 +110,7 @@ void ConversionAreaInfo::SetAttributes(const TextAttribute& attr) void ConversionAreaInfo::WriteText(const std::vector& text, const til::CoordType column) { - gsl::span view(text.data(), text.size()); + std::span view(text.data(), text.size()); _screenBuffer->Write(view, { column, 0 }); } diff --git a/src/host/conimeinfo.cpp b/src/host/conimeinfo.cpp index f003815fb05..9ab47a80029 100644 --- a/src/host/conimeinfo.cpp +++ b/src/host/conimeinfo.cpp @@ -57,8 +57,8 @@ void ConsoleImeInfo::RedrawCompMessage() // - attributes - Encoded attributes including the cursor position and the color index (to the array) // - colorArray - An array of colors to use for the text void ConsoleImeInfo::WriteCompMessage(const std::wstring_view text, - const gsl::span attributes, - const gsl::span colorArray) + const std::span attributes, + const std::span colorArray) { ClearAllAreas(); @@ -181,8 +181,8 @@ void ConsoleImeInfo::ClearAllAreas() // Return Value: // - TextAttribute object with color and cursor and line drawing data. TextAttribute ConsoleImeInfo::s_RetrieveAttributeAt(const size_t pos, - const gsl::span attributes, - const gsl::span colorArray) + const std::span attributes, + const std::span colorArray) { // Encoded attribute is the shorthand information passed from the IME // that contains a cursor position packed in along with which color in the @@ -218,8 +218,8 @@ TextAttribute ConsoleImeInfo::s_RetrieveAttributeAt(const size_t pos, // Return Value: // - Vector of OutputCells where each one represents one cell of the output buffer. std::vector ConsoleImeInfo::s_ConvertToCells(const std::wstring_view text, - const gsl::span attributes, - const gsl::span colorArray) + const std::span attributes, + const std::span colorArray) { std::vector cells; @@ -398,8 +398,8 @@ std::vector::const_iterator ConsoleImeInfo::_WriteConversionArea(con // each text character. This view must be the same size as the text view. // - colorArray - 8 colors to be used to format the text for display void ConsoleImeInfo::_WriteUndeterminedChars(const std::wstring_view text, - const gsl::span attributes, - const gsl::span colorArray) + const std::span attributes, + const std::span colorArray) { auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation(); auto& screenInfo = gci.GetActiveOutputBuffer(); diff --git a/src/host/conimeinfo.h b/src/host/conimeinfo.h index 3d84f232caf..81ea359d8a5 100644 --- a/src/host/conimeinfo.h +++ b/src/host/conimeinfo.h @@ -48,8 +48,8 @@ class ConsoleImeInfo final [[nodiscard]] HRESULT ResizeAllAreas(const til::size newSize); void WriteCompMessage(const std::wstring_view text, - const gsl::span attributes, - const gsl::span colorArray); + const std::span attributes, + const std::span colorArray); void WriteResultMessage(const std::wstring_view text); @@ -64,18 +64,18 @@ class ConsoleImeInfo final void _ClearComposition(); void _WriteUndeterminedChars(const std::wstring_view text, - const gsl::span attributes, - const gsl::span colorArray); + const std::span attributes, + const std::span colorArray); void _InsertConvertedString(const std::wstring_view text); static TextAttribute s_RetrieveAttributeAt(const size_t pos, - const gsl::span attributes, - const gsl::span colorArray); + const std::span attributes, + const std::span colorArray); static std::vector s_ConvertToCells(const std::wstring_view text, - const gsl::span attributes, - const gsl::span colorArray); + const std::span attributes, + const std::span colorArray); std::vector::const_iterator _WriteConversionArea(const std::vector::const_iterator begin, const std::vector::const_iterator end, diff --git a/src/host/convarea.cpp b/src/host/convarea.cpp index c354755fd16..62c9796a56f 100644 --- a/src/host/convarea.cpp +++ b/src/host/convarea.cpp @@ -116,8 +116,8 @@ void WriteConvRegionToScreen(const SCREEN_INFORMATION& ScreenInfo, } [[nodiscard]] HRESULT ImeComposeData(std::wstring_view text, - gsl::span attributes, - gsl::span colorArray) + std::span attributes, + std::span colorArray) { try { diff --git a/src/host/dbcs.cpp b/src/host/dbcs.cpp index 0d5b51e21a4..0048f5cdc4a 100644 --- a/src/host/dbcs.cpp +++ b/src/host/dbcs.cpp @@ -55,7 +55,7 @@ bool CheckBisectStringA(_In_reads_bytes_(cbBuf) PCHAR pchBuf, _In_ DWORD cbBuf, // - buffer - The buffer to walk and fix // Return Value: // - The length of the final modified buffer. -DWORD UnicodeRasterFontCellMungeOnRead(const gsl::span buffer) +DWORD UnicodeRasterFontCellMungeOnRead(const std::span buffer) { // Walk through the source CHAR_INFO and copy each to the destination. // EXCEPT for trailing bytes (this will de-duplicate the leading/trailing byte double copies of the CHAR_INFOs as stored in the buffer). @@ -194,7 +194,7 @@ _Ret_range_(0, cbAnsi) memcpy(TmpUni, pwchUnicode, cchUnicode * sizeof(WCHAR)); - BYTE AsciiDbcs[2]; + CHAR AsciiDbcs[2]; AsciiDbcs[1] = 0; ULONG i, j; diff --git a/src/host/dbcs.h b/src/host/dbcs.h index 53762d11880..fd4737e7a9c 100644 --- a/src/host/dbcs.h +++ b/src/host/dbcs.h @@ -22,7 +22,7 @@ Revision History: bool CheckBisectStringA(_In_reads_bytes_(cbBuf) PCHAR pchBuf, _In_ DWORD cbBuf, const CPINFO* const pCPInfo); -DWORD UnicodeRasterFontCellMungeOnRead(const gsl::span buffer); +DWORD UnicodeRasterFontCellMungeOnRead(const std::span buffer); bool IsDBCSLeadByteConsole(const CHAR ch, const CPINFO* const pCPInfo); diff --git a/src/host/directio.cpp b/src/host/directio.cpp index 382aa2d840c..cd3649f27e8 100644 --- a/src/host/directio.cpp +++ b/src/host/directio.cpp @@ -452,7 +452,7 @@ void EventsToUnicode(_Inout_ std::deque>& inEvents, // Return Value: // - HRESULT indicating success or failure [[nodiscard]] HRESULT ApiRoutines::WriteConsoleInputAImpl(InputBuffer& context, - const gsl::span buffer, + const std::span buffer, size_t& written, const bool append) noexcept { @@ -496,7 +496,7 @@ void EventsToUnicode(_Inout_ std::deque>& inEvents, // Return Value: // - HRESULT indicating success or failure [[nodiscard]] HRESULT ApiRoutines::WriteConsoleInputWImpl(InputBuffer& context, - const gsl::span buffer, + const std::span buffer, size_t& written, const bool append) noexcept { @@ -524,7 +524,7 @@ void EventsToUnicode(_Inout_ std::deque>& inEvents, // Return Value: // - Generally S_OK. Could be a memory or math error code. [[nodiscard]] static HRESULT _ConvertCellsToAInplace(const UINT codepage, - const gsl::span buffer, + const std::span buffer, const Viewport rectangle) noexcept { try @@ -601,7 +601,7 @@ void EventsToUnicode(_Inout_ std::deque>& inEvents, // Return Value: // - Generally S_OK. Could be a memory or math error code. [[nodiscard]] HRESULT _ConvertCellsToWInplace(const UINT codepage, - gsl::span buffer, + std::span buffer, const Viewport& rectangle) noexcept { try @@ -671,7 +671,7 @@ void EventsToUnicode(_Inout_ std::deque>& inEvents, CATCH_RETURN(); } -[[nodiscard]] static std::vector _ConvertCellsToMungedW(gsl::span buffer, const Viewport& rectangle) +[[nodiscard]] static std::vector _ConvertCellsToMungedW(std::span buffer, const Viewport& rectangle) { std::vector result; result.reserve(buffer.size()); @@ -722,7 +722,7 @@ void EventsToUnicode(_Inout_ std::deque>& inEvents, } [[nodiscard]] static HRESULT _ReadConsoleOutputWImplHelper(const SCREEN_INFORMATION& context, - gsl::span targetBuffer, + std::span targetBuffer, const Microsoft::Console::Types::Viewport& requestRectangle, Microsoft::Console::Types::Viewport& readRectangle) noexcept { @@ -812,7 +812,7 @@ void EventsToUnicode(_Inout_ std::deque>& inEvents, } [[nodiscard]] HRESULT ApiRoutines::ReadConsoleOutputAImpl(const SCREEN_INFORMATION& context, - gsl::span buffer, + std::span buffer, const Microsoft::Console::Types::Viewport& sourceRectangle, Microsoft::Console::Types::Viewport& readRectangle) noexcept { @@ -834,7 +834,7 @@ void EventsToUnicode(_Inout_ std::deque>& inEvents, } [[nodiscard]] HRESULT ApiRoutines::ReadConsoleOutputWImpl(const SCREEN_INFORMATION& context, - gsl::span buffer, + std::span buffer, const Microsoft::Console::Types::Viewport& sourceRectangle, Microsoft::Console::Types::Viewport& readRectangle) noexcept { @@ -858,7 +858,7 @@ void EventsToUnicode(_Inout_ std::deque>& inEvents, } [[nodiscard]] static HRESULT _WriteConsoleOutputWImplHelper(SCREEN_INFORMATION& context, - gsl::span buffer, + std::span buffer, const Viewport& requestRectangle, Viewport& writtenRectangle) noexcept { @@ -942,7 +942,7 @@ void EventsToUnicode(_Inout_ std::deque>& inEvents, const auto subspan = buffer.subspan(totalOffset, writeRectangle.Width()); // Convert to a CHAR_INFO view to fit into the iterator - const auto charInfos = gsl::span(subspan.data(), subspan.size()); + const auto charInfos = std::span(subspan.data(), subspan.size()); // Make the iterator and write to the target position. OutputCellIterator it(charInfos); @@ -958,7 +958,7 @@ void EventsToUnicode(_Inout_ std::deque>& inEvents, } [[nodiscard]] HRESULT ApiRoutines::WriteConsoleOutputAImpl(SCREEN_INFORMATION& context, - gsl::span buffer, + std::span buffer, const Viewport& requestRectangle, Viewport& writtenRectangle) noexcept { @@ -979,7 +979,7 @@ void EventsToUnicode(_Inout_ std::deque>& inEvents, } [[nodiscard]] HRESULT ApiRoutines::WriteConsoleOutputWImpl(SCREEN_INFORMATION& context, - gsl::span buffer, + std::span buffer, const Viewport& requestRectangle, Viewport& writtenRectangle) noexcept { @@ -1007,7 +1007,7 @@ void EventsToUnicode(_Inout_ std::deque>& inEvents, [[nodiscard]] HRESULT ApiRoutines::ReadConsoleOutputAttributeImpl(const SCREEN_INFORMATION& context, const til::point origin, - gsl::span buffer, + std::span buffer, size_t& written) noexcept { written = 0; @@ -1028,7 +1028,7 @@ void EventsToUnicode(_Inout_ std::deque>& inEvents, [[nodiscard]] HRESULT ApiRoutines::ReadConsoleOutputCharacterAImpl(const SCREEN_INFORMATION& context, const til::point origin, - gsl::span buffer, + std::span buffer, size_t& written) noexcept { written = 0; @@ -1057,7 +1057,7 @@ void EventsToUnicode(_Inout_ std::deque>& inEvents, [[nodiscard]] HRESULT ApiRoutines::ReadConsoleOutputCharacterWImpl(const SCREEN_INFORMATION& context, const til::point origin, - gsl::span buffer, + std::span buffer, size_t& written) noexcept { written = 0; diff --git a/src/host/getset.cpp b/src/host/getset.cpp index fa6df67b8d5..f2cd485842f 100644 --- a/src/host/getset.cpp +++ b/src/host/getset.cpp @@ -1281,7 +1281,7 @@ void ApiRoutines::GetConsoleDisplayModeImpl(ULONG& flags) noexcept // - isOriginal - If true, gets the title when we booted up. If false, gets whatever it is set to right now. // Return Value: // - S_OK, E_INVALIDARG, or failure code from thrown exception -[[nodiscard]] HRESULT GetConsoleTitleWImplHelper(std::optional> title, +[[nodiscard]] HRESULT GetConsoleTitleWImplHelper(std::optional> title, size_t& written, size_t& needed, const bool isOriginal) noexcept @@ -1332,7 +1332,7 @@ void ApiRoutines::GetConsoleDisplayModeImpl(ULONG& flags) noexcept // Return Value: // - S_OK, E_INVALIDARG, or failure code from thrown exception -[[nodiscard]] HRESULT GetConsoleTitleAImplHelper(gsl::span title, +[[nodiscard]] HRESULT GetConsoleTitleAImplHelper(std::span title, size_t& written, size_t& needed, const bool isOriginal) noexcept @@ -1362,7 +1362,7 @@ void ApiRoutines::GetConsoleDisplayModeImpl(ULONG& flags) noexcept auto unicodeBuffer = std::make_unique(unicodeSize); RETURN_IF_NULL_ALLOC(unicodeBuffer); - const gsl::span unicodeSpan(unicodeBuffer.get(), unicodeSize); + const std::span unicodeSpan(unicodeBuffer.get(), unicodeSize); // Retrieve the title in Unicode. RETURN_IF_FAILED(GetConsoleTitleWImplHelper(unicodeSpan, unicodeWritten, unicodeNeeded, isOriginal)); @@ -1420,7 +1420,7 @@ void ApiRoutines::GetConsoleDisplayModeImpl(ULONG& flags) noexcept // - needed - The number of characters we would need to completely write out the title. // Return Value: // - S_OK, E_INVALIDARG, or failure code from thrown exception -[[nodiscard]] HRESULT ApiRoutines::GetConsoleTitleAImpl(gsl::span title, +[[nodiscard]] HRESULT ApiRoutines::GetConsoleTitleAImpl(std::span title, size_t& written, size_t& needed) noexcept { @@ -1443,7 +1443,7 @@ void ApiRoutines::GetConsoleDisplayModeImpl(ULONG& flags) noexcept // - needed - The number of characters we would need to completely write out the title. // Return Value: // - S_OK, E_INVALIDARG, or failure code from thrown exception -[[nodiscard]] HRESULT ApiRoutines::GetConsoleTitleWImpl(gsl::span title, +[[nodiscard]] HRESULT ApiRoutines::GetConsoleTitleWImpl(std::span title, size_t& written, size_t& needed) noexcept { @@ -1466,7 +1466,7 @@ void ApiRoutines::GetConsoleDisplayModeImpl(ULONG& flags) noexcept // - needed - The number of characters we would need to completely write out the title. // Return Value: // - S_OK, E_INVALIDARG, or failure code from thrown exception -[[nodiscard]] HRESULT ApiRoutines::GetConsoleOriginalTitleAImpl(gsl::span title, +[[nodiscard]] HRESULT ApiRoutines::GetConsoleOriginalTitleAImpl(std::span title, size_t& written, size_t& needed) noexcept { @@ -1489,7 +1489,7 @@ void ApiRoutines::GetConsoleDisplayModeImpl(ULONG& flags) noexcept // - needed - The number of characters we would need to completely write out the title. // Return Value: // - S_OK, E_INVALIDARG, or failure code from thrown exception -[[nodiscard]] HRESULT ApiRoutines::GetConsoleOriginalTitleWImpl(gsl::span title, +[[nodiscard]] HRESULT ApiRoutines::GetConsoleOriginalTitleWImpl(std::span title, size_t& written, size_t& needed) noexcept { diff --git a/src/host/history.cpp b/src/host/history.cpp index 58ae5eba21c..501b33e0ee2 100644 --- a/src/host/history.cpp +++ b/src/host/history.cpp @@ -164,7 +164,7 @@ std::wstring_view CommandHistory::GetNth(const SHORT index) const } [[nodiscard]] HRESULT CommandHistory::RetrieveNth(const SHORT index, - gsl::span buffer, + std::span buffer, size_t& commandSize) { LastDisplayed = index; @@ -191,7 +191,7 @@ std::wstring_view CommandHistory::GetNth(const SHORT index) const } [[nodiscard]] HRESULT CommandHistory::Retrieve(const SearchDirection searchDirection, - const gsl::span buffer, + const std::span buffer, size_t& commandSize) { FAIL_FAST_IF(!(WI_IsFlagSet(Flags, CLE_ALLOCATED))); @@ -776,7 +776,7 @@ HRESULT ApiRoutines::GetConsoleCommandHistoryLengthWImpl(const std::wstring_view // Return Value: // - Check HRESULT with SUCCEEDED. Can return memory, safe math, safe string, or locale conversion errors. HRESULT GetConsoleCommandHistoryWImplHelper(const std::wstring_view exeName, - gsl::span historyBuffer, + std::span historyBuffer, size_t& writtenOrNeeded) { // Ensure output variables are initialized @@ -847,7 +847,7 @@ HRESULT GetConsoleCommandHistoryWImplHelper(const std::wstring_view exeName, // Return Value: // - Check HRESULT with SUCCEEDED. Can return memory, safe math, safe string, or locale conversion errors. HRESULT ApiRoutines::GetConsoleCommandHistoryAImpl(const std::string_view exeName, - gsl::span commandHistory, + std::span commandHistory, size_t& written) noexcept { const auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation(); @@ -882,7 +882,7 @@ HRESULT ApiRoutines::GetConsoleCommandHistoryAImpl(const std::string_view exeNam // Call the Unicode version of this method size_t bufferWritten; - RETURN_IF_FAILED(GetConsoleCommandHistoryWImplHelper(exeNameW, gsl::span(buffer.get(), bufferNeeded), bufferWritten)); + RETURN_IF_FAILED(GetConsoleCommandHistoryWImplHelper(exeNameW, std::span(buffer.get(), bufferNeeded), bufferWritten)); // Convert result to A const auto converted = ConvertToA(codepage, { buffer.get(), bufferWritten }); @@ -911,7 +911,7 @@ HRESULT ApiRoutines::GetConsoleCommandHistoryAImpl(const std::string_view exeNam // Return Value: // - Check HRESULT with SUCCEEDED. Can return memory, safe math, safe string, or locale conversion errors. HRESULT ApiRoutines::GetConsoleCommandHistoryWImpl(const std::wstring_view exeName, - gsl::span commandHistory, + std::span commandHistory, size_t& written) noexcept { LockConsole(); diff --git a/src/host/history.h b/src/host/history.h index b2c2bb17cf6..9abe6841a95 100644 --- a/src/host/history.h +++ b/src/host/history.h @@ -50,11 +50,11 @@ class CommandHistory const bool suppressDuplicates); [[nodiscard]] HRESULT Retrieve(const SearchDirection searchDirection, - const gsl::span buffer, + const std::span buffer, size_t& commandSize); [[nodiscard]] HRESULT RetrieveNth(const SHORT index, - const gsl::span buffer, + const std::span buffer, size_t& commandSize); size_t GetNumberOfCommands() const; diff --git a/src/host/misc.cpp b/src/host/misc.cpp index f30fb7d3acd..671da86d7a6 100644 --- a/src/host/misc.cpp +++ b/src/host/misc.cpp @@ -191,22 +191,23 @@ BOOL CheckBisectProcessW(const SCREEN_INFORMATION& ScreenInfo, // Note: may throw on error void SplitToOem(std::deque>& events) { - const auto codepage = ServiceLocator::LocateGlobals().getConsoleInformation().CP; - - // convert events to oem codepage + const auto cp = ServiceLocator::LocateGlobals().getConsoleInformation().CP; std::deque> convertedEvents; - while (!events.empty()) + + for (auto& currentEvent : events) { - auto currentEvent = std::move(events.front()); - events.pop_front(); if (currentEvent->EventType() == InputEventType::KeyEvent) { const auto pKeyEvent = static_cast(currentEvent.get()); - // convert from wchar to char - std::wstring wstr{ pKeyEvent->GetCharData() }; - const auto str = ConvertToA(codepage, wstr); + const auto wch = pKeyEvent->GetCharData(); + + char buffer[8]; + const auto length = WideCharToMultiByte(cp, 0, &wch, 1, &buffer[0], sizeof(buffer), nullptr, nullptr); + THROW_LAST_ERROR_IF(length <= 0); + + const std::string_view str{ &buffer[0], gsl::narrow_cast(length) }; - for (auto& ch : str) + for (const auto& ch : str) { auto tempEvent = std::make_unique(*pKeyEvent); tempEvent->SetCharData(ch); @@ -218,12 +219,8 @@ void SplitToOem(std::deque>& events) convertedEvents.push_back(std::move(currentEvent)); } } - // move all events back - while (!convertedEvents.empty()) - { - events.push_back(std::move(convertedEvents.front())); - convertedEvents.pop_front(); - } + + events = std::move(convertedEvents); } // Routine Description: diff --git a/src/host/readDataCooked.cpp b/src/host/readDataCooked.cpp index 6ade6bf5f53..73e6af7eadf 100644 --- a/src/host/readDataCooked.cpp +++ b/src/host/readDataCooked.cpp @@ -128,12 +128,12 @@ COOKED_READ_DATA::~COOKED_READ_DATA() CommandLine::Instance().EndAllPopups(); } -gsl::span COOKED_READ_DATA::SpanWholeBuffer() +std::span COOKED_READ_DATA::SpanWholeBuffer() { - return gsl::make_span(_backupLimit, (_bufferSize / sizeof(wchar_t))); + return std::span{ _backupLimit, (_bufferSize / sizeof(wchar_t)) }; } -gsl::span COOKED_READ_DATA::SpanAtPointer() +std::span COOKED_READ_DATA::SpanAtPointer() { auto wholeSpan = SpanWholeBuffer(); return wholeSpan.subspan(_bufPtr - _backupLimit); diff --git a/src/host/readDataCooked.hpp b/src/host/readDataCooked.hpp index a60b8ca87ba..23096e42b51 100644 --- a/src/host/readDataCooked.hpp +++ b/src/host/readDataCooked.hpp @@ -57,8 +57,8 @@ class COOKED_READ_DATA final : public ReadData _Out_ DWORD* const pControlKeyState, _Out_ void* const pOutputData) override; - gsl::span SpanAtPointer(); - gsl::span SpanWholeBuffer(); + std::span SpanAtPointer(); + std::span SpanWholeBuffer(); size_t Write(const std::wstring_view wstr); diff --git a/src/host/stream.cpp b/src/host/stream.cpp index 23dd8002719..27c91ecc4cc 100644 --- a/src/host/stream.cpp +++ b/src/host/stream.cpp @@ -281,7 +281,7 @@ til::CoordType RetrieveNumberOfSpaces(_In_ til::CoordType sOriginalCursorPositio // - STATUS_NO_MEMORY in low memory situation // - other relevant NTSTATUS codes [[nodiscard]] static NTSTATUS _ReadPendingInput(InputBuffer& inputBuffer, - gsl::span buffer, + std::span buffer, size_t& bytesRead, INPUT_READ_HANDLE_DATA& readHandleState, const bool unicode) @@ -457,7 +457,7 @@ til::CoordType RetrieveNumberOfSpaces(_In_ til::CoordType sOriginalCursorPositio // - other relevant HRESULT codes [[nodiscard]] static HRESULT _ReadLineInput(InputBuffer& inputBuffer, const HANDLE processData, - gsl::span buffer, + std::span buffer, size_t& bytesRead, DWORD& controlKeyState, const std::string_view initialData, @@ -522,7 +522,7 @@ til::CoordType RetrieveNumberOfSpaces(_In_ til::CoordType sOriginalCursorPositio // - STATUS_SUCCESS on success // - Other NTSTATUS codes as necessary [[nodiscard]] static NTSTATUS _ReadCharacterInput(InputBuffer& inputBuffer, - gsl::span buffer, + std::span buffer, size_t& bytesRead, INPUT_READ_HANDLE_DATA& readHandleState, const bool unicode, @@ -682,7 +682,7 @@ til::CoordType RetrieveNumberOfSpaces(_In_ til::CoordType sOriginalCursorPositio // - Other NSTATUS codes as necessary [[nodiscard]] NTSTATUS DoReadConsole(InputBuffer& inputBuffer, const HANDLE processData, - gsl::span buffer, + std::span buffer, size_t& bytesRead, ULONG& controlKeyState, const std::string_view initialData, @@ -742,7 +742,7 @@ til::CoordType RetrieveNumberOfSpaces(_In_ til::CoordType sOriginalCursorPositio } [[nodiscard]] HRESULT ApiRoutines::ReadConsoleAImpl(IConsoleInputObject& context, - gsl::span buffer, + std::span buffer, size_t& written, std::unique_ptr& waiter, const std::string_view initialData, @@ -770,7 +770,7 @@ til::CoordType RetrieveNumberOfSpaces(_In_ til::CoordType sOriginalCursorPositio } [[nodiscard]] HRESULT ApiRoutines::ReadConsoleWImpl(IConsoleInputObject& context, - gsl::span buffer, + std::span buffer, size_t& written, std::unique_ptr& waiter, const std::string_view initialData, diff --git a/src/host/ut_host/ApiRoutinesTests.cpp b/src/host/ut_host/ApiRoutinesTests.cpp index ed46cb3cdc9..90d3fd1044b 100644 --- a/src/host/ut_host/ApiRoutinesTests.cpp +++ b/src/host/ut_host/ApiRoutinesTests.cpp @@ -222,7 +222,7 @@ class ApiRoutinesTests char pszTitle[MAX_PATH]; // most applications use MAX_PATH size_t cchWritten = 0; size_t cchNeeded = 0; - VERIFY_SUCCEEDED(_pApiRoutines->GetConsoleTitleAImpl(gsl::span(pszTitle, ARRAYSIZE(pszTitle)), cchWritten, cchNeeded)); + VERIFY_SUCCEEDED(_pApiRoutines->GetConsoleTitleAImpl(std::span(pszTitle, ARRAYSIZE(pszTitle)), cchWritten, cchNeeded)); VERIFY_ARE_NOT_EQUAL(0u, cchWritten); // NOTE: W version of API returns string length. A version of API returns buffer length (string + null). @@ -239,7 +239,7 @@ class ApiRoutinesTests wchar_t pwszTitle[MAX_PATH]; // most applications use MAX_PATH size_t cchWritten = 0; size_t cchNeeded = 0; - VERIFY_SUCCEEDED(_pApiRoutines->GetConsoleTitleWImpl(gsl::span(pwszTitle, ARRAYSIZE(pwszTitle)), cchWritten, cchNeeded)); + VERIFY_SUCCEEDED(_pApiRoutines->GetConsoleTitleWImpl(std::span(pwszTitle, ARRAYSIZE(pwszTitle)), cchWritten, cchNeeded)); VERIFY_ARE_NOT_EQUAL(0u, cchWritten); @@ -285,7 +285,7 @@ class ApiRoutinesTests char pszTitle[MAX_PATH]; // most applications use MAX_PATH size_t cchWritten = 0; size_t cchNeeded = 0; - VERIFY_SUCCEEDED(_pApiRoutines->GetConsoleOriginalTitleAImpl(gsl::span(pszTitle, ARRAYSIZE(pszTitle)), cchWritten, cchNeeded)); + VERIFY_SUCCEEDED(_pApiRoutines->GetConsoleOriginalTitleAImpl(std::span(pszTitle, ARRAYSIZE(pszTitle)), cchWritten, cchNeeded)); VERIFY_ARE_NOT_EQUAL(0u, cchWritten); // NOTE: W version of API returns string length. A version of API returns buffer length (string + null). @@ -302,7 +302,7 @@ class ApiRoutinesTests wchar_t pwszTitle[MAX_PATH]; // most applications use MAX_PATH size_t cchWritten = 0; size_t cchNeeded = 0; - VERIFY_SUCCEEDED(_pApiRoutines->GetConsoleOriginalTitleWImpl(gsl::span(pwszTitle, ARRAYSIZE(pwszTitle)), cchWritten, cchNeeded)); + VERIFY_SUCCEEDED(_pApiRoutines->GetConsoleOriginalTitleWImpl(std::span(pwszTitle, ARRAYSIZE(pwszTitle)), cchWritten, cchNeeded)); VERIFY_ARE_NOT_EQUAL(0u, cchWritten); diff --git a/src/host/ut_host/DbcsTests.cpp b/src/host/ut_host/DbcsTests.cpp index 012f5a97783..3395c4b00dc 100644 --- a/src/host/ut_host/DbcsTests.cpp +++ b/src/host/ut_host/DbcsTests.cpp @@ -58,7 +58,7 @@ class DbcsTests wchDouble++; } - const gsl::span buffer(rgci, ARRAYSIZE(rgci)); + const std::span buffer(rgci, ARRAYSIZE(rgci)); // feed it into UnicodeRasterFontCellMungeOnRead to confirm that it is working properly. // do it in-place to confirm that it can operate properly in the common case. diff --git a/src/host/ut_host/OutputCellIteratorTests.cpp b/src/host/ut_host/OutputCellIteratorTests.cpp index cb078da228b..8fc2dfa0dd7 100644 --- a/src/host/ut_host/OutputCellIteratorTests.cpp +++ b/src/host/ut_host/OutputCellIteratorTests.cpp @@ -367,7 +367,7 @@ class OutputCellIteratorTests SetVerifyOutput settings(VerifyOutputSettings::LogOnlyFailures); const std::vector colors{ FOREGROUND_GREEN, FOREGROUND_RED | BACKGROUND_BLUE, FOREGROUND_BLUE | FOREGROUND_INTENSITY, BACKGROUND_GREEN }; - const gsl::span view{ colors.data(), colors.size() }; + const std::span view{ colors.data(), colors.size() }; OutputCellIterator it(view); @@ -401,7 +401,7 @@ class OutputCellIteratorTests charInfos.push_back(ci); } - const gsl::span view{ charInfos.data(), charInfos.size() }; + const std::span view{ charInfos.data(), charInfos.size() }; OutputCellIterator it(view); @@ -433,7 +433,7 @@ class OutputCellIteratorTests cells.push_back(cell); } - const gsl::span view{ cells.data(), cells.size() }; + const std::span view{ cells.data(), cells.size() }; OutputCellIterator it(view); diff --git a/src/inc/LibraryIncludes.h b/src/inc/LibraryIncludes.h index 66ee52d5eb8..515f0956ce2 100644 --- a/src/inc/LibraryIncludes.h +++ b/src/inc/LibraryIncludes.h @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -66,7 +67,6 @@ // and uses the C-namespaced "max" which conflicts with Windows definitions. #define GSL_MULTI_SPAN_H #include -#include // CppCoreCheck #include diff --git a/src/inc/conime.h b/src/inc/conime.h index 18ebf245f00..96ca7c3e0b6 100644 --- a/src/inc/conime.h +++ b/src/inc/conime.h @@ -32,8 +32,8 @@ constexpr BYTE CONIME_CURSOR_LEFT = 0x20; [[nodiscard]] HRESULT ImeEndComposition(); [[nodiscard]] HRESULT ImeComposeData(std::wstring_view text, - gsl::span attributes, - gsl::span colorArray); + std::span attributes, + std::span colorArray); [[nodiscard]] HRESULT ImeClearComposeData(); diff --git a/src/inc/til/at.h b/src/inc/til/at.h index 28a715be86b..9b7c804e839 100644 --- a/src/inc/til/at.h +++ b/src/inc/til/at.h @@ -5,53 +5,20 @@ namespace til { - namespace details - { - // This was lifted from gsl::details::is_span. - template - struct is_span_oracle : std::false_type - { - }; - -#ifdef GSL_SPAN_H - template - struct is_span_oracle> : std::true_type - { - }; -#endif - - template - struct is_span : public is_span_oracle> - { - }; - } - // The at function declares that you've already sufficiently checked that your array access // is in range before retrieving an item inside it at an offset. // This is to save double/triple/quadruple testing in circumstances where you are already // pivoting on the length of a set and now want to pull elements out of it by offset // without checking again. // gsl::at will do the check again. As will .at(). And using [] will have a warning in audit. - // This template is explicitly disabled if T is of type gsl::span, as it would interfere with + // This template is explicitly disabled if T is of type std::span, as it would interfere with // the overload below. template constexpr auto at(T&& cont, const I i) noexcept -> decltype(auto) { -#ifdef GSL_SPAN_H - if constexpr (details::is_span::value) - { -#pragma warning(suppress : 26481) // Suppress bounds.1 check for doing pointer arithmetic -#pragma warning(suppress : 26482) // Suppress bounds.2 check for indexing with constant expressions -#pragma warning(suppress : 26446) // Suppress bounds.4 check for subscript operator. - return cont.data()[i]; - } - else -#endif - { #pragma warning(suppress : 26482) // Suppress bounds.2 check for indexing with constant expressions #pragma warning(suppress : 26446) // Suppress bounds.4 check for subscript operator. -#pragma warning(suppress : 26445) // Suppress lifetime check for a reference to gsl::span or std::string_view - return cont[i]; - } +#pragma warning(suppress : 26445) // Suppress lifetime check for a reference to std::span or std::string_view + return cont[i]; } } diff --git a/src/inc/til/bitmap.h b/src/inc/til/bitmap.h index f3527914bf2..438e1b946fb 100644 --- a/src/inc/til/bitmap.h +++ b/src/inc/til/bitmap.h @@ -264,7 +264,7 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned" return const_iterator(_bits, til::rect{ _sz }, _sz.area()); } - const gsl::span runs() const + const std::span runs() const { // If we don't have cached runs, rebuild. if (!_runs.has_value()) diff --git a/src/inc/til/rle.h b/src/inc/til/rle.h index 81a16aa8d45..21f56f100d9 100644 --- a/src/inc/til/rle.h +++ b/src/inc/til/rle.h @@ -473,7 +473,7 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned" // Replace the range [start_index, end_index) with replacements. // If end_index is larger than size() it's set to size(). // start_index must be smaller or equal to end_index. - void replace(size_type start_index, size_type end_index, const gsl::span replacements) + void replace(size_type start_index, size_type end_index, const std::span replacements) { _check_indices(start_index, end_index); _replace_unchecked(start_index, end_index, replacements); @@ -692,7 +692,7 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned" } // Replace the range [start_index, end_index) with replacements. - void _replace_unchecked(size_type start_index, size_type end_index, const gsl::span replacements) + void _replace_unchecked(size_type start_index, size_type end_index, const std::span replacements) { // // diff --git a/src/interactivity/base/HostSignalInputThread.cpp b/src/interactivity/base/HostSignalInputThread.cpp index bed01bbd013..9ea9cefff5b 100644 --- a/src/interactivity/base/HostSignalInputThread.cpp +++ b/src/interactivity/base/HostSignalInputThread.cpp @@ -56,7 +56,7 @@ template T HostSignalInputThread::_ReceiveTypedPacket() { T msg = { 0 }; - THROW_HR_IF(E_ABORT, !_GetData(gsl::as_writable_bytes(gsl::span{ &msg, 1 }))); + THROW_HR_IF(E_ABORT, !_GetData(std::as_writable_bytes(std::span{ &msg, 1 }))); // If the message is smaller than what we expected // then it was malformed and we need to throw. @@ -80,7 +80,7 @@ T HostSignalInputThread::_ReceiveTypedPacket() { HostSignals signalId; - while (_GetData(gsl::as_writable_bytes(gsl::span{ &signalId, 1 }))) + while (_GetData(std::as_writable_bytes(std::span{ &signalId, 1 }))) { switch (signalId) { @@ -128,7 +128,7 @@ T HostSignalInputThread::_ReceiveTypedPacket() // - True if we could skip forward successfully. False otherwise. bool HostSignalInputThread::_AdvanceReader(DWORD byteCount) { - std::array buffer; + std::array buffer; while (byteCount > 0) { @@ -152,7 +152,7 @@ bool HostSignalInputThread::_AdvanceReader(DWORD byteCount) // - buffer - Buffer to fill with data. // Return Value: // - True if data was retrieved successfully. False otherwise. -bool HostSignalInputThread::_GetData(gsl::span buffer) +bool HostSignalInputThread::_GetData(std::span buffer) { DWORD bytesRead = 0; // If we failed to read because the terminal broke our pipe (usually due diff --git a/src/interactivity/base/HostSignalInputThread.hpp b/src/interactivity/base/HostSignalInputThread.hpp index 429e492955b..71deef02e62 100644 --- a/src/interactivity/base/HostSignalInputThread.hpp +++ b/src/interactivity/base/HostSignalInputThread.hpp @@ -37,7 +37,7 @@ namespace Microsoft::Console T _ReceiveTypedPacket(); [[nodiscard]] HRESULT _InputThread(); - bool _GetData(gsl::span buffer); + bool _GetData(std::span buffer); bool _AdvanceReader(DWORD byteCount); void _Shutdown(); diff --git a/src/interactivity/onecore/BgfxEngine.cpp b/src/interactivity/onecore/BgfxEngine.cpp index 12d3c76f3f5..12c6de82e49 100644 --- a/src/interactivity/onecore/BgfxEngine.cpp +++ b/src/interactivity/onecore/BgfxEngine.cpp @@ -126,7 +126,7 @@ CATCH_RETURN() return S_OK; } -[[nodiscard]] HRESULT BgfxEngine::PaintBufferLine(const gsl::span clusters, +[[nodiscard]] HRESULT BgfxEngine::PaintBufferLine(const std::span clusters, const til::point coord, const bool /*trimLeft*/, const bool /*lineWrapped*/) noexcept @@ -215,7 +215,7 @@ CATCH_RETURN() return S_OK; } -[[nodiscard]] HRESULT BgfxEngine::GetDirtyArea(gsl::span& area) noexcept +[[nodiscard]] HRESULT BgfxEngine::GetDirtyArea(std::span& area) noexcept { _dirtyArea.bottom = gsl::narrow_cast(std::max(static_cast(0), _displayHeight)); _dirtyArea.right = gsl::narrow_cast(std::max(static_cast(0), _displayWidth)); diff --git a/src/interactivity/onecore/BgfxEngine.hpp b/src/interactivity/onecore/BgfxEngine.hpp index 00476d805f1..31fa49c8522 100644 --- a/src/interactivity/onecore/BgfxEngine.hpp +++ b/src/interactivity/onecore/BgfxEngine.hpp @@ -47,7 +47,7 @@ namespace Microsoft::Console::Render [[nodiscard]] HRESULT ScrollFrame() noexcept override; [[nodiscard]] HRESULT PaintBackground() noexcept override; - [[nodiscard]] HRESULT PaintBufferLine(const gsl::span clusters, + [[nodiscard]] HRESULT PaintBufferLine(const std::span clusters, const til::point coord, const bool trimLeft, const bool lineWrapped) noexcept override; @@ -67,7 +67,7 @@ namespace Microsoft::Console::Render [[nodiscard]] HRESULT GetProposedFont(const FontInfoDesired& fiFontInfoDesired, FontInfo& fiFontInfo, const int iDpi) noexcept override; - [[nodiscard]] HRESULT GetDirtyArea(gsl::span& area) noexcept override; + [[nodiscard]] HRESULT GetDirtyArea(std::span& area) noexcept override; [[nodiscard]] HRESULT GetFontSize(_Out_ til::size* pFontSize) noexcept override; [[nodiscard]] HRESULT IsGlyphWideByFont(const std::wstring_view glyph, _Out_ bool* const pResult) noexcept override; diff --git a/src/interactivity/win32/windowio.cpp b/src/interactivity/win32/windowio.cpp index de21356a799..0f4263282e1 100644 --- a/src/interactivity/win32/windowio.cpp +++ b/src/interactivity/win32/windowio.cpp @@ -209,7 +209,7 @@ void HandleKeyEvent(const HWND hWnd, } else { - keyEvent.SetCharData(0); + keyEvent.SetCharData(L'\0'); } } else @@ -220,7 +220,7 @@ void HandleKeyEvent(const HWND hWnd, return; } keyEvent.SetActiveModifierKeys(ControlKeyState); - keyEvent.SetCharData(0); + keyEvent.SetCharData(L'\0'); } const INPUT_KEY_INFO inputKeyInfo(VirtualKeyCode, ControlKeyState); diff --git a/src/renderer/atlas/AtlasEngine.api.cpp b/src/renderer/atlas/AtlasEngine.api.cpp index d9871debc6c..777802e1117 100644 --- a/src/renderer/atlas/AtlasEngine.api.cpp +++ b/src/renderer/atlas/AtlasEngine.api.cpp @@ -159,7 +159,7 @@ constexpr HRESULT vec2_narrow(U x, U y, AtlasEngine::vec2& out) noexcept return UpdateFont(fontInfoDesired, fontInfo, {}, {}); } -[[nodiscard]] HRESULT AtlasEngine::UpdateSoftFont(const gsl::span bitPattern, const til::size cellSize, const size_t centeringHint) noexcept +[[nodiscard]] HRESULT AtlasEngine::UpdateSoftFont(const std::span bitPattern, const til::size cellSize, const size_t centeringHint) noexcept { return S_OK; } @@ -254,9 +254,9 @@ try } CATCH_RETURN() -[[nodiscard]] HRESULT AtlasEngine::GetDirtyArea(gsl::span& area) noexcept +[[nodiscard]] HRESULT AtlasEngine::GetDirtyArea(std::span& area) noexcept { - area = gsl::span{ &_api.dirtyRect, 1 }; + area = std::span{ &_api.dirtyRect, 1 }; return S_OK; } diff --git a/src/renderer/atlas/AtlasEngine.cpp b/src/renderer/atlas/AtlasEngine.cpp index c9ff2327d2b..dd26ac928b2 100644 --- a/src/renderer/atlas/AtlasEngine.cpp +++ b/src/renderer/atlas/AtlasEngine.cpp @@ -342,7 +342,7 @@ CATCH_RETURN() return S_OK; } -[[nodiscard]] HRESULT AtlasEngine::PaintBufferLine(gsl::span clusters, til::point coord, const bool fTrimLeft, const bool lineWrapped) noexcept +[[nodiscard]] HRESULT AtlasEngine::PaintBufferLine(std::span clusters, til::point coord, const bool fTrimLeft, const bool lineWrapped) noexcept try { const auto y = gsl::narrow_cast(clamp(coord.y, 0, _api.cellCount.y)); diff --git a/src/renderer/atlas/AtlasEngine.h b/src/renderer/atlas/AtlasEngine.h index f463a000575..fd8523e9373 100644 --- a/src/renderer/atlas/AtlasEngine.h +++ b/src/renderer/atlas/AtlasEngine.h @@ -43,17 +43,17 @@ namespace Microsoft::Console::Render [[nodiscard]] HRESULT ResetLineTransform() noexcept override; [[nodiscard]] HRESULT PrepareLineTransform(LineRendition lineRendition, til::CoordType targetRow, til::CoordType viewportLeft) noexcept override; [[nodiscard]] HRESULT PaintBackground() noexcept override; - [[nodiscard]] HRESULT PaintBufferLine(gsl::span clusters, til::point coord, bool fTrimLeft, bool lineWrapped) noexcept override; + [[nodiscard]] HRESULT PaintBufferLine(std::span clusters, til::point coord, bool fTrimLeft, bool lineWrapped) noexcept override; [[nodiscard]] HRESULT PaintBufferGridLines(GridLineSet lines, COLORREF color, size_t cchLine, til::point coordTarget) noexcept override; [[nodiscard]] HRESULT PaintSelection(const til::rect& rect) noexcept override; [[nodiscard]] HRESULT PaintCursor(const CursorOptions& options) noexcept override; [[nodiscard]] HRESULT UpdateDrawingBrushes(const TextAttribute& textAttributes, const RenderSettings& renderSettings, gsl::not_null pData, bool usingSoftFont, bool isSettingDefaultBrushes) noexcept override; [[nodiscard]] HRESULT UpdateFont(const FontInfoDesired& FontInfoDesired, _Out_ FontInfo& FontInfo) noexcept override; - [[nodiscard]] HRESULT UpdateSoftFont(gsl::span bitPattern, til::size cellSize, size_t centeringHint) noexcept override; + [[nodiscard]] HRESULT UpdateSoftFont(std::span bitPattern, til::size cellSize, size_t centeringHint) noexcept override; [[nodiscard]] HRESULT UpdateDpi(int iDpi) noexcept override; [[nodiscard]] HRESULT UpdateViewport(const til::inclusive_rect& srNewViewport) noexcept override; [[nodiscard]] HRESULT GetProposedFont(const FontInfoDesired& FontInfoDesired, _Out_ FontInfo& FontInfo, int iDpi) noexcept override; - [[nodiscard]] HRESULT GetDirtyArea(gsl::span& area) noexcept override; + [[nodiscard]] HRESULT GetDirtyArea(std::span& area) noexcept override; [[nodiscard]] HRESULT GetFontSize(_Out_ til::size* pFontSize) noexcept override; [[nodiscard]] HRESULT IsGlyphWideByFont(std::wstring_view glyph, _Out_ bool* pResult) noexcept override; [[nodiscard]] HRESULT UpdateTitle(std::wstring_view newTitle) noexcept override; diff --git a/src/renderer/atlas/pch.h b/src/renderer/atlas/pch.h index a436ae580af..f80306b1ea3 100644 --- a/src/renderer/atlas/pch.h +++ b/src/renderer/atlas/pch.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -27,7 +28,6 @@ #include #include -#include #include #include #include diff --git a/src/renderer/base/FontResource.cpp b/src/renderer/base/FontResource.cpp index 465317e9ff0..9a93582bc37 100644 --- a/src/renderer/base/FontResource.cpp +++ b/src/renderer/base/FontResource.cpp @@ -76,7 +76,7 @@ namespace #pragma pack(pop) } -FontResource::FontResource(const gsl::span bitPattern, +FontResource::FontResource(const std::span bitPattern, const til::size sourceSize, const til::size targetSize, const size_t centeringHint) : @@ -149,7 +149,7 @@ void FontResource::_regenerateFont() // Raster fonts aren't generally scalable, so we need to resize the bit // patterns for the character glyphs to the requested target size, and // copy the results into the resource structure. - auto fontResourceSpan = gsl::span(fontResourceBuffer); + auto fontResourceSpan = std::span(fontResourceBuffer); _resizeBitPattern(fontResourceSpan.subspan(fontResource.dfBitsOffset)); DWORD fontCount = 0; @@ -169,7 +169,7 @@ void FontResource::_regenerateFont() LOG_HR_IF_NULL(E_FAIL, _fontHandle.get()); } -void FontResource::_resizeBitPattern(gsl::span targetBuffer) +void FontResource::_resizeBitPattern(std::span targetBuffer) { auto sourceWidth = _sourceSize.width; auto targetWidth = _targetSize.width; diff --git a/src/renderer/base/RenderEngineBase.cpp b/src/renderer/base/RenderEngineBase.cpp index 988aaf6690b..80c1f86cda1 100644 --- a/src/renderer/base/RenderEngineBase.cpp +++ b/src/renderer/base/RenderEngineBase.cpp @@ -35,7 +35,7 @@ HRESULT RenderEngineBase::NotifyNewText(const std::wstring_view /*newText*/) noe return S_FALSE; } -HRESULT RenderEngineBase::UpdateSoftFont(const gsl::span /*bitPattern*/, +HRESULT RenderEngineBase::UpdateSoftFont(const std::span /*bitPattern*/, const til::size /*cellSize*/, const size_t /*centeringHint*/) noexcept { diff --git a/src/renderer/base/renderer.cpp b/src/renderer/base/renderer.cpp index 8f7332597c8..0739a9281bb 100644 --- a/src/renderer/base/renderer.cpp +++ b/src/renderer/base/renderer.cpp @@ -544,7 +544,7 @@ void Renderer::TriggerFontChange(const int iDpi, const FontInfoDesired& FontInfo // - centeringHint - The horizontal extent that glyphs are offset from center. // Return Value: // - -void Renderer::UpdateSoftFont(const gsl::span bitPattern, const til::size cellSize, const size_t centeringHint) +void Renderer::UpdateSoftFont(const std::span bitPattern, const til::size cellSize, const size_t centeringHint) { // We reserve PUA code points U+EF20 to U+EF7F for soft fonts, but the range // that we test for in _IsSoftFontChar will depend on the size of the active @@ -687,7 +687,7 @@ void Renderer::_PaintBufferOutput(_In_ IRenderEngine* const pEngine) // This is effectively the number of cells on the visible screen that need to be redrawn. // The origin is always 0, 0 because it represents the screen itself, not the underlying buffer. - gsl::span dirtyAreas; + std::span dirtyAreas; LOG_IF_FAILED(pEngine->GetDirtyArea(dirtyAreas)); // This is to make sure any transforms are reset when this paint is finished. @@ -1127,7 +1127,7 @@ void Renderer::_PaintOverlay(IRenderEngine& engine, srCaView.left += overlay.origin.x; srCaView.right += overlay.origin.x; - gsl::span dirtyAreas; + std::span dirtyAreas; LOG_IF_FAILED(engine.GetDirtyArea(dirtyAreas)); for (const auto& rect : dirtyAreas) @@ -1181,7 +1181,7 @@ void Renderer::_PaintSelection(_In_ IRenderEngine* const pEngine) { try { - gsl::span dirtyAreas; + std::span dirtyAreas; LOG_IF_FAILED(pEngine->GetDirtyArea(dirtyAreas)); // Get selection rectangles diff --git a/src/renderer/base/renderer.hpp b/src/renderer/base/renderer.hpp index abb3641ef89..f85b279abeb 100644 --- a/src/renderer/base/renderer.hpp +++ b/src/renderer/base/renderer.hpp @@ -67,7 +67,7 @@ namespace Microsoft::Console::Render const FontInfoDesired& FontInfoDesired, _Out_ FontInfo& FontInfo); - void UpdateSoftFont(const gsl::span bitPattern, + void UpdateSoftFont(const std::span bitPattern, const til::size cellSize, const size_t centeringHint); diff --git a/src/renderer/dx/CustomTextLayout.cpp b/src/renderer/dx/CustomTextLayout.cpp index c6f479dbc4b..695cf04791f 100644 --- a/src/renderer/dx/CustomTextLayout.cpp +++ b/src/renderer/dx/CustomTextLayout.cpp @@ -65,7 +65,7 @@ CATCH_RETURN() // - clusters - From the backing buffer, the text to be displayed clustered by the columns it should consume. // Return Value: // - S_OK or suitable memory management issue. -[[nodiscard]] HRESULT STDMETHODCALLTYPE CustomTextLayout::AppendClusters(const gsl::span clusters) +[[nodiscard]] HRESULT STDMETHODCALLTYPE CustomTextLayout::AppendClusters(const std::span clusters) try { _textClusterColumns.reserve(_textClusterColumns.size() + clusters.size()); diff --git a/src/renderer/dx/CustomTextLayout.h b/src/renderer/dx/CustomTextLayout.h index 1fe93810b55..4ea4da0f4d9 100644 --- a/src/renderer/dx/CustomTextLayout.h +++ b/src/renderer/dx/CustomTextLayout.h @@ -23,7 +23,7 @@ namespace Microsoft::Console::Render CustomTextLayout(const gsl::not_null fontRenderData); - [[nodiscard]] HRESULT STDMETHODCALLTYPE AppendClusters(const gsl::span clusters); + [[nodiscard]] HRESULT STDMETHODCALLTYPE AppendClusters(const std::span clusters); [[nodiscard]] HRESULT STDMETHODCALLTYPE Reset() noexcept; diff --git a/src/renderer/dx/CustomTextRenderer.cpp b/src/renderer/dx/CustomTextRenderer.cpp index 6e6acd6460f..515f4a3dab6 100644 --- a/src/renderer/dx/CustomTextRenderer.cpp +++ b/src/renderer/dx/CustomTextRenderer.cpp @@ -540,7 +540,7 @@ CATCH_RETURN() // Draw the background // The rectangle needs to be deduced based on the origin and the BidiDirection - const auto advancesSpan = gsl::make_span(glyphRun->glyphAdvances, glyphRun->glyphCount); + const auto advancesSpan = std::span{ glyphRun->glyphAdvances, glyphRun->glyphCount }; const auto totalSpan = std::accumulate(advancesSpan.begin(), advancesSpan.end(), 0.0f); D2D1_RECT_F rect; diff --git a/src/renderer/dx/DxFontRenderData.cpp b/src/renderer/dx/DxFontRenderData.cpp index b2444bb8251..d33f5f25d02 100644 --- a/src/renderer/dx/DxFontRenderData.cpp +++ b/src/renderer/dx/DxFontRenderData.cpp @@ -573,7 +573,7 @@ void DxFontRenderData::_SetAxes(const std::unordered_map _axesVector; - gsl::span _axesVectorWithoutWeight; + std::span _axesVectorWithoutWeight; // We use this to identify font variants with different attributes. static FontAttributeMapKey _ToMapKey(DWRITE_FONT_WEIGHT weight, DWRITE_FONT_STYLE style, DWRITE_FONT_STRETCH stretch) noexcept diff --git a/src/renderer/dx/DxRenderer.cpp b/src/renderer/dx/DxRenderer.cpp index ed5234fc5bd..70e6e01806e 100644 --- a/src/renderer/dx/DxRenderer.cpp +++ b/src/renderer/dx/DxRenderer.cpp @@ -1663,7 +1663,7 @@ CATCH_RETURN() // - fTrimLeft - Whether or not to trim off the left half of a double wide character // Return Value: // - S_OK or relevant DirectX error -[[nodiscard]] HRESULT DxEngine::PaintBufferLine(const gsl::span clusters, +[[nodiscard]] HRESULT DxEngine::PaintBufferLine(const std::span clusters, const til::point coord, const bool /*trimLeft*/, const bool /*lineWrapped*/) noexcept @@ -2112,7 +2112,7 @@ CATCH_RETURN(); // - area - Rectangle describing dirty area in characters. // Return Value: // - S_OK -[[nodiscard]] HRESULT DxEngine::GetDirtyArea(gsl::span& area) noexcept +[[nodiscard]] HRESULT DxEngine::GetDirtyArea(std::span& area) noexcept try { area = _invalidMap.runs(); @@ -2286,7 +2286,7 @@ void DxEngine::UpdateHyperlinkHoveredId(const uint16_t hoveredId) noexcept // - centeringHint - The horizontal extent that glyphs are offset from center. // Return Value: // - S_OK if successful. E_FAIL if there was an error. -HRESULT DxEngine::UpdateSoftFont(const gsl::span bitPattern, +HRESULT DxEngine::UpdateSoftFont(const std::span bitPattern, const til::size cellSize, const size_t centeringHint) noexcept try diff --git a/src/renderer/dx/DxRenderer.hpp b/src/renderer/dx/DxRenderer.hpp index d3242d2a98f..9dc9fdff741 100644 --- a/src/renderer/dx/DxRenderer.hpp +++ b/src/renderer/dx/DxRenderer.hpp @@ -89,7 +89,7 @@ namespace Microsoft::Console::Render [[nodiscard]] HRESULT ScrollFrame() noexcept override; - [[nodiscard]] HRESULT UpdateSoftFont(const gsl::span bitPattern, + [[nodiscard]] HRESULT UpdateSoftFont(const std::span bitPattern, const til::size cellSize, const size_t centeringHint) noexcept override; @@ -101,7 +101,7 @@ namespace Microsoft::Console::Render const til::CoordType viewportLeft) noexcept override; [[nodiscard]] HRESULT PaintBackground() noexcept override; - [[nodiscard]] HRESULT PaintBufferLine(const gsl::span clusters, + [[nodiscard]] HRESULT PaintBufferLine(const std::span clusters, const til::point coord, const bool fTrimLeft, const bool lineWrapped) noexcept override; @@ -123,7 +123,7 @@ namespace Microsoft::Console::Render [[nodiscard]] HRESULT GetProposedFont(const FontInfoDesired& fiFontInfoDesired, FontInfo& fiFontInfo, const int iDpi) noexcept override; - [[nodiscard]] HRESULT GetDirtyArea(gsl::span& area) noexcept override; + [[nodiscard]] HRESULT GetDirtyArea(std::span& area) noexcept override; [[nodiscard]] HRESULT GetFontSize(_Out_ til::size* pFontSize) noexcept override; [[nodiscard]] HRESULT IsGlyphWideByFont(const std::wstring_view glyph, _Out_ bool* const pResult) noexcept override; diff --git a/src/renderer/dx/DxSoftFont.cpp b/src/renderer/dx/DxSoftFont.cpp index f9c01155a5e..f1435644d8e 100644 --- a/src/renderer/dx/DxSoftFont.cpp +++ b/src/renderer/dx/DxSoftFont.cpp @@ -34,7 +34,7 @@ DxSoftFont::DxSoftFont() noexcept : _colorMatrix.m[0][3] = 1; } -void DxSoftFont::SetFont(const gsl::span bitPattern, +void DxSoftFont::SetFont(const std::span bitPattern, const til::size sourceSize, const til::size targetSize, const size_t centeringHint) @@ -141,7 +141,7 @@ HRESULT DxSoftFont::SetColor(const D2D1_COLOR_F& color) } HRESULT DxSoftFont::Draw(const DrawingContext& drawingContext, - const gsl::span clusters, + const std::span clusters, const float originX, const float originY) { diff --git a/src/renderer/dx/DxSoftFont.h b/src/renderer/dx/DxSoftFont.h index 718861902a9..f6c47cc41b2 100644 --- a/src/renderer/dx/DxSoftFont.h +++ b/src/renderer/dx/DxSoftFont.h @@ -7,7 +7,6 @@ #include #include -#include #include #include @@ -19,7 +18,7 @@ namespace Microsoft::Console::Render { public: DxSoftFont() noexcept; - void SetFont(const gsl::span bitPattern, + void SetFont(const std::span bitPattern, const til::size sourceSize, const til::size targetSize, const size_t centeringHint); @@ -27,7 +26,7 @@ namespace Microsoft::Console::Render HRESULT SetAntialiasing(const bool antialiased); HRESULT SetColor(const D2D1_COLOR_F& color); HRESULT Draw(const DrawingContext& drawingContext, - const gsl::span clusters, + const std::span clusters, const float originX, const float originY); void Reset(); diff --git a/src/renderer/gdi/gdirenderer.hpp b/src/renderer/gdi/gdirenderer.hpp index 0eeb0486225..a1ab2290a97 100644 --- a/src/renderer/gdi/gdirenderer.hpp +++ b/src/renderer/gdi/gdirenderer.hpp @@ -47,7 +47,7 @@ namespace Microsoft::Console::Render const til::CoordType viewportLeft) noexcept override; [[nodiscard]] HRESULT PaintBackground() noexcept override; - [[nodiscard]] HRESULT PaintBufferLine(const gsl::span clusters, + [[nodiscard]] HRESULT PaintBufferLine(const std::span clusters, const til::point coord, const bool trimLeft, const bool lineWrapped) noexcept override; @@ -66,7 +66,7 @@ namespace Microsoft::Console::Render const bool isSettingDefaultBrushes) noexcept override; [[nodiscard]] HRESULT UpdateFont(const FontInfoDesired& FontInfoDesired, _Out_ FontInfo& FontInfo) noexcept override; - [[nodiscard]] HRESULT UpdateSoftFont(const gsl::span bitPattern, + [[nodiscard]] HRESULT UpdateSoftFont(const std::span bitPattern, const til::size cellSize, const size_t centeringHint) noexcept override; [[nodiscard]] HRESULT UpdateDpi(const int iDpi) noexcept override; @@ -76,7 +76,7 @@ namespace Microsoft::Console::Render _Out_ FontInfo& Font, const int iDpi) noexcept override; - [[nodiscard]] HRESULT GetDirtyArea(gsl::span& area) noexcept override; + [[nodiscard]] HRESULT GetDirtyArea(std::span& area) noexcept override; [[nodiscard]] HRESULT GetFontSize(_Out_ til::size* const pFontSize) noexcept override; [[nodiscard]] HRESULT IsGlyphWideByFont(const std::wstring_view glyph, _Out_ bool* const pResult) noexcept override; diff --git a/src/renderer/gdi/math.cpp b/src/renderer/gdi/math.cpp index 4c25eefd338..eb5c845ff58 100644 --- a/src/renderer/gdi/math.cpp +++ b/src/renderer/gdi/math.cpp @@ -16,7 +16,7 @@ using namespace Microsoft::Console::Render; // This is an Inclusive rect. // Return Value: // - S_OK or math failure -[[nodiscard]] HRESULT GdiEngine::GetDirtyArea(gsl::span& area) noexcept +[[nodiscard]] HRESULT GdiEngine::GetDirtyArea(std::span& area) noexcept { _invalidCharacters = til::rect{ _psInvalidData.rcPaint }.scale_down(_GetFontSize()); diff --git a/src/renderer/gdi/paint.cpp b/src/renderer/gdi/paint.cpp index aff91e7c31b..17dc9bddd82 100644 --- a/src/renderer/gdi/paint.cpp +++ b/src/renderer/gdi/paint.cpp @@ -322,7 +322,7 @@ bool GdiEngine::FontHasWesternScript(HDC hdc) // See: Win7: 390673, 447839 and then superseded by http://osgvsowi/638274 when FE/non-FE rendering condensed. //#define CONSOLE_EXTTEXTOUT_FLAGS ETO_OPAQUE | ETO_CLIPPED //#define MAX_POLY_LINES 80 -[[nodiscard]] HRESULT GdiEngine::PaintBufferLine(const gsl::span clusters, +[[nodiscard]] HRESULT GdiEngine::PaintBufferLine(const std::span clusters, const til::point coord, const bool trimLeft, const bool /*lineWrapped*/) noexcept diff --git a/src/renderer/gdi/state.cpp b/src/renderer/gdi/state.cpp index b8dc10e45bb..556f2df02fb 100644 --- a/src/renderer/gdi/state.cpp +++ b/src/renderer/gdi/state.cpp @@ -440,7 +440,7 @@ GdiEngine::~GdiEngine() // - centeringHint - The horizontal extent that glyphs are offset from center. // Return Value: // - S_OK if successful. E_FAIL if there was an error. -[[nodiscard]] HRESULT GdiEngine::UpdateSoftFont(const gsl::span bitPattern, +[[nodiscard]] HRESULT GdiEngine::UpdateSoftFont(const std::span bitPattern, const til::size cellSize, const size_t centeringHint) noexcept { diff --git a/src/renderer/inc/FontResource.hpp b/src/renderer/inc/FontResource.hpp index aa159ed3461..b76fb7f0e2d 100644 --- a/src/renderer/inc/FontResource.hpp +++ b/src/renderer/inc/FontResource.hpp @@ -21,7 +21,7 @@ namespace Microsoft::Console::Render class FontResource { public: - FontResource(const gsl::span bitPattern, + FontResource(const std::span bitPattern, const til::size sourceSize, const til::size targetSize, const size_t centeringHint); @@ -33,7 +33,7 @@ namespace Microsoft::Console::Render private: void _regenerateFont(); - void _resizeBitPattern(gsl::span targetBuffer); + void _resizeBitPattern(std::span targetBuffer); std::vector _bitPattern; til::size _sourceSize; diff --git a/src/renderer/inc/IRenderEngine.hpp b/src/renderer/inc/IRenderEngine.hpp index 06a756c627c..281c0d2a484 100644 --- a/src/renderer/inc/IRenderEngine.hpp +++ b/src/renderer/inc/IRenderEngine.hpp @@ -72,17 +72,17 @@ namespace Microsoft::Console::Render [[nodiscard]] virtual HRESULT ResetLineTransform() noexcept = 0; [[nodiscard]] virtual HRESULT PrepareLineTransform(LineRendition lineRendition, til::CoordType targetRow, til::CoordType viewportLeft) noexcept = 0; [[nodiscard]] virtual HRESULT PaintBackground() noexcept = 0; - [[nodiscard]] virtual HRESULT PaintBufferLine(gsl::span clusters, til::point coord, bool fTrimLeft, bool lineWrapped) noexcept = 0; + [[nodiscard]] virtual HRESULT PaintBufferLine(std::span clusters, til::point coord, bool fTrimLeft, bool lineWrapped) noexcept = 0; [[nodiscard]] virtual HRESULT PaintBufferGridLines(GridLineSet lines, COLORREF color, size_t cchLine, til::point coordTarget) noexcept = 0; [[nodiscard]] virtual HRESULT PaintSelection(const til::rect& rect) noexcept = 0; [[nodiscard]] virtual HRESULT PaintCursor(const CursorOptions& options) noexcept = 0; [[nodiscard]] virtual HRESULT UpdateDrawingBrushes(const TextAttribute& textAttributes, const RenderSettings& renderSettings, gsl::not_null pData, bool usingSoftFont, bool isSettingDefaultBrushes) noexcept = 0; [[nodiscard]] virtual HRESULT UpdateFont(const FontInfoDesired& FontInfoDesired, _Out_ FontInfo& FontInfo) noexcept = 0; - [[nodiscard]] virtual HRESULT UpdateSoftFont(gsl::span bitPattern, til::size cellSize, size_t centeringHint) noexcept = 0; + [[nodiscard]] virtual HRESULT UpdateSoftFont(std::span bitPattern, til::size cellSize, size_t centeringHint) noexcept = 0; [[nodiscard]] virtual HRESULT UpdateDpi(int iDpi) noexcept = 0; [[nodiscard]] virtual HRESULT UpdateViewport(const til::inclusive_rect& srNewViewport) noexcept = 0; [[nodiscard]] virtual HRESULT GetProposedFont(const FontInfoDesired& FontInfoDesired, _Out_ FontInfo& FontInfo, int iDpi) noexcept = 0; - [[nodiscard]] virtual HRESULT GetDirtyArea(gsl::span& area) noexcept = 0; + [[nodiscard]] virtual HRESULT GetDirtyArea(std::span& area) noexcept = 0; [[nodiscard]] virtual HRESULT GetFontSize(_Out_ til::size* pFontSize) noexcept = 0; [[nodiscard]] virtual HRESULT IsGlyphWideByFont(std::wstring_view glyph, _Out_ bool* pResult) noexcept = 0; [[nodiscard]] virtual HRESULT UpdateTitle(std::wstring_view newTitle) noexcept = 0; diff --git a/src/renderer/inc/RenderEngineBase.hpp b/src/renderer/inc/RenderEngineBase.hpp index eea90051021..0091df64466 100644 --- a/src/renderer/inc/RenderEngineBase.hpp +++ b/src/renderer/inc/RenderEngineBase.hpp @@ -30,7 +30,7 @@ namespace Microsoft::Console::Render [[nodiscard]] HRESULT NotifyNewText(const std::wstring_view newText) noexcept override; - [[nodiscard]] HRESULT UpdateSoftFont(const gsl::span bitPattern, + [[nodiscard]] HRESULT UpdateSoftFont(const std::span bitPattern, const til::size cellSize, const size_t centeringHint) noexcept override; diff --git a/src/renderer/uia/UiaRenderer.cpp b/src/renderer/uia/UiaRenderer.cpp index 206f2193a86..e58c227c561 100644 --- a/src/renderer/uia/UiaRenderer.cpp +++ b/src/renderer/uia/UiaRenderer.cpp @@ -334,7 +334,7 @@ void UiaEngine::WaitUntilCanRender() noexcept // - fTrimLeft - Whether or not to trim off the left half of a double wide character // Return Value: // - S_FALSE -[[nodiscard]] HRESULT UiaEngine::PaintBufferLine(const gsl::span /*clusters*/, +[[nodiscard]] HRESULT UiaEngine::PaintBufferLine(const std::span /*clusters*/, const til::point /*coord*/, const bool /*trimLeft*/, const bool /*lineWrapped*/) noexcept @@ -463,7 +463,7 @@ void UiaEngine::WaitUntilCanRender() noexcept // - area - Rectangle describing dirty area in characters. // Return Value: // - S_OK. -[[nodiscard]] HRESULT UiaEngine::GetDirtyArea(gsl::span& area) noexcept +[[nodiscard]] HRESULT UiaEngine::GetDirtyArea(std::span& area) noexcept { // Magic static is only valid because any instance of this object has the same behavior. // Use member variable instead if this ever changes. diff --git a/src/renderer/uia/UiaRenderer.hpp b/src/renderer/uia/UiaRenderer.hpp index 16a6ae6630c..5e486b7e0e1 100644 --- a/src/renderer/uia/UiaRenderer.hpp +++ b/src/renderer/uia/UiaRenderer.hpp @@ -48,7 +48,7 @@ namespace Microsoft::Console::Render [[nodiscard]] HRESULT InvalidateAll() noexcept override; [[nodiscard]] HRESULT NotifyNewText(const std::wstring_view newText) noexcept override; [[nodiscard]] HRESULT PaintBackground() noexcept override; - [[nodiscard]] HRESULT PaintBufferLine(const gsl::span clusters, const til::point coord, const bool fTrimLeft, const bool lineWrapped) noexcept override; + [[nodiscard]] HRESULT PaintBufferLine(const std::span clusters, const til::point coord, const bool fTrimLeft, const bool lineWrapped) noexcept override; [[nodiscard]] HRESULT PaintBufferGridLines(const GridLineSet lines, const COLORREF color, const size_t cchLine, const til::point coordTarget) noexcept override; [[nodiscard]] HRESULT PaintSelection(const til::rect& rect) noexcept override; [[nodiscard]] HRESULT PaintCursor(const CursorOptions& options) noexcept override; @@ -57,7 +57,7 @@ namespace Microsoft::Console::Render [[nodiscard]] HRESULT UpdateDpi(const int iDpi) noexcept override; [[nodiscard]] HRESULT UpdateViewport(const til::inclusive_rect& srNewViewport) noexcept override; [[nodiscard]] HRESULT GetProposedFont(const FontInfoDesired& FontInfoDesired, _Out_ FontInfo& FontInfo, const int iDpi) noexcept override; - [[nodiscard]] HRESULT GetDirtyArea(gsl::span& area) noexcept override; + [[nodiscard]] HRESULT GetDirtyArea(std::span& area) noexcept override; [[nodiscard]] HRESULT GetFontSize(_Out_ til::size* const pFontSize) noexcept override; [[nodiscard]] HRESULT IsGlyphWideByFont(const std::wstring_view glyph, _Out_ bool* const pResult) noexcept override; diff --git a/src/renderer/vt/XtermEngine.cpp b/src/renderer/vt/XtermEngine.cpp index 13bcca7ab04..33847e6106a 100644 --- a/src/renderer/vt/XtermEngine.cpp +++ b/src/renderer/vt/XtermEngine.cpp @@ -69,7 +69,7 @@ XtermEngine::XtermEngine(_In_ wil::unique_hfile hPipe, } else { - gsl::span dirty; + std::span dirty; RETURN_IF_FAILED(GetDirtyArea(dirty)); // If we have 0 or 1 dirty pieces in the area, set as appropriate. @@ -504,7 +504,7 @@ CATCH_RETURN(); // will be false. // Return Value: // - S_OK or suitable HRESULT error from writing pipe. -[[nodiscard]] HRESULT XtermEngine::PaintBufferLine(const gsl::span clusters, +[[nodiscard]] HRESULT XtermEngine::PaintBufferLine(const std::span clusters, const til::point coord, const bool /*trimLeft*/, const bool lineWrapped) noexcept diff --git a/src/renderer/vt/XtermEngine.hpp b/src/renderer/vt/XtermEngine.hpp index c3a1af5f8b4..6f1b480b61e 100644 --- a/src/renderer/vt/XtermEngine.hpp +++ b/src/renderer/vt/XtermEngine.hpp @@ -43,7 +43,7 @@ namespace Microsoft::Console::Render const gsl::not_null pData, const bool usingSoftFont, const bool isSettingDefaultBrushes) noexcept override; - [[nodiscard]] HRESULT PaintBufferLine(const gsl::span clusters, + [[nodiscard]] HRESULT PaintBufferLine(const std::span clusters, const til::point coord, const bool trimLeft, const bool lineWrapped) noexcept override; diff --git a/src/renderer/vt/math.cpp b/src/renderer/vt/math.cpp index bcbd6a5e834..d86e4644ca5 100644 --- a/src/renderer/vt/math.cpp +++ b/src/renderer/vt/math.cpp @@ -17,7 +17,7 @@ using namespace Microsoft::Console::Types; // This is an Inclusive rect. // Return Value: // - S_OK. -[[nodiscard]] HRESULT VtEngine::GetDirtyArea(gsl::span& area) noexcept +[[nodiscard]] HRESULT VtEngine::GetDirtyArea(std::span& area) noexcept { area = _invalidMap.runs(); return S_OK; diff --git a/src/renderer/vt/paint.cpp b/src/renderer/vt/paint.cpp index 3eb561f97f6..16ba7caf548 100644 --- a/src/renderer/vt/paint.cpp +++ b/src/renderer/vt/paint.cpp @@ -176,7 +176,7 @@ using namespace Microsoft::Console::Types; // will be false. // Return Value: // - S_OK or suitable HRESULT error from writing pipe. -[[nodiscard]] HRESULT VtEngine::PaintBufferLine(const gsl::span clusters, +[[nodiscard]] HRESULT VtEngine::PaintBufferLine(const std::span clusters, const til::point coord, const bool /*trimLeft*/, const bool /*lineWrapped*/) noexcept @@ -389,7 +389,7 @@ using namespace Microsoft::Console::Types; // - coord - character coordinate target to render within viewport // Return Value: // - S_OK or suitable HRESULT error from writing pipe. -[[nodiscard]] HRESULT VtEngine::_PaintAsciiBufferLine(const gsl::span clusters, +[[nodiscard]] HRESULT VtEngine::_PaintAsciiBufferLine(const std::span clusters, const til::point coord) noexcept { try @@ -424,7 +424,7 @@ using namespace Microsoft::Console::Types; // - coord - character coordinate target to render within viewport // Return Value: // - S_OK or suitable HRESULT error from writing pipe. -[[nodiscard]] HRESULT VtEngine::_PaintUtf8BufferLine(const gsl::span clusters, +[[nodiscard]] HRESULT VtEngine::_PaintUtf8BufferLine(const std::span clusters, const til::point coord, const bool lineWrapped) noexcept { diff --git a/src/renderer/vt/vtrenderer.hpp b/src/renderer/vt/vtrenderer.hpp index a7cdb7326e7..48bf6133efe 100644 --- a/src/renderer/vt/vtrenderer.hpp +++ b/src/renderer/vt/vtrenderer.hpp @@ -61,7 +61,7 @@ namespace Microsoft::Console::Render [[nodiscard]] HRESULT ResetLineTransform() noexcept override; [[nodiscard]] HRESULT PrepareLineTransform(const LineRendition lineRendition, const til::CoordType targetRow, const til::CoordType viewportLeft) noexcept override; [[nodiscard]] HRESULT PaintBackground() noexcept override; - [[nodiscard]] HRESULT PaintBufferLine(gsl::span clusters, til::point coord, bool fTrimLeft, bool lineWrapped) noexcept override; + [[nodiscard]] HRESULT PaintBufferLine(std::span clusters, til::point coord, bool fTrimLeft, bool lineWrapped) noexcept override; [[nodiscard]] HRESULT PaintBufferGridLines(GridLineSet lines, COLORREF color, size_t cchLine, til::point coordTarget) noexcept override; [[nodiscard]] HRESULT PaintSelection(const til::rect& rect) noexcept override; [[nodiscard]] HRESULT PaintCursor(const CursorOptions& options) noexcept override; @@ -69,7 +69,7 @@ namespace Microsoft::Console::Render [[nodiscard]] HRESULT UpdateDpi(int iDpi) noexcept override; [[nodiscard]] HRESULT UpdateViewport(const til::inclusive_rect& srNewViewport) noexcept override; [[nodiscard]] HRESULT GetProposedFont(const FontInfoDesired& FontInfoDesired, _Out_ FontInfo& FontInfo, int iDpi) noexcept override; - [[nodiscard]] HRESULT GetDirtyArea(gsl::span& area) noexcept override; + [[nodiscard]] HRESULT GetDirtyArea(std::span& area) noexcept override; [[nodiscard]] HRESULT GetFontSize(_Out_ til::size* pFontSize) noexcept override; [[nodiscard]] HRESULT IsGlyphWideByFont(std::wstring_view glyph, _Out_ bool* pResult) noexcept override; @@ -216,11 +216,11 @@ namespace Microsoft::Console::Render // buffer space for these two functions to build their lines // so they don't have to alloc/free in a tight loop std::wstring _bufferLine; - [[nodiscard]] HRESULT _PaintUtf8BufferLine(const gsl::span clusters, + [[nodiscard]] HRESULT _PaintUtf8BufferLine(const std::span clusters, const til::point coord, const bool lineWrapped) noexcept; - [[nodiscard]] HRESULT _PaintAsciiBufferLine(const gsl::span clusters, + [[nodiscard]] HRESULT _PaintAsciiBufferLine(const std::span clusters, const til::point coord) noexcept; [[nodiscard]] HRESULT _WriteTerminalUtf8(const std::wstring_view str) noexcept; diff --git a/src/renderer/wddmcon/WddmConRenderer.cpp b/src/renderer/wddmcon/WddmConRenderer.cpp index ae7acdd4b23..378b1dfd086 100644 --- a/src/renderer/wddmcon/WddmConRenderer.cpp +++ b/src/renderer/wddmcon/WddmConRenderer.cpp @@ -258,7 +258,7 @@ CATCH_RETURN() return S_OK; } -[[nodiscard]] HRESULT WddmConEngine::PaintBufferLine(const gsl::span clusters, +[[nodiscard]] HRESULT WddmConEngine::PaintBufferLine(const std::span clusters, const til::point coord, const bool /*trimLeft*/, const bool /*lineWrapped*/) noexcept @@ -353,7 +353,7 @@ CATCH_RETURN() return S_OK; } -[[nodiscard]] HRESULT WddmConEngine::GetDirtyArea(gsl::span& area) noexcept +[[nodiscard]] HRESULT WddmConEngine::GetDirtyArea(std::span& area) noexcept { _dirtyArea.bottom = std::max(0, _displayHeight); _dirtyArea.right = std::max(0, _displayWidth); diff --git a/src/renderer/wddmcon/WddmConRenderer.hpp b/src/renderer/wddmcon/WddmConRenderer.hpp index 87c3a799bd8..a658ef51180 100644 --- a/src/renderer/wddmcon/WddmConRenderer.hpp +++ b/src/renderer/wddmcon/WddmConRenderer.hpp @@ -40,7 +40,7 @@ namespace Microsoft::Console::Render [[nodiscard]] HRESULT ScrollFrame() noexcept override; [[nodiscard]] HRESULT PaintBackground() noexcept override; - [[nodiscard]] HRESULT PaintBufferLine(const gsl::span clusters, + [[nodiscard]] HRESULT PaintBufferLine(const std::span clusters, const til::point coord, const bool trimLeft, const bool lineWrapped) noexcept override; @@ -60,7 +60,7 @@ namespace Microsoft::Console::Render [[nodiscard]] HRESULT GetProposedFont(const FontInfoDesired& fiFontInfoDesired, FontInfo& fiFontInfo, const int iDpi) noexcept override; - [[nodiscard]] HRESULT GetDirtyArea(gsl::span& area) noexcept override; + [[nodiscard]] HRESULT GetDirtyArea(std::span& area) noexcept override; [[nodiscard]] HRESULT GetFontSize(_Out_ til::size* const pFontSize) noexcept override; [[nodiscard]] HRESULT IsGlyphWideByFont(const std::wstring_view glyph, _Out_ bool* const pResult) noexcept override; diff --git a/src/server/ApiDispatchers.cpp b/src/server/ApiDispatchers.cpp index ed3c815eade..0558b43ac78 100644 --- a/src/server/ApiDispatchers.cpp +++ b/src/server/ApiDispatchers.cpp @@ -326,7 +326,7 @@ if (a->Unicode) { const std::string_view initialData(pbInitialData.get(), cbInitialData); - const gsl::span outputBuffer(reinterpret_cast(pvBuffer), cbBufferSize); + const std::span outputBuffer(reinterpret_cast(pvBuffer), cbBufferSize); hr = m->_pApiRoutines->ReadConsoleWImpl(*pInputBuffer, outputBuffer, cbWritten, // We must set the reply length in bytes. @@ -341,7 +341,7 @@ else { const std::string_view initialData(pbInitialData.get(), cbInitialData); - const gsl::span outputBuffer(reinterpret_cast(pvBuffer), cbBufferSize); + const std::span outputBuffer(reinterpret_cast(pvBuffer), cbBufferSize); hr = m->_pApiRoutines->ReadConsoleAImpl(*pInputBuffer, outputBuffer, cbWritten, // We must set the reply length in bytes. @@ -833,20 +833,20 @@ { case CONSOLE_ATTRIBUTE: { - const gsl::span buffer(reinterpret_cast(pvBuffer), cbBuffer / sizeof(WORD)); + const std::span buffer(reinterpret_cast(pvBuffer), cbBuffer / sizeof(WORD)); RETURN_IF_FAILED(m->_pApiRoutines->ReadConsoleOutputAttributeImpl(*pScreenInfo, til::wrap_coord(a->ReadCoord), buffer, written)); break; } case CONSOLE_REAL_UNICODE: case CONSOLE_FALSE_UNICODE: { - const gsl::span buffer(reinterpret_cast(pvBuffer), cbBuffer / sizeof(wchar_t)); + const std::span buffer(reinterpret_cast(pvBuffer), cbBuffer / sizeof(wchar_t)); RETURN_IF_FAILED(m->_pApiRoutines->ReadConsoleOutputCharacterWImpl(*pScreenInfo, til::wrap_coord(a->ReadCoord), buffer, written)); break; } case CONSOLE_ASCII: { - const gsl::span buffer(reinterpret_cast(pvBuffer), cbBuffer); + const std::span buffer(reinterpret_cast(pvBuffer), cbBuffer); RETURN_IF_FAILED(m->_pApiRoutines->ReadConsoleOutputCharacterAImpl(*pScreenInfo, til::wrap_coord(a->ReadCoord), buffer, written)); break; } @@ -884,7 +884,7 @@ RETURN_IF_FAILED(pObjectHandle->GetInputBuffer(GENERIC_WRITE, &pInputBuffer)); size_t written; - gsl::span buffer(reinterpret_cast(pvBuffer), cbSize / sizeof(INPUT_RECORD)); + std::span buffer(reinterpret_cast(pvBuffer), cbSize / sizeof(INPUT_RECORD)); if (!a->Unicode) { RETURN_IF_FAILED(m->_pApiRoutines->WriteConsoleInputAImpl(*pInputBuffer, buffer, written, !!a->Append)); @@ -929,7 +929,7 @@ RETURN_IF_FAILED(SizeTMult(regionArea, sizeof(CHAR_INFO), ®ionBytes)); RETURN_HR_IF(E_INVALIDARG, cbSize < regionBytes); // If given fewer bytes on input than we need to do this write, it's invalid. - const gsl::span buffer(reinterpret_cast(pvBuffer), cbSize / sizeof(CHAR_INFO)); + const std::span buffer(reinterpret_cast(pvBuffer), cbSize / sizeof(CHAR_INFO)); if (!a->Unicode) { RETURN_IF_FAILED(m->_pApiRoutines->WriteConsoleOutputAImpl(*pScreenInfo, buffer, originalRegion, writtenRegion)); @@ -1009,7 +1009,7 @@ } case CONSOLE_ATTRIBUTE: { - const gsl::span text(reinterpret_cast(pvBuffer), cbBufferSize / sizeof(WORD)); + const std::span text(reinterpret_cast(pvBuffer), cbBufferSize / sizeof(WORD)); hr = m->_pApiRoutines->WriteConsoleOutputAttributeImpl(*pScreenInfo, text, @@ -1059,7 +1059,7 @@ RETURN_IF_FAILED(SizeTMult(regionArea, sizeof(CHAR_INFO), ®ionBytes)); RETURN_HR_IF(E_INVALIDARG, regionArea > 0 && ((regionArea > ULONG_MAX / sizeof(CHAR_INFO)) || (cbBuffer < regionBytes))); - gsl::span buffer(reinterpret_cast(pvBuffer), cbBuffer / sizeof(CHAR_INFO)); + std::span buffer(reinterpret_cast(pvBuffer), cbBuffer / sizeof(CHAR_INFO)); auto finalRegion = Microsoft::Console::Types::Viewport::Empty(); // the actual region read out of the buffer if (!a->Unicode) { @@ -1098,7 +1098,7 @@ auto hr = S_OK; if (a->Unicode) { - gsl::span buffer(reinterpret_cast(pvBuffer), cbBuffer / sizeof(wchar_t)); + std::span buffer(reinterpret_cast(pvBuffer), cbBuffer / sizeof(wchar_t)); size_t written; size_t needed; if (a->Original) @@ -1120,7 +1120,7 @@ } else { - gsl::span buffer(reinterpret_cast(pvBuffer), cbBuffer); + std::span buffer(reinterpret_cast(pvBuffer), cbBuffer); size_t written; size_t needed; if (a->Original) @@ -1330,7 +1330,7 @@ { const std::wstring_view inputSource(reinterpret_cast(pvInputSource), cbInputSource / sizeof(wchar_t)); const std::wstring_view inputExeName(reinterpret_cast(pvInputExe), cbInputExe / sizeof(wchar_t)); - gsl::span outputBuffer(reinterpret_cast(pvOutputBuffer), cbOutputBufferSize / sizeof(wchar_t)); + std::span outputBuffer(reinterpret_cast(pvOutputBuffer), cbOutputBufferSize / sizeof(wchar_t)); size_t cchWritten; hr = m->_pApiRoutines->GetConsoleAliasWImpl(inputSource, outputBuffer, cchWritten, inputExeName); @@ -1342,7 +1342,7 @@ { const std::string_view inputSource(reinterpret_cast(pvInputSource), cbInputSource); const std::string_view inputExeName(reinterpret_cast(pvInputExe), cbInputExe); - gsl::span outputBuffer(reinterpret_cast(pvOutputBuffer), cbOutputBufferSize); + std::span outputBuffer(reinterpret_cast(pvOutputBuffer), cbOutputBufferSize); size_t cchWritten; hr = m->_pApiRoutines->GetConsoleAliasAImpl(inputSource, outputBuffer, cchWritten, inputExeName); @@ -1443,7 +1443,7 @@ if (a->Unicode) { const std::wstring_view inputExeName(reinterpret_cast(pvExeName), cbExeNameLength / sizeof(wchar_t)); - gsl::span outputBuffer(reinterpret_cast(pvOutputBuffer), cbAliasesBufferLength / sizeof(wchar_t)); + std::span outputBuffer(reinterpret_cast(pvOutputBuffer), cbAliasesBufferLength / sizeof(wchar_t)); size_t cchWritten; RETURN_IF_FAILED(m->_pApiRoutines->GetConsoleAliasesWImpl(inputExeName, outputBuffer, cchWritten)); @@ -1454,7 +1454,7 @@ else { const std::string_view inputExeName(reinterpret_cast(pvExeName), cbExeNameLength); - gsl::span outputBuffer(reinterpret_cast(pvOutputBuffer), cbAliasesBufferLength); + std::span outputBuffer(reinterpret_cast(pvOutputBuffer), cbAliasesBufferLength); size_t cchWritten; RETURN_IF_FAILED(m->_pApiRoutines->GetConsoleAliasesAImpl(inputExeName, outputBuffer, cchWritten)); @@ -1482,7 +1482,7 @@ size_t cbWritten; if (a->Unicode) { - gsl::span outputBuffer(reinterpret_cast(pvBuffer), cbAliasExesBufferLength / sizeof(wchar_t)); + std::span outputBuffer(reinterpret_cast(pvBuffer), cbAliasExesBufferLength / sizeof(wchar_t)); size_t cchWritten; RETURN_IF_FAILED(m->_pApiRoutines->GetConsoleAliasExesWImpl(outputBuffer, cchWritten)); @@ -1490,7 +1490,7 @@ } else { - gsl::span outputBuffer(reinterpret_cast(pvBuffer), cbAliasExesBufferLength); + std::span outputBuffer(reinterpret_cast(pvBuffer), cbAliasExesBufferLength); size_t cchWritten; RETURN_IF_FAILED(m->_pApiRoutines->GetConsoleAliasExesAImpl(outputBuffer, cchWritten)); @@ -1604,7 +1604,7 @@ if (a->Unicode) { const std::wstring_view inputExeName(reinterpret_cast(pvExeName), cbExeNameLength / sizeof(wchar_t)); - gsl::span outputBuffer(reinterpret_cast(pvOutputBuffer), cbOutputBuffer / sizeof(wchar_t)); + std::span outputBuffer(reinterpret_cast(pvOutputBuffer), cbOutputBuffer / sizeof(wchar_t)); size_t cchWritten; RETURN_IF_FAILED(m->_pApiRoutines->GetConsoleCommandHistoryWImpl(inputExeName, outputBuffer, cchWritten)); @@ -1614,7 +1614,7 @@ else { const std::string_view inputExeName(reinterpret_cast(pvExeName), cbExeNameLength); - gsl::span outputBuffer(reinterpret_cast(pvOutputBuffer), cbOutputBuffer); + std::span outputBuffer(reinterpret_cast(pvOutputBuffer), cbOutputBuffer); size_t cchWritten; RETURN_IF_FAILED(m->_pApiRoutines->GetConsoleCommandHistoryAImpl(inputExeName, outputBuffer, cchWritten)); diff --git a/src/server/IApiRoutines.h b/src/server/IApiRoutines.h index 9621b895d23..9d9307d10ab 100644 --- a/src/server/IApiRoutines.h +++ b/src/server/IApiRoutines.h @@ -91,7 +91,7 @@ class IApiRoutines std::unique_ptr& waiter) noexcept = 0; [[nodiscard]] virtual HRESULT ReadConsoleAImpl(IConsoleInputObject& context, - gsl::span buffer, + std::span buffer, size_t& written, std::unique_ptr& waiter, const std::string_view initialData, @@ -102,7 +102,7 @@ class IApiRoutines DWORD& controlKeyState) noexcept = 0; [[nodiscard]] virtual HRESULT ReadConsoleWImpl(IConsoleInputObject& context, - gsl::span buffer, + std::span buffer, size_t& written, std::unique_ptr& waiter, const std::string_view initialData, @@ -207,41 +207,41 @@ class IApiRoutines [[nodiscard]] virtual HRESULT ReadConsoleOutputAttributeImpl(const IConsoleOutputObject& context, const til::point origin, - gsl::span buffer, + std::span buffer, size_t& written) noexcept = 0; [[nodiscard]] virtual HRESULT ReadConsoleOutputCharacterAImpl(const IConsoleOutputObject& context, const til::point origin, - gsl::span buffer, + std::span buffer, size_t& written) noexcept = 0; [[nodiscard]] virtual HRESULT ReadConsoleOutputCharacterWImpl(const IConsoleOutputObject& context, const til::point origin, - gsl::span buffer, + std::span buffer, size_t& written) noexcept = 0; [[nodiscard]] virtual HRESULT WriteConsoleInputAImpl(IConsoleInputObject& context, - const gsl::span buffer, + const std::span buffer, size_t& written, const bool append) noexcept = 0; [[nodiscard]] virtual HRESULT WriteConsoleInputWImpl(IConsoleInputObject& context, - const gsl::span buffer, + const std::span buffer, size_t& written, const bool append) noexcept = 0; [[nodiscard]] virtual HRESULT WriteConsoleOutputAImpl(IConsoleOutputObject& context, - gsl::span buffer, + std::span buffer, const Microsoft::Console::Types::Viewport& requestRectangle, Microsoft::Console::Types::Viewport& writtenRectangle) noexcept = 0; [[nodiscard]] virtual HRESULT WriteConsoleOutputWImpl(IConsoleOutputObject& context, - gsl::span buffer, + std::span buffer, const Microsoft::Console::Types::Viewport& requestRectangle, Microsoft::Console::Types::Viewport& writtenRectangle) noexcept = 0; [[nodiscard]] virtual HRESULT WriteConsoleOutputAttributeImpl(IConsoleOutputObject& OutContext, - const gsl::span attrs, + const std::span attrs, const til::point target, size_t& used) noexcept = 0; @@ -256,28 +256,28 @@ class IApiRoutines size_t& used) noexcept = 0; [[nodiscard]] virtual HRESULT ReadConsoleOutputAImpl(const IConsoleOutputObject& context, - gsl::span buffer, + std::span buffer, const Microsoft::Console::Types::Viewport& sourceRectangle, Microsoft::Console::Types::Viewport& readRectangle) noexcept = 0; [[nodiscard]] virtual HRESULT ReadConsoleOutputWImpl(const IConsoleOutputObject& context, - gsl::span buffer, + std::span buffer, const Microsoft::Console::Types::Viewport& sourceRectangle, Microsoft::Console::Types::Viewport& readRectangle) noexcept = 0; - [[nodiscard]] virtual HRESULT GetConsoleTitleAImpl(gsl::span title, + [[nodiscard]] virtual HRESULT GetConsoleTitleAImpl(std::span title, size_t& written, size_t& needed) noexcept = 0; - [[nodiscard]] virtual HRESULT GetConsoleTitleWImpl(gsl::span title, + [[nodiscard]] virtual HRESULT GetConsoleTitleWImpl(std::span title, size_t& written, size_t& needed) noexcept = 0; - [[nodiscard]] virtual HRESULT GetConsoleOriginalTitleAImpl(gsl::span title, + [[nodiscard]] virtual HRESULT GetConsoleOriginalTitleAImpl(std::span title, size_t& written, size_t& needed) noexcept = 0; - [[nodiscard]] virtual HRESULT GetConsoleOriginalTitleWImpl(gsl::span title, + [[nodiscard]] virtual HRESULT GetConsoleOriginalTitleWImpl(std::span title, size_t& written, size_t& needed) noexcept = 0; @@ -314,12 +314,12 @@ class IApiRoutines const std::wstring_view exeName) noexcept = 0; [[nodiscard]] virtual HRESULT GetConsoleAliasAImpl(const std::string_view source, - gsl::span target, + std::span target, size_t& written, const std::string_view exeName) noexcept = 0; [[nodiscard]] virtual HRESULT GetConsoleAliasWImpl(const std::wstring_view source, - gsl::span target, + std::span target, size_t& written, const std::wstring_view exeName) noexcept = 0; @@ -334,17 +334,17 @@ class IApiRoutines [[nodiscard]] virtual HRESULT GetConsoleAliasExesLengthWImpl(size_t& bufferRequired) noexcept = 0; [[nodiscard]] virtual HRESULT GetConsoleAliasesAImpl(const std::string_view exeName, - gsl::span alias, + std::span alias, size_t& written) noexcept = 0; [[nodiscard]] virtual HRESULT GetConsoleAliasesWImpl(const std::wstring_view exeName, - gsl::span alias, + std::span alias, size_t& written) noexcept = 0; - [[nodiscard]] virtual HRESULT GetConsoleAliasExesAImpl(gsl::span aliasExes, + [[nodiscard]] virtual HRESULT GetConsoleAliasExesAImpl(std::span aliasExes, size_t& written) noexcept = 0; - [[nodiscard]] virtual HRESULT GetConsoleAliasExesWImpl(gsl::span aliasExes, + [[nodiscard]] virtual HRESULT GetConsoleAliasExesWImpl(std::span aliasExes, size_t& written) noexcept = 0; #pragma region CMDext Private API @@ -366,11 +366,11 @@ class IApiRoutines size_t& length) noexcept = 0; [[nodiscard]] virtual HRESULT GetConsoleCommandHistoryAImpl(const std::string_view exeName, - gsl::span commandHistory, + std::span commandHistory, size_t& written) noexcept = 0; [[nodiscard]] virtual HRESULT GetConsoleCommandHistoryWImpl(const std::wstring_view exeName, - gsl::span commandHistory, + std::span commandHistory, size_t& written) noexcept = 0; #pragma endregion diff --git a/src/terminal/adapter/DispatchTypes.hpp b/src/terminal/adapter/DispatchTypes.hpp index b20adf4bfc4..907d9392650 100644 --- a/src/terminal/adapter/DispatchTypes.hpp +++ b/src/terminal/adapter/DispatchTypes.hpp @@ -155,7 +155,7 @@ namespace Microsoft::Console::VirtualTerminal constexpr VTParameter at(const size_t index) const noexcept { // If the index is out of range, we return a parameter with no value. - return index < _values.size() ? _values[index] : VTParameter{}; + return index < _values.size() ? til::at(_values, index) : defaultParameter; } constexpr bool empty() const noexcept @@ -179,18 +179,28 @@ namespace Microsoft::Console::VirtualTerminal template bool for_each(const T&& predicate) const { + auto values = _values; + // We always return at least 1 value here, since an empty parameter // list is the equivalent of a single "default" parameter. - auto success = predicate(at(0)); - for (auto i = 1u; i < _values.size(); i++) + if (values.empty()) { - success = predicate(_values[i]) && success; + values = defaultParameters; + } + + auto success = true; + for (const auto& v : values) + { + success = predicate(v) && success; } return success; } private: - gsl::span _values; + static constexpr VTParameter defaultParameter; + static constexpr std::span defaultParameters{ &defaultParameter, 1 }; + + std::span _values; }; // FlaggedEnumValue is a convenience class that produces enum values (of a specified size) diff --git a/src/terminal/adapter/FontBuffer.cpp b/src/terminal/adapter/FontBuffer.cpp index 8bac5d3f9d4..c7f205f5a10 100644 --- a/src/terminal/adapter/FontBuffer.cpp +++ b/src/terminal/adapter/FontBuffer.cpp @@ -217,7 +217,7 @@ bool FontBuffer::FinalizeSixelData() return true; } -gsl::span FontBuffer::GetBitPattern() const noexcept +std::span FontBuffer::GetBitPattern() const noexcept { return { _buffer.data(), gsl::narrow_cast(MAX_CHARS * _fullHeight) }; } diff --git a/src/terminal/adapter/FontBuffer.hpp b/src/terminal/adapter/FontBuffer.hpp index a945f9a75ef..f520c7bc958 100644 --- a/src/terminal/adapter/FontBuffer.hpp +++ b/src/terminal/adapter/FontBuffer.hpp @@ -30,7 +30,7 @@ namespace Microsoft::Console::VirtualTerminal void AddSixelData(const wchar_t ch); bool FinalizeSixelData(); - gsl::span GetBitPattern() const noexcept; + std::span GetBitPattern() const noexcept; til::size GetCellSize() const noexcept; size_t GetTextCenteringHint() const noexcept; VTID GetDesignation() const noexcept; diff --git a/src/terminal/input/terminalInput.cpp b/src/terminal/input/terminalInput.cpp index db3d3fd805c..0af36efe603 100644 --- a/src/terminal/input/terminalInput.cpp +++ b/src/terminal/input/terminalInput.cpp @@ -278,7 +278,7 @@ void TerminalInput::ForceDisableWin32InputMode(const bool win32InputMode) noexce _forceDisableWin32InputMode = win32InputMode; } -static const gsl::span _getKeyMapping(const KeyEvent& keyEvent, +static const std::span _getKeyMapping(const KeyEvent& keyEvent, const bool ansiMode, const bool cursorApplicationMode, const bool keypadApplicationMode) noexcept @@ -329,7 +329,7 @@ static const gsl::span _getKeyMapping(const KeyEvent& keyEvent // Return Value: // - Has value if there was a match to a key translation. static std::optional _searchKeyMapping(const KeyEvent& keyEvent, - gsl::span keyMapping) noexcept + std::span keyMapping) noexcept { for (auto& map : keyMapping) { @@ -492,7 +492,7 @@ static bool _searchWithModifier(const KeyEvent& keyEvent, InputSender sender) // Return Value: // - True if there was a match to a key translation, and we successfully sent it to the input static bool _translateDefaultMapping(const KeyEvent& keyEvent, - const gsl::span keyMapping, + const std::span keyMapping, InputSender sender) { const auto match = _searchKeyMapping(keyEvent, keyMapping); diff --git a/src/terminal/parser/InputStateMachineEngine.cpp b/src/terminal/parser/InputStateMachineEngine.cpp index ab5492ed6d1..5d0a6c51db0 100644 --- a/src/terminal/parser/InputStateMachineEngine.cpp +++ b/src/terminal/parser/InputStateMachineEngine.cpp @@ -703,7 +703,7 @@ bool InputStateMachineEngine::_WriteSingleKey(const wchar_t wch, const short vke // At most 8 records - 2 for each of shift,ctrl,alt up and down, and 2 for the actual key up and down. std::vector input; _GenerateWrappedSequence(wch, vkey, modifierState, input); - auto inputEvents = IInputEvent::Create(gsl::make_span(input)); + auto inputEvents = IInputEvent::Create(std::span{ input }); return _pDispatch->WriteInput(inputEvents); } @@ -744,7 +744,7 @@ bool InputStateMachineEngine::_WriteMouseEvent(const til::point uiPos, const DWO // pack and write input record // 1 record - the modifiers don't get their own events - auto inputEvents = IInputEvent::Create(gsl::make_span(&rgInput, 1)); + auto inputEvents = IInputEvent::Create(std::span{ &rgInput, 1 }); return _pDispatch->WriteInput(inputEvents); } @@ -1095,7 +1095,7 @@ void InputStateMachineEngine::SetFlushToInputQueueCallback(std::function // - function - Receives the function type // Return Value: // - True iff we successfully pulled the function type from the parameters -bool InputStateMachineEngine::_GetWindowManipulationType(const gsl::span parameters, +bool InputStateMachineEngine::_GetWindowManipulationType(const std::span parameters, unsigned int& function) const noexcept { auto success = false; diff --git a/src/terminal/parser/InputStateMachineEngine.hpp b/src/terminal/parser/InputStateMachineEngine.hpp index c4a814a1eeb..0bcc8398ebf 100644 --- a/src/terminal/parser/InputStateMachineEngine.hpp +++ b/src/terminal/parser/InputStateMachineEngine.hpp @@ -205,7 +205,7 @@ namespace Microsoft::Console::VirtualTerminal const DWORD modifierState, std::vector& input); - bool _GetWindowManipulationType(const gsl::span parameters, + bool _GetWindowManipulationType(const std::span parameters, unsigned int& function) const noexcept; KeyEvent _GenerateWin32Key(const VTParameters parameters); diff --git a/src/terminal/parser/OutputStateMachineEngine.cpp b/src/terminal/parser/OutputStateMachineEngine.cpp index 509a16433ad..55c4a0d080d 100644 --- a/src/terminal/parser/OutputStateMachineEngine.cpp +++ b/src/terminal/parser/OutputStateMachineEngine.cpp @@ -1016,7 +1016,7 @@ bool OutputStateMachineEngine::_GetOscSetColorTable(const std::wstring_view stri } #pragma warning(push) -#pragma warning(disable : 26445) // Suppress lifetime check for a reference to gsl::span or std::string_view +#pragma warning(disable : 26445) // Suppress lifetime check for a reference to std::span or std::string_view // Routine Description: // - Given a hyperlink string, attempts to parse the URI encoded. An 'id' parameter diff --git a/src/terminal/parser/ut_parser/OutputEngineTest.cpp b/src/terminal/parser/ut_parser/OutputEngineTest.cpp index 38d79f54e6d..6fc04c62f72 100644 --- a/src/terminal/parser/ut_parser/OutputEngineTest.cpp +++ b/src/terminal/parser/ut_parser/OutputEngineTest.cpp @@ -1839,7 +1839,7 @@ class StateMachineExternalTest final pDispatch->ClearState(); } - void VerifyDispatchTypes(const gsl::span expectedOptions, + void VerifyDispatchTypes(const std::span expectedOptions, const StatefulDispatch& dispatch) { VERIFY_ARE_EQUAL(expectedOptions.size(), dispatch._options.size()); diff --git a/src/tsf/TfConvArea.cpp b/src/tsf/TfConvArea.cpp index b9ab24b4f65..940bb7af098 100644 --- a/src/tsf/TfConvArea.cpp +++ b/src/tsf/TfConvArea.cpp @@ -45,8 +45,8 @@ Revision History: const auto encodedAttributes = _DisplayAttributesToEncodedAttributes(DisplayAttributes, CompCursorPos); - gsl::span attributes(encodedAttributes.data(), encodedAttributes.size()); - gsl::span colorArray(colors.data(), colors.size()); + std::span attributes(encodedAttributes.data(), encodedAttributes.size()); + std::span colorArray(colors.data(), colors.size()); return ImeComposeData(CompStr, attributes, colorArray); } diff --git a/src/types/IInputEvent.cpp b/src/types/IInputEvent.cpp index c01ff7067bd..c2285caec66 100644 --- a/src/types/IInputEvent.cpp +++ b/src/types/IInputEvent.cpp @@ -25,7 +25,7 @@ std::unique_ptr IInputEvent::Create(const INPUT_RECORD& record) } } -std::deque> IInputEvent::Create(gsl::span records) +std::deque> IInputEvent::Create(std::span records) { std::deque> outEvents; diff --git a/src/types/KeyEvent.cpp b/src/types/KeyEvent.cpp index 791c099e9c7..475cd837411 100644 --- a/src/types/KeyEvent.cpp +++ b/src/types/KeyEvent.cpp @@ -44,6 +44,14 @@ void KeyEvent::SetVirtualScanCode(const WORD virtualScanCode) noexcept _virtualScanCode = virtualScanCode; } +void KeyEvent::SetCharData(const char character) noexcept +{ + // With MSVC char is signed by default and the conversion to wchar_t (unsigned) would turn negative + // chars into very large wchar_t values. While this doesn't pose a problem per se (even with such sign + // extension, the lower 8 bit stay the same), it makes debugging and reading key events more difficult. + _charData = til::as_unsigned(character); +} + void KeyEvent::SetCharData(const wchar_t character) noexcept { _charData = character; diff --git a/src/types/ScreenInfoUiaProviderBase.cpp b/src/types/ScreenInfoUiaProviderBase.cpp index 8fc6073c667..27dfb8c3b7a 100644 --- a/src/types/ScreenInfoUiaProviderBase.cpp +++ b/src/types/ScreenInfoUiaProviderBase.cpp @@ -9,7 +9,7 @@ using namespace Microsoft::Console::Types; // A helper function to create a SafeArray Version of an int array of a specified length -SAFEARRAY* BuildIntSafeArray(gsl::span data) +SAFEARRAY* BuildIntSafeArray(std::span data) { auto psa = SafeArrayCreateVector(VT_I4, 0, gsl::narrow(data.size())); if (psa != nullptr) @@ -191,7 +191,7 @@ IFACEMETHODIMP ScreenInfoUiaProviderBase::GetRuntimeId(_Outptr_result_maybenull_ // AppendRuntimeId is a magic Number that tells UIAutomation to Append its own Runtime ID(From the HWND) const std::array rId{ UiaAppendRuntimeId, -1 }; - const gsl::span span{ rId.data(), rId.size() }; + const std::span span{ rId.data(), rId.size() }; // BuildIntSafeArray is a custom function to hide the SafeArray creation *ppRuntimeId = BuildIntSafeArray(span); RETURN_IF_NULL_ALLOC(*ppRuntimeId); diff --git a/src/types/colorTable.cpp b/src/types/colorTable.cpp index 15a51f0d456..46f59bfd2dd 100644 --- a/src/types/colorTable.cpp +++ b/src/types/colorTable.cpp @@ -435,9 +435,9 @@ static constexpr til::presorted_static_map xorgAppColorTable{ std::pair{ "yellowgreen"sv, til::color{ 154, 205, 50 } } }; -gsl::span Utils::CampbellColorTable() +std::span Utils::CampbellColorTable() noexcept { - return gsl::make_span(standard256ColorTable).first(16); + return std::span{ standard256ColorTable }.first(16); } // Function Description: @@ -446,7 +446,7 @@ gsl::span Utils::CampbellColorTable() // - table: a color table to be filled // Return Value: // - -void Utils::InitializeColorTable(const gsl::span table) +void Utils::InitializeColorTable(const std::span table) { const auto tableSize = std::min(table.size(), standard256ColorTable.size()); std::copy_n(standard256ColorTable.begin(), tableSize, table.begin()); diff --git a/src/types/inc/IInputEvent.hpp b/src/types/inc/IInputEvent.hpp index 21867f4c1e4..edda9846a55 100644 --- a/src/types/inc/IInputEvent.hpp +++ b/src/types/inc/IInputEvent.hpp @@ -41,7 +41,7 @@ class IInputEvent { public: static std::unique_ptr Create(const INPUT_RECORD& record); - static std::deque> Create(gsl::span records); + static std::deque> Create(std::span records); static std::deque> Create(const std::deque& records); static std::vector ToInputRecords(const std::deque>& events); @@ -290,6 +290,7 @@ class KeyEvent : public IInputEvent void SetRepeatCount(const WORD repeatCount) noexcept; void SetVirtualKeyCode(const WORD virtualKeyCode) noexcept; void SetVirtualScanCode(const WORD virtualScanCode) noexcept; + void SetCharData(const char character) noexcept; void SetCharData(const wchar_t character) noexcept; void SetActiveModifierKeys(const DWORD activeModifierKeys) noexcept; diff --git a/src/types/inc/colorTable.hpp b/src/types/inc/colorTable.hpp index f68284aaa01..d81445fc184 100644 --- a/src/types/inc/colorTable.hpp +++ b/src/types/inc/colorTable.hpp @@ -12,8 +12,8 @@ Module Name: namespace Microsoft::Console::Utils { - void InitializeColorTable(const gsl::span table); - gsl::span CampbellColorTable(); + void InitializeColorTable(const std::span table); + std::span CampbellColorTable() noexcept; std::optional ColorFromXOrgAppColorName(const std::wstring_view wstr) noexcept; } diff --git a/src/types/inc/utils.hpp b/src/types/inc/utils.hpp index 0efae695985..3dbe7928c9a 100644 --- a/src/types/inc/utils.hpp +++ b/src/types/inc/utils.hpp @@ -94,7 +94,7 @@ namespace Microsoft::Console::Utils return value; } - GUID CreateV5Uuid(const GUID& namespaceGuid, const gsl::span name); + GUID CreateV5Uuid(const GUID& namespaceGuid, const std::span name); bool IsElevated(); diff --git a/src/types/ut_types/UuidTests.cpp b/src/types/ut_types/UuidTests.cpp index af35c4ebd2c..e0abbc6a6f3 100644 --- a/src/types/ut_types/UuidTests.cpp +++ b/src/types/ut_types/UuidTests.cpp @@ -25,7 +25,7 @@ class UuidTests const GUID uuidExpected{ 0x8b9d4336, 0x0c82, 0x54c4, { 0xb3, 0x15, 0xf1, 0xd2, 0xd2, 0x7e, 0xc6, 0xda } }; std::string name{ "testing" }; - auto uuidActual = CreateV5Uuid(TEST_NAMESPACE_GUID, gsl::as_bytes(gsl::make_span(name))); + auto uuidActual = CreateV5Uuid(TEST_NAMESPACE_GUID, std::as_bytes(std::span{ name })); VERIFY_ARE_EQUAL(uuidExpected, uuidActual); } @@ -36,7 +36,7 @@ class UuidTests // This'll come out in little endian; the reference GUID was generated as such. std::wstring name{ L"testing" }; - auto uuidActual = CreateV5Uuid(TEST_NAMESPACE_GUID, gsl::as_bytes(gsl::make_span(name))); + auto uuidActual = CreateV5Uuid(TEST_NAMESPACE_GUID, std::as_bytes(std::span{ name })); VERIFY_ARE_EQUAL(uuidExpected, uuidActual); } diff --git a/src/types/utils.cpp b/src/types/utils.cpp index 8d4edf1e75b..dac6212c6e0 100644 --- a/src/types/utils.cpp +++ b/src/types/utils.cpp @@ -623,7 +623,7 @@ bool Utils::IsValidHandle(const HANDLE handle) noexcept // - name: Bytes comprising the name (in a namespace-specific format) // Return Value: // - a new stable v5 UUID -GUID Utils::CreateV5Uuid(const GUID& namespaceGuid, const gsl::span name) +GUID Utils::CreateV5Uuid(const GUID& namespaceGuid, const std::span name) { // v5 uuid generation happens over values in network byte order, so let's enforce that auto correctEndianNamespaceGuid{ EndianSwap(namespaceGuid) }; @@ -635,7 +635,7 @@ GUID Utils::CreateV5Uuid(const GUID& namespaceGuid, const gsl::span(&correctEndianNamespaceGuid), sizeof(GUID), 0)); // BCryptHashData is ill-specified in that it leaves off "const" qualification for pbInput - THROW_IF_NTSTATUS_FAILED(BCryptHashData(hash.get(), reinterpret_cast(const_cast(name.data())), gsl::narrow(name.size()), 0)); + THROW_IF_NTSTATUS_FAILED(BCryptHashData(hash.get(), reinterpret_cast(const_cast(name.data())), gsl::narrow(name.size()), 0)); std::array buffer; THROW_IF_NTSTATUS_FAILED(BCryptFinishHash(hash.get(), buffer.data(), gsl::narrow(buffer.size()), 0));