Hide cursor on move

Setting the cursor position on a non-active buffer still displays it on
the active buffer.  Hide the cursor, set the position, show the cursor
is a sufficient workaround.
This commit is contained in:
Jason Hood 2017-12-24 22:39:53 +10:00
parent e8247f3aa7
commit 75f707fc20
2 changed files with 39 additions and 11 deletions

48
ANSI.c
View File

@ -589,11 +589,37 @@ HANDLE hFlushTimer;
void MoveDown( BOOL home ); void MoveDown( BOOL home );
// Well, this is annoying. Setting the cursor position on any buffer always
// displays the cursor on the active buffer (at least on 7). Since there's no
// way to tell which buffer is active (hooking SetConsoleActiveScreenBuffer
// isn't sufficient, since multiple handles could refer to the same buffer),
// hide the cursor, do the move and restore the cursor.
BOOL SetConsoleCursorPos( HANDLE hConsoleOutput, COORD dwCursorPosition )
{
CONSOLE_CURSOR_INFO CursInfo;
BOOL rc;
GetConsoleCursorInfo( hConsoleOutput, &CursInfo );
if (CursInfo.bVisible)
{
CursInfo.bVisible = FALSE;
SetConsoleCursorInfo( hConsoleOutput, &CursInfo );
rc = SetConsoleCursorPosition( hConsoleOutput, dwCursorPosition );
CursInfo.bVisible = TRUE;
SetConsoleCursorInfo( hConsoleOutput, &CursInfo );
}
else
rc = SetConsoleCursorPosition( hConsoleOutput, dwCursorPosition );
return rc;
}
// Set the cursor position, resetting the wrap flag. // Set the cursor position, resetting the wrap flag.
void set_pos( int x, int y ) void set_pos( int x, int y )
{ {
COORD pos = { x, y }; COORD pos = { x, y };
SetConsoleCursorPosition( hConOut, pos ); SetConsoleCursorPos( hConOut, pos );
nWrapped = 0; nWrapped = 0;
} }
@ -768,7 +794,7 @@ void FlushBuffer( void )
c.Y = sr.Top - wi.CURPOS.Y; c.Y = sr.Top - wi.CURPOS.Y;
ScrollConsoleScreenBuffer( hConOut, &sr, &sr, c, &ci ); ScrollConsoleScreenBuffer( hConOut, &sr, &sr, c, &ci );
CUR.Y -= wi.CURPOS.Y; CUR.Y -= wi.CURPOS.Y;
SetConsoleCursorPosition( hConOut, CUR ); SetConsoleCursorPos( hConOut, CUR );
} }
} }
nWrapped += wi.CURPOS.Y; nWrapped += wi.CURPOS.Y;
@ -857,7 +883,7 @@ void PushBuffer( WCHAR c )
if (CUR.X != 0) if (CUR.X != 0)
{ {
CUR.X = 0; CUR.X = 0;
SetConsoleCursorPosition( hConOut, CUR ); SetConsoleCursorPos( hConOut, CUR );
} }
nl = FALSE; nl = FALSE;
break; break;
@ -896,7 +922,7 @@ void PushBuffer( WCHAR c )
{ {
CUR.X = RIGHT; CUR.X = RIGHT;
CUR.Y--; CUR.Y--;
SetConsoleCursorPosition( hConOut, CUR ); SetConsoleCursorPos( hConOut, CUR );
--nWrapped; --nWrapped;
bs = TRUE; bs = TRUE;
} }
@ -1578,7 +1604,7 @@ void InterpretEscSeq( void )
Pos.X = (CUR.X & -8) + p1 * 8; Pos.X = (CUR.X & -8) + p1 * 8;
if (Pos.X > RIGHT) Pos.X = RIGHT; if (Pos.X > RIGHT) Pos.X = RIGHT;
// Don't use set_pos, the tabs could be discarded. // Don't use set_pos, the tabs could be discarded.
SetConsoleCursorPosition( hConOut, Pos ); SetConsoleCursorPos( hConOut, Pos );
return; return;
case 'Z': // CBT - ESC[#Z Moves cursor back # tabs case 'Z': // CBT - ESC[#Z Moves cursor back # tabs
@ -1936,7 +1962,7 @@ void MoveDown( BOOL home )
if (home) if (home)
{ {
CUR.X = 0; CUR.X = 0;
SetConsoleCursorPosition( hConOut, CUR ); SetConsoleCursorPos( hConOut, CUR );
} }
} }
else if (pState->tb_margins && CUR.Y == BOTTOM) else if (pState->tb_margins && CUR.Y == BOTTOM)
@ -1944,7 +1970,7 @@ void MoveDown( BOOL home )
if (home) if (home)
{ {
CUR.X = 0; CUR.X = 0;
SetConsoleCursorPosition( hConOut, CUR ); SetConsoleCursorPos( hConOut, CUR );
} }
} }
else if (CUR.Y == LAST) else if (CUR.Y == LAST)
@ -1960,14 +1986,14 @@ void MoveDown( BOOL home )
if (home) if (home)
{ {
CUR.X = 0; CUR.X = 0;
SetConsoleCursorPosition( hConOut, CUR ); SetConsoleCursorPos( hConOut, CUR );
} }
} }
else else
{ {
if (home) CUR.X = 0; if (home) CUR.X = 0;
++CUR.Y; ++CUR.Y;
SetConsoleCursorPosition( hConOut, CUR ); SetConsoleCursorPos( hConOut, CUR );
} }
} }
@ -2010,7 +2036,7 @@ void MoveUp( void )
else else
{ {
--CUR.Y; --CUR.Y;
SetConsoleCursorPosition( hConOut, CUR ); SetConsoleCursorPos( hConOut, CUR );
} }
} }
@ -2096,7 +2122,7 @@ ParseAndPrintString( HANDLE hDev,
while (++CUR.X < MAX_TABS && !pState->tab_stop[CUR.X]) ; while (++CUR.X < MAX_TABS && !pState->tab_stop[CUR.X]) ;
if (CUR.X > RIGHT) CUR.X = RIGHT; if (CUR.X > RIGHT) CUR.X = RIGHT;
// Don't use set_pos, the tab could be discarded. // Don't use set_pos, the tab could be discarded.
SetConsoleCursorPosition( hConOut, CUR ); SetConsoleCursorPos( hConOut, CUR );
} }
else if (im && (c == HT || c == '\r' || c == '\b' || c == '\n')) else if (im && (c == HT || c == '\r' || c == '\b' || c == '\n'))
{ {

View File

@ -344,6 +344,8 @@ Version History
- fix explicit zero parameters not defaulting to 1; - fix explicit zero parameters not defaulting to 1;
- set color by index (also setting bold/underline); - set color by index (also setting bold/underline);
- fix processes that start without a window; - fix processes that start without a window;
- hide the cursor when moving (prevent it displaying on the active buffer
when moving on another);
* use the system default sound for the bell; * use the system default sound for the bell;
* limit parameters to a maximum value of 32767; * limit parameters to a maximum value of 32767;
* go back to saving the buffer cursor position; * go back to saving the buffer cursor position;