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

Code before:
        _activeBuffer().TriggerRedrawAll();
    }
    CATCH_LOG();
}

// NOTE: This is the version of AddMark that comes from VT
void Terminal::AddMark(const Microsoft::Console::VirtualTerminal::DispatchTypes::ScrollMark& mark)
{
    const til::point cursorPos{ _activeBuffer().GetCursor().GetPosition() };
    AddMark(mark, cursorPos, cursorPos);
    auto* last = &_scrollMarks.back();
    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())
        {

Review comment (suggestion):
```suggestion
        // Move the end of this mark to the current cursor position. The prompt
        // is between [mark.start, mark.end)
        _currentPrompt->end = _activeBuffer().GetCursor().GetPosition();
```
if you want

Code after:
        tgtCursor.SetIsVisible(myCursor.IsVisible());
        tgtCursor.SetBlinkingAllowed(myCursor.IsBlinkingAllowed());

        // The new position should match the viewport-relative position of the main buffer.
        // This is the equal and opposite effect of what we did in UseAlternateScreenBuffer
        auto tgtCursorPos = myCursor.GetPosition();
        tgtCursorPos.y += _mutableViewport.Top();
        tgtCursor.SetPosition(tgtCursorPos);
    }

    _mainBuffer->SetAsActiveBuffer(true);
    // 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));