Don't show the cursor if it is outside the console window

Fixes https://github.com/rprichard/winpty/issues/113
This commit is contained in:
Ryan Prichard 2017-04-22 23:41:22 -07:00
parent bae43674b1
commit 5b99238fca
3 changed files with 26 additions and 14 deletions

View File

@ -432,7 +432,7 @@ WORD Scraper::attributesMask()
} }
void Scraper::directScrapeOutput(const ConsoleScreenBufferInfo &info, void Scraper::directScrapeOutput(const ConsoleScreenBufferInfo &info,
bool cursorVisible) bool consoleCursorVisible)
{ {
const SmallRect windowRect = info.windowRect(); const SmallRect windowRect = info.windowRect();
@ -446,11 +446,12 @@ void Scraper::directScrapeOutput(const ConsoleScreenBufferInfo &info,
const int h = scrapeRect.height(); const int h = scrapeRect.height();
const Coord cursor = info.cursorPosition(); const Coord cursor = info.cursorPosition();
const int cursorColumn = !cursorVisible ? -1 : const bool showTerminalCursor =
constrained(0, cursor.X - scrapeRect.Left, w - 1); consoleCursorVisible && scrapeRect.contains(cursor);
const int cursorLine = !cursorVisible ? -1 : const int cursorColumn = !showTerminalCursor ? -1 : cursor.X - scrapeRect.Left;
constrained(0, cursor.Y - scrapeRect.Top, h - 1); const int cursorLine = !showTerminalCursor ? -1 : cursor.Y - scrapeRect.Top;
if (!cursorVisible) {
if (!showTerminalCursor) {
m_terminal->hideTerminalCursor(); m_terminal->hideTerminalCursor();
} }
@ -467,13 +468,13 @@ void Scraper::directScrapeOutput(const ConsoleScreenBufferInfo &info,
} }
} }
if (cursorVisible) { if (showTerminalCursor) {
m_terminal->showTerminalCursor(cursorColumn, cursorLine); m_terminal->showTerminalCursor(cursorColumn, cursorLine);
} }
} }
bool Scraper::scrollingScrapeOutput(const ConsoleScreenBufferInfo &info, bool Scraper::scrollingScrapeOutput(const ConsoleScreenBufferInfo &info,
bool cursorVisible, bool consoleCursorVisible,
bool tentative) bool tentative)
{ {
const Coord cursor = info.cursorPosition(); const Coord cursor = info.cursorPosition();
@ -605,9 +606,12 @@ bool Scraper::scrollingScrapeOutput(const ConsoleScreenBufferInfo &info,
std::min(m_dirtyLineCount, windowRect.top() + windowRect.height()) + std::min(m_dirtyLineCount, windowRect.top() + windowRect.height()) +
m_scrolledCount; m_scrolledCount;
const int64_t cursorLine = !cursorVisible ? -1 : cursor.Y + m_scrolledCount; const bool showTerminalCursor =
const int cursorColumn = !cursorVisible ? -1 : cursor.X; consoleCursorVisible && windowRect.contains(cursor);
if (!cursorVisible) { const int64_t cursorLine = !showTerminalCursor ? -1 : cursor.Y + m_scrolledCount;
const int cursorColumn = !showTerminalCursor ? -1 : cursor.X;
if (!showTerminalCursor) {
m_terminal->hideTerminalCursor(); m_terminal->hideTerminalCursor();
} }
@ -636,7 +640,7 @@ bool Scraper::scrollingScrapeOutput(const ConsoleScreenBufferInfo &info,
m_scrapedLineCount = windowRect.top() + m_scrolledCount; m_scrapedLineCount = windowRect.top() + m_scrolledCount;
if (cursorVisible) { if (showTerminalCursor) {
m_terminal->showTerminalCursor(cursorColumn, cursorLine); m_terminal->showTerminalCursor(cursorColumn, cursorLine);
} }

View File

@ -73,9 +73,9 @@ private:
ConsoleScreenBufferInfo &finalInfoOut); ConsoleScreenBufferInfo &finalInfoOut);
WORD attributesMask(); WORD attributesMask();
void directScrapeOutput(const ConsoleScreenBufferInfo &info, void directScrapeOutput(const ConsoleScreenBufferInfo &info,
bool cursorVisible); bool consoleCursorVisible);
bool scrollingScrapeOutput(const ConsoleScreenBufferInfo &info, bool scrollingScrapeOutput(const ConsoleScreenBufferInfo &info,
bool cursorVisible, bool consoleCursorVisible,
bool tentative); bool tentative);
void syncMarkerText(CHAR_INFO (&output)[SYNC_MARKER_LEN]); void syncMarkerText(CHAR_INFO (&output)[SYNC_MARKER_LEN]);
int findSyncMarker(); int findSyncMarker();

View File

@ -76,6 +76,14 @@ struct SmallRect : SMALL_RECT
other.Bottom <= Bottom; other.Bottom <= Bottom;
} }
bool contains(const Coord &other) const
{
return other.X >= Left &&
other.X <= Right &&
other.Y >= Top &&
other.Y <= Bottom;
}
SmallRect intersected(const SmallRect &other) const SmallRect intersected(const SmallRect &other) const
{ {
int x1 = std::max(Left, other.Left); int x1 = std::max(Left, other.Left);