Repository: microsoft/terminal
File: src/terminal/adapter/adaptDispatch.cpp (C++)

Code before:
        return false;
    }

    if constexpr (!Feature_ScrollbarMarks::IsEnabled())
    {
        return false;
    }

    const auto parts = Utils::SplitString(string, L';');

    if (parts.size() < 1)
    {
        return false;
    }

    const auto action = til::at(parts, 0);

    if (action == L"A") // FTCS_PROMPT
    {
        // Simply just mark this line as a prompt line.
        DispatchTypes::ScrollMark mark;
        mark.category = DispatchTypes::MarkCategory::Prompt;
        _api.AddMark(mark);
        return true;
    }
    else if (action == L"B") // FTCS_COMMAND_START
    {
        _api.CommandStart();
        return true;
    }
    else if (action == L"C") // FTCS_COMMAND_EXECUTED
    {
        _api.OutputStart();
        return true;
    }
    else if (action == L"D") // FTCS_COMMAND_FINISHED
    {
        std::optional<unsigned int> error = std::nullopt;
        if (parts.size() >= 2)
        {
            const auto errorString = til::at(parts, 1);

            // If we fail to parse the code, then it was gibberish, or it might
            // have just started with "-". Either way, let's just treat it as an
            // error and move on.
            //
            // We know that "0" will be successfully parsed, and that's close enough.
            unsigned int parsedError = 0;
            error = Utils::StringToUint(errorString, parsedError) ? parsedError :
                                                                    static_cast<unsigned int>(-1);
        }

Review comment (suggestion):
nit: Now that there are 4 instead of just 1 branch, I think it makes sense to convert this into an `if (action.size() == 1`) and `switch (action[0])`.

Code after:
{
    // Other Window Manipulation functions:
    //  MSFT:13271098 - QueryViewport
    //  MSFT:13271146 - QueryScreenSize
    switch (function)
    {
    case DispatchTypes::WindowManipulationType::DeIconifyWindow:
        _api.ShowWindow(true);
        return true;
    case DispatchTypes::WindowManipulationType::IconifyWindow:
        _api.ShowWindow(false);
        return true;
    case DispatchTypes::WindowManipulationType::RefreshWindow:
        _api.GetTextBuffer().TriggerRedrawAll();
        return true;
    case DispatchTypes::WindowManipulationType::ResizeWindowInCharacters:
        _api.ResizeWindow(parameter2.value_or(0), parameter1.value_or(0));
        return true;
    default:
        return false;
    }
}

// Method Description:
// - Starts a hyperlink
// Arguments:
// - The hyperlink URI, optional additional parameters
// Return Value:
// - true
bool AdaptDispatch::AddHyperlink(const std::wstring_view uri, const std::wstring_view params)
{
    auto& textBuffer = _api.GetTextBuffer();
    auto attr = textBuffer.GetCurrentAttributes();
    const auto id = textBuffer.GetHyperlinkId(uri, params);
    attr.SetHyperlinkId(id);
    textBuffer.SetCurrentAttributes(attr);
    textBuffer.AddHyperlinkToMap(uri, id);
    return true;
}

// Method Description:
// - Ends a hyperlink
// Return Value:
// - true
bool AdaptDispatch::EndHyperlink()
{
    auto& textBuffer = _api.GetTextBuffer();
    auto attr = textBuffer.GetCurrentAttributes();
    attr.SetHyperlinkId(0);
    textBuffer.SetCurrentAttributes(attr);
    return true;