Skip to content

Commit

Permalink
add VTSubParameters class
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharsnx committed Jul 12, 2023
1 parent d7aa1d7 commit 742072e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
50 changes: 46 additions & 4 deletions src/terminal/adapter/DispatchTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,48 @@ namespace Microsoft::Console::VirtualTerminal
VTInt _value;
};

class VTSubParameters
{
public:
constexpr VTSubParameters() noexcept
{
}

constexpr VTSubParameters(const std::span<const VTParameter> 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 VTParameter>() const noexcept
{
return _subParams;
}

private:
std::span<const VTParameter> _subParams;
};

class VTParameters
{
public:
Expand Down Expand Up @@ -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<const VTParameter> subParamsFor(const size_t index) const noexcept
VTSubParameters subParamsFor(const size_t index) const noexcept
{
if (index < _subParamRanges.size())
{
Expand All @@ -212,7 +254,7 @@ namespace Microsoft::Console::VirtualTerminal
}
else
{
return std::span<const VTParameter>{};
return VTSubParameters{};
}
}

Expand Down Expand Up @@ -259,7 +301,7 @@ namespace Microsoft::Console::VirtualTerminal
static constexpr std::span defaultParameters{ &defaultParameter, 1 };

std::span<const VTParameter> _params;
std::span<const VTParameter> _subParams;
VTSubParameters _subParams;
std::span<const std::pair<BYTE, BYTE>> _subParamRanges;
};

Expand Down
2 changes: 1 addition & 1 deletion src/terminal/adapter/adaptDispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ namespace Microsoft::Console::VirtualTerminal
const size_t optionIndex,
TextAttribute& attr) noexcept;
void _ApplyGraphicsOptionSubParam(const VTParameter option,
const std::span<const VTParameter> subParams,
const VTSubParameters subParams,
TextAttribute& attr) noexcept;
void _ApplyGraphicsOptions(const VTParameters options,
TextAttribute& attr) noexcept;
Expand Down
2 changes: 1 addition & 1 deletion src/terminal/adapter/adaptDispatchGraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ size_t AdaptDispatch::_ApplyGraphicsOption(const VTParameters options,
// Return Value:
// - <None>
void AdaptDispatch::_ApplyGraphicsOptionSubParam(const VTParameter /* option */,
const std::span<const VTParameter> /* subParam */,
const VTSubParameters /* subParam */,
TextAttribute& /* attr */) noexcept
{
// here, we apply our "best effort" rule, while handling sub params if we don't
Expand Down

0 comments on commit 742072e

Please sign in to comment.