Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't abort early in VT reset operations if one of the steps fails #6763

Merged
2 commits merged into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 37 additions & 55 deletions src/cascadia/TerminalCore/TerminalDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,45 +438,30 @@ bool TerminalDispatch::SoftReset() noexcept
// of what needs to be done.

bool success = CursorVisibility(true); // Cursor enabled.
// if (success)
// {
// success = SetOriginMode(false); // Absolute cursor addressing.
// }
// if (success)
// {
// success = SetAutoWrapMode(true); // Wrap at end of line.
// }
if (success)
{
success = SetCursorKeysMode(false); // Normal characters.
}
if (success)
{
success = SetKeypadMode(false); // Numeric characters.
}
// if (success)
// {
// // Top margin = 1; bottom margin = page length.
// success = _DoSetTopBottomScrollingMargins(0, 0);
// }
// if (success)
// {
// success = DesignateCharset(DispatchTypes::VTCharacterSets::USASCII); // Default Charset
// }
if (success)
{
const auto opt = DispatchTypes::GraphicsOptions::Off;
success = SetGraphicsRendition({ &opt, 1 }); // Normal rendition.
}
// if (success)
// success = SetOriginMode(false) && success; // Absolute cursor addressing.
// success = SetAutoWrapMode(true) && success; // Wrap at end of line.
success = SetCursorKeysMode(false) && success; // Normal characters.
success = SetKeypadMode(false) && success; // Numeric characters.

// // Top margin = 1; bottom margin = page length.
// success = _DoSetTopBottomScrollingMargins(0, 0) && success;

// _termOutput = {}; // Reset all character set designations.
// if (_initialCodePage.has_value())
// {
// // Reset the saved cursor state.
// // Note that XTerm only resets the main buffer state, but that
// // seems likely to be a bug. Most other terminals reset both.
// _savedCursorState.at(0) = {}; // Main buffer
// _savedCursorState.at(1) = {}; // Alt buffer
// // Restore initial code page if previously changed by a DOCS sequence.
// success = _pConApi->SetConsoleOutputCP(_initialCodePage.value()) && success;
// }

const auto opt = DispatchTypes::GraphicsOptions::Off;
success = SetGraphicsRendition({ &opt, 1 }) && success; // Normal rendition.

// // Reset the saved cursor state.
// // Note that XTerm only resets the main buffer state, but that
// // seems likely to be a bug. Most other terminals reset both.
// _savedCursorState.at(0) = {}; // Main buffer
// _savedCursorState.at(1) = {}; // Alt buffer

return success;
}

Expand All @@ -491,34 +476,31 @@ bool TerminalDispatch::HardReset() noexcept
// This code is left here (from its original form in conhost) as a reminder
// of what needs to be done.

bool success = true;

// // If in the alt buffer, switch back to main before doing anything else.
// if (_usingAltBuffer)
// {
// success = _pConApi->PrivateUseMainScreenBuffer();
// _usingAltBuffer = !success;
// }

// Sets the SGR state to normal - this must be done before EraseInDisplay
// to ensure that it clears with the default background color.
bool success = SoftReset();
success = SoftReset() && success;

// Clears the screen - Needs to be done in two operations.
if (success)
{
success = EraseInDisplay(DispatchTypes::EraseType::All);
}
if (success)
{
success = EraseInDisplay(DispatchTypes::EraseType::Scrollback);
}
success = EraseInDisplay(DispatchTypes::EraseType::All) && success;
success = EraseInDisplay(DispatchTypes::EraseType::Scrollback) && success;

// // Set the DECSCNM screen mode back to normal.
// if (success)
// {
// success = SetScreenMode(false);
// }
// success = SetScreenMode(false) && success;

// Cursor to 1,1 - the Soft Reset guarantees this is absolute
if (success)
{
success = CursorPosition(1, 1);
}
success = CursorPosition(1, 1) && success;

// // delete all current tab stops and reapply
// _pConApi->PrivateSetDefaultTabStops();
// // Delete all current tab stops and reapply
// _ResetTabStops();

