Clear screen on exit, fix gnome-terminal issue on resize

This commit is contained in:
John Sennesael 2021-08-29 13:45:49 -05:00
parent c5c23d4176
commit 9a56e6dfaa
5 changed files with 50 additions and 0 deletions

View File

@ -401,6 +401,11 @@ void ClearScreen();
*/
Vector2D GetCursorPos();
/**
* @brief Hides the cursor.
*/
void HideCursor();
/**
* @brief Sets the cursor position.
*
@ -478,6 +483,11 @@ void SetMouseReporting(
MouseCoordinateMode coordinateMode = MouseCoordinateMode::Character
);
/**
* @brief Makes cursor visible.
*/
void ShowCursor();
/**
* Convert Color enum to ANSI background color code.
*

View File

@ -114,6 +114,11 @@ public:
*/
bool Dirty() const;
/**
* @brief Forces the entire buffer to be redrawn on next render.
*/
void ForceRedrawAll();
/**
* @brief Check initialized.
*

View File

@ -42,6 +42,11 @@ void Application::Initialize()
const Vector2D newSize = m_terminal.Size() - Vector2D(1, 1);
Size(newSize, m_bgFillCharacter);
OnResize(newSize);
/**
* @todo A complete redraw on resize seems to be needed for VTE based
* terminals for some reason. Debug this some day probably never.
*/
ForceRedrawAll();
});
m_terminal.SetOnTerminate([&](){
Stop();
@ -75,6 +80,7 @@ void Application::Run()
);
}
ClearScreen();
HideCursor();
m_running = true;
InitializeViews();
while (m_running)
@ -87,7 +93,10 @@ void Application::Run()
void Application::Stop()
{
ClearScreen();
SetMouseReporting(MouseEventMode::None);
ShowCursor();
IO::Get().Write(L"\r\n"); // Just in case we need a buffer flush.
IO::Get().Write(ansi::MakeEscapeSequence(ansi::EscapeSequence::RIS));
m_terminal.Cleanup();
m_running = false;

View File

@ -328,6 +328,16 @@ Vector2D GetCursorPos()
return {x, y};
}
void HideCursor()
{
IO::Get().Write(
ansi::MakeDecPmSequence(
ansi::DecPmSequence::DECTECM,
ansi::DecPmSuffix::DISABLE
)
);
}
void SetCursorPos(const Vector2D& pos, bool relative)
{
// ansi cursor positions are 1-based, ours are 0-based, so we add one.
@ -456,6 +466,16 @@ void SetMouseReporting(
IO::Get().Write(outStr);
}
void ShowCursor()
{
IO::Get().Write(
ansi::MakeDecPmSequence(
ansi::DecPmSequence::DECTECM,
ansi::DecPmSuffix::ENABLE
)
);
}
std::wstring ToAnsiBgColor(StandardColor c)
{
switch(c)

View File

@ -51,6 +51,12 @@ bool View::Dirty() const
return m_dirty;
}
void View::ForceRedrawAll()
{
const std::lock_guard<std::mutex> previousBufferLock(m_previousBufferMutex);
m_previousBuffer.clear();
}
void View::Initialize()
{
m_initialized = true;