From 742072e606942ffce0c27624a7a63b02fcaca5ba Mon Sep 17 00:00:00 2001 From: Tushar Singh Date: Wed, 12 Jul 2023 12:21:25 +0530 Subject: [PATCH] add VTSubParameters class --- src/terminal/adapter/DispatchTypes.hpp | 50 +++++++++++++++++-- src/terminal/adapter/adaptDispatch.hpp | 2 +- .../adapter/adaptDispatchGraphics.cpp | 2 +- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/terminal/adapter/DispatchTypes.hpp b/src/terminal/adapter/DispatchTypes.hpp index 8a199a196735..088714e5cf90 100644 --- a/src/terminal/adapter/DispatchTypes.hpp +++ b/src/terminal/adapter/DispatchTypes.hpp @@ -152,6 +152,48 @@ namespace Microsoft::Console::VirtualTerminal VTInt _value; }; + class VTSubParameters + { + public: + constexpr VTSubParameters() noexcept + { + } + + constexpr VTSubParameters(const std::span subParams) noexcept : + _subParams{ subParams } + { + } + + constexpr VTParameter at(const size_t index) const noexcept + { + return til::at(_subParams, index); + } + + VTSubParameters subspan(const size_t offset, const size_t count) const noexcept + { + const auto subParamsSpan = _subParams.subspan(offset, count); + return { subParamsSpan }; + } + + bool empty() const noexcept + { + return _subParams.empty(); + } + + size_t size() const noexcept + { + return _subParams.size(); + } + + constexpr operator std::span() const noexcept + { + return _subParams; + } + + private: + std::span _subParams; + }; + class VTParameters { public: @@ -200,10 +242,10 @@ namespace Microsoft::Console::VirtualTerminal // _subParams as is and create new span for others. const auto newParamsSpan = _params.subspan(std::min(offset, _params.size())); const auto newSubParamRangesSpan = _subParamRanges.subspan(std::min(offset, _subParamRanges.size())); - return { newParamsSpan, _subParams, newSubParamRangesSpan }; + return { newParamsSpan, _subParams , newSubParamRangesSpan }; } - std::span subParamsFor(const size_t index) const noexcept + VTSubParameters subParamsFor(const size_t index) const noexcept { if (index < _subParamRanges.size()) { @@ -212,7 +254,7 @@ namespace Microsoft::Console::VirtualTerminal } else { - return std::span{}; + return VTSubParameters{}; } } @@ -259,7 +301,7 @@ namespace Microsoft::Console::VirtualTerminal static constexpr std::span defaultParameters{ &defaultParameter, 1 }; std::span _params; - std::span _subParams; + VTSubParameters _subParams; std::span> _subParamRanges; }; diff --git a/src/terminal/adapter/adaptDispatch.hpp b/src/terminal/adapter/adaptDispatch.hpp index 059fb3852c5c..e0c346dc9d0b 100644 --- a/src/terminal/adapter/adaptDispatch.hpp +++ b/src/terminal/adapter/adaptDispatch.hpp @@ -301,7 +301,7 @@ namespace Microsoft::Console::VirtualTerminal const size_t optionIndex, TextAttribute& attr) noexcept; void _ApplyGraphicsOptionSubParam(const VTParameter option, - const std::span subParams, + const VTSubParameters subParams, TextAttribute& attr) noexcept; void _ApplyGraphicsOptions(const VTParameters options, TextAttribute& attr) noexcept; diff --git a/src/terminal/adapter/adaptDispatchGraphics.cpp b/src/terminal/adapter/adaptDispatchGraphics.cpp index cd05158fe991..5259cf8ce64f 100644 --- a/src/terminal/adapter/adaptDispatchGraphics.cpp +++ b/src/terminal/adapter/adaptDispatchGraphics.cpp @@ -268,7 +268,7 @@ size_t AdaptDispatch::_ApplyGraphicsOption(const VTParameters options, // Return Value: // - void AdaptDispatch::_ApplyGraphicsOptionSubParam(const VTParameter /* option */, - const std::span /* subParam */, + const VTSubParameters /* subParam */, TextAttribute& /* attr */) noexcept { // here, we apply our "best effort" rule, while handling sub params if we don't