return success;
}
95 changes: 27 additions & 68 deletions src/terminal/adapter/adaptDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1763,57 +1763,31 @@ bool AdaptDispatch::SingleShift(const size_t gsetNumber)
// True if handled successfully. False otherwise.
bool AdaptDispatch::SoftReset()
{
const bool isPty = _pConApi->IsConsolePty();

bool success = CursorVisibility(true); // Cursor enabled.
if (success)
{
success = SetOriginMode(false); // Absolute cursor addressing.
}
if (success)
{
success = SetAutoWrapMode(true); // Wrap at end of line.
}
if (success)
{
success = SetCursorKeysMode(false); // Normal characters.
}
// SetCursorKeysMode will return false if we're in conpty mode, as to
// trigger a passthrough. If that's the case, just power through here.
if (success || isPty)
{
success = SetKeypadMode(false); // Numeric characters.
}
// SetKeypadMode will return false if we're in conpty mode, as to trigger a
// passthrough. If that's the case, just power through here.
if (success || isPty)
{
// Top margin = 1; bottom margin = page length.
success = _DoSetTopBottomScrollingMargins(0, 0);
}
if (success)
{
_termOutput = {}; // Reset all character set designations.
if (_initialCodePage.has_value())
{
// Restore initial code page if previously changed by a DOCS sequence.
success = _pConApi->SetConsoleOutputCP(_initialCodePage.value());
}
}
if (success)
{
const auto opt = DispatchTypes::GraphicsOptions::Off;
success = SetGraphicsRendition({ &opt, 1 }); // Normal rendition.
}
if (success)
success = SetOriginMode(false) && success; // Absolute cursor addressing.
success = SetAutoWrapMode(true) && success; // Wrap at end of line.
success = SetCursorKeysMode(false) && success; // Normal characters.
success = SetKeypadMode(false) && success; // Numeric characters.

// Top margin = 1; bottom margin = page length.
success = _DoSetTopBottomScrollingMargins(0, 0) && success;

_termOutput = {}; // Reset all character set designations.
if (_initialCodePage.has_value())
{
// Reset the saved cursor state.
// Note that XTerm only resets the main buffer state, but that
// seems likely to be a bug. Most other terminals reset both.
_savedCursorState.at(0) = {}; // Main buffer
_savedCursorState.at(1) = {}; // Alt buffer
// Restore initial code page if previously changed by a DOCS sequence.
success = _pConApi->SetConsoleOutputCP(_initialCodePage.value()) && success;
}

const auto opt = DispatchTypes::GraphicsOptions::Off;
success = SetGraphicsRendition({ &opt, 1 }) && success; // Normal rendition.

// Reset the saved cursor state.
// Note that XTerm only resets the main buffer state, but that
// seems likely to be a bug. Most other terminals reset both.
_savedCursorState.at(0) = {}; // Main buffer
_savedCursorState.at(1) = {}; // Alt buffer

return success;
}

Expand Down Expand Up @@ -1851,34 +1825,19 @@ bool AdaptDispatch::HardReset()

// Sets the SGR state to normal - this must be done before EraseInDisplay
// to ensure that it clears with the default background color.
if (success)
{
success = SoftReset();
}
success = SoftReset() && success;

// Clears the screen - Needs to be done in two operations.
if (success)
{
success = EraseInDisplay(DispatchTypes::EraseType::All);
}
if (success)
{
success = _EraseScrollback();
}
success = EraseInDisplay(DispatchTypes::EraseType::All) && success;
success = EraseInDisplay(DispatchTypes::EraseType::Scrollback) && success;

// Set the DECSCNM screen mode back to normal.
if (success)
{
success = SetScreenMode(false);
}
success = SetScreenMode(false) && success;

// Cursor to 1,1 - the Soft Reset guarantees this is absolute
if (success)
{
success = CursorPosition(1, 1);
}
success = CursorPosition(1, 1) && success;

// delete all current tab stops and reapply
// Delete all current tab stops and reapply
_ResetTabStops();

// GH#2715 - If all this succeeded, but we're in a conpty, return `false` to
Expand Down