Repository: microsoft/terminal
File: src/host/outputStream.cpp (C++)

Code before:
//   SetInputMode is an internal-only "API" call that the vt commands can execute,
//     but it is not represented as a function call on out public API surface.
// Arguments:
// - mode - the input mode to change.
// - enabled - set to true to enable the mode, false to disable it.
// Return Value:
// - true if successful. false otherwise.
bool ConhostInternalGetSet::SetInputMode(const TerminalInput::Mode mode, const bool enabled)
{
    auto& terminalInput = _io.GetActiveInputBuffer()->GetTerminalInput();
    terminalInput.SetInputMode(mode, enabled);

    // If we're a conpty, AND WE'RE IN VT INPUT MODE, always pass input mode requests
    // The VT Input mode check is to work around ssh.exe v7.7, which uses VT
    // output, but not Input.
    // The original comment said, "Once the conpty supports these types of input,
    // this check can be removed. See GH#4911". Unfortunately, time has shown
    // us that SSH 7.7 _also_ requests mouse input and that can have a user interface
    // impact on the actual connected terminal. We can't remove this check,
    // because SSH <=7.7 is out in the wild on all versions of Windows <=2004.
    const bool inConpty = IsConsolePty();
    const bool shouldPassthrough = inConpty && IsVtInputEnabled();

    // GH#12799 - If the app requested that we disable focus events, DON'T pass
    // that through. ConPTY would _always_ like to know about focus events.
    const bool disabledFocusEvents = inConpty && (!enabled && mode == TerminalInput::Mode::FocusEvent);

    return !shouldPassthrough || disabledFocusEvents;
}

// Routine Description:
// - Sets the various StateMachine parser modes.
//   SetParserMode is an internal-only "API" call that the vt commands can execute,
//     but it is not represented as a function call on out public API surface.
// Arguments:
// - mode - the parser mode to change.
// - enabled - set to true to enable the mode, false to disable it.
// Return Value:
// - <none>
void ConhostInternalGetSet::SetParserMode(const StateMachine::Mode mode, const bool enabled)
{
    auto& stateMachine = _io.GetActiveOutputBuffer().GetStateMachine();
    stateMachine.SetParserMode(mode, enabled);
}

// Routine Description:
// - Retrieves the various StateMachine parser modes.
//   GetParserMode is an internal-only "API" call that the vt commands can execute,
//     but it is not represented as a function call on out public API surface.
// Arguments:
// - mode - the parser mode to query.

Review comment (suggestion):
FYI purely from a boolean logic, this extra `inConpty` check is unneccessary.
```
!(IsConsolePty && IsVtInputEnabled) || (IsConsolePty && (!enabled && mode == FocusEvent))
```
is equivalent to
```
!IsConsolePty || !IsVtInputEnabled || (!enabled && mode == FocusEvent))
```
Such a expression IMO is also a bit more readable as it's like a "filter" left to right. Due to the early return via `!IsConsolePty` once you're at the `!enabled` part `IsConsolePty` can only be `true` anymore.

Code after:
    auto& textBuffer = screenInfo.GetTextBuffer();
    auto cursorPosition = textBuffer.GetCursor().GetPosition();

    // We turn the cursor on before an operation that might scroll the viewport, otherwise
    // that can result in an old copy of the cursor being left behind on the screen.
    textBuffer.GetCursor().SetIsOn(true);

    // Since we are explicitly moving down a row, clear the wrap status on the row we're leaving
    textBuffer.GetRowByOffset(cursorPosition.Y).SetWrapForced(false);

    cursorPosition.Y += 1;
    if (withReturn)
    {
        cursorPosition.X = 0;
    }
    else
    {
        cursorPosition = textBuffer.ClampPositionWithinLine(cursorPosition);
    }

    THROW_IF_NTSTATUS_FAILED(AdjustCursorPosition(screenInfo, cursorPosition, FALSE, nullptr));
}

// Routine Description:
// - Sends a notify message to play the "SystemHand" sound event.
// Return Value:
// - <none>
void ConhostInternalGetSet::WarningBell()
{
    _io.GetActiveOutputBuffer().SendNotifyBeep();
}

// Routine Description:
// - Sets the title of the console window.
// Arguments:
// - title - The null-terminated string to set as the window title
// Return Value:
// - <none>
void ConhostInternalGetSet::SetWindowTitle(std::wstring_view title)
{
    ServiceLocator::LocateGlobals().getConsoleInformation().SetTitle(title);
}

// Routine Description:
// - Swaps to the alternate screen buffer. In virtual terminals, there exists both a "main"
//     screen buffer and an alternate. This creates a new alternate, and switches to it.
//     If there is an already existing alternate, it is discarded.
// Return Value:
// - <none>
void ConhostInternalGetSet::UseAlternateScreenBuffer()
{