Skip to content

Commit

Permalink
Don't show the cursor if it is outside the console window
Browse files Browse the repository at this point in the history
Fixes #113
  • Loading branch information
rprichard committed Apr 23, 2017
1 parent bae4367 commit 5b99238
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
28 changes: 16 additions & 12 deletions src/agent/Scraper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ WORD Scraper::attributesMask()
}

void Scraper::directScrapeOutput(const ConsoleScreenBufferInfo &info,
bool cursorVisible)
bool consoleCursorVisible)
{
const SmallRect windowRect = info.windowRect();

Expand All @@ -446,11 +446,12 @@ void Scraper::directScrapeOutput(const ConsoleScreenBufferInfo &info,
const int h = scrapeRect.height();

const Coord cursor = info.cursorPosition();
const int cursorColumn = !cursorVisible ? -1 :
constrained(0, cursor.X - scrapeRect.Left, w - 1);
const int cursorLine = !cursorVisible ? -1 :
constrained(0, cursor.Y - scrapeRect.Top, h - 1);
if (!cursorVisible) {
const bool showTerminalCursor =
consoleCursorVisible && scrapeRect.contains(cursor);
const int cursorColumn = !showTerminalCursor ? -1 : cursor.X - scrapeRect.Left;
const int cursorLine = !showTerminalCursor ? -1 : cursor.Y - scrapeRect.Top;

if (!showTerminalCursor) {
m_terminal->hideTerminalCursor();
}

Expand All @@ -467,13 +468,13 @@ void Scraper::directScrapeOutput(const ConsoleScreenBufferInfo &info,
}
}

if (cursorVisible) {
if (showTerminalCursor) {
m_terminal->showTerminalCursor(cursorColumn, cursorLine);
}
}

bool Scraper::scrollingScrapeOutput(const ConsoleScreenBufferInfo &info,
bool cursorVisible,
bool consoleCursorVisible,
bool tentative)
{
const Coord cursor = info.cursorPosition();
Expand Down Expand Up @@ -605,9 +606,12 @@ bool Scraper::scrollingScrapeOutput(const ConsoleScreenBufferInfo &info,
std::min(m_dirtyLineCount, windowRect.top() + windowRect.height()) +
m_scrolledCount;

const int64_t cursorLine = !cursorVisible ? -1 : cursor.Y + m_scrolledCount;
const int cursorColumn = !cursorVisible ? -1 : cursor.X;
if (!cursorVisible) {
const bool showTerminalCursor =
consoleCursorVisible && windowRect.contains(cursor);
const int64_t cursorLine = !showTerminalCursor ? -1 : cursor.Y + m_scrolledCount;
const int cursorColumn = !showTerminalCursor ? -1 : cursor.X;

if (!showTerminalCursor) {
m_terminal->hideTerminalCursor();
}

Expand Down Expand Up @@ -636,7 +640,7 @@ bool Scraper::scrollingScrapeOutput(const ConsoleScreenBufferInfo &info,

m_scrapedLineCount = windowRect.top() + m_scrolledCount;

if (cursorVisible) {
if (showTerminalCursor) {
m_terminal->showTerminalCursor(cursorColumn, cursorLine);
}

Expand Down
4 changes: 2 additions & 2 deletions src/agent/Scraper.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ class Scraper {
ConsoleScreenBufferInfo &finalInfoOut);
WORD attributesMask();
void directScrapeOutput(const ConsoleScreenBufferInfo &info,
bool cursorVisible);
bool consoleCursorVisible);
bool scrollingScrapeOutput(const ConsoleScreenBufferInfo &info,
bool cursorVisible,
bool consoleCursorVisible,
bool tentative);
void syncMarkerText(CHAR_INFO (&output)[SYNC_MARKER_LEN]);
int findSyncMarker();
Expand Down
8 changes: 8 additions & 0 deletions src/agent/SmallRect.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ struct SmallRect : SMALL_RECT
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
{
int x1 = std::max(Left, other.Left);
Expand Down

0 comments on commit 5b99238

Please sign in to comment.