Repository: microsoft/terminal
File: src/cascadia/TerminalCore/TerminalApi.cpp (C++)

Code before:
    if (last->category == Microsoft::Console::VirtualTerminal::DispatchTypes::MarkCategory::Prompt)
    {
        _currentPrompt = last;
    }
}

void Terminal::CommandStart()
{
    if (_currentPrompt)
    {
        const til::point cursorPos{ _activeBuffer().GetCursor().GetPosition() };

        // Move the end of this mark to the current cursor position. The prompt
        // is between [mark.start, mark.end)
        _currentPrompt->end = cursorPos;
    }
}

void Terminal::OutputStart()
{
    if (_currentPrompt)
    {
        const til::point cursorPos{ _activeBuffer().GetCursor().GetPosition() };
        // Mark the current cursor pos as the the end of the command. The command
        // is between [mark.end, mark.commandEnd)
        _currentPrompt->commandEnd = cursorPos;
    }
}

void Terminal::CommandFinished(std::optional<unsigned int> error)
{
    if (_currentPrompt)
    {
        const til::point cursorPos{ _activeBuffer().GetCursor().GetPosition() };
        // Mark the current cursor pos as the the end of the output. The command
        // is between [mark.commandEnd, mark.outputEnd)
        _currentPrompt->outputEnd = cursorPos;

        if (error.has_value())
        {
            _currentPrompt->category = *error == 0u ?
                                           DispatchTypes::MarkCategory::Success :
                                           DispatchTypes::MarkCategory::Error;
        }
    }
}

// Method Description:
// - Reacts to a client asking us to show or hide the window.
// Arguments:
// - showOrHide - True for show. False for hide.

Review comment (suggestion):
```suggestion
        // Mark the current cursor pos as the the end of the command. The command
        // is between [mark.end, mark.commandEnd)
        _currentPrompt->commandEnd = _activeBuffer().GetCursor().GetPosition();
```
if you want

Code after:
    // destroy the alt buffer
    _altBuffer = nullptr;

    if (_deferredResize.has_value())
    {
        LOG_IF_FAILED(UserResize(_deferredResize.value()));
        _deferredResize = std::nullopt;
    }

    // update all the hyperlinks on the screen
    _mainBuffer->ClearPatternRecognizers();
    _updateUrlDetection();

    // GH#3321: Make sure we let the TerminalInput know that we switched
    // buffers. This might affect how we interpret certain mouse events.
    _terminalInput->UseMainScreenBuffer();

    // Update scrollbars
    _NotifyScrollEvent();

    // redraw the screen
    try
    {
        _activeBuffer().TriggerRedrawAll();
    }
    CATCH_LOG();
}

// NOTE: This is the version of AddMark that comes from VT
void Terminal::MarkPrompt(const DispatchTypes::ScrollMark& mark)
{
    static bool logged = false;
    if (!logged)
    {
        TraceLoggingWrite(
            g_hCTerminalCoreProvider,
            "ShellIntegrationMarkAdded",
            TraceLoggingDescription("A mark was added via VT at least once"),
            TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
            TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));

        logged = true;
    }

    const til::point cursorPos{ _activeBuffer().GetCursor().GetPosition() };
    AddMark(mark, cursorPos, cursorPos, false);

    if (mark.category == DispatchTypes::MarkCategory::Prompt)
    {
        _currentPromptState = PromptState::Prompt;
    }