@@ -55,6 +55,8 @@ int ScreenX;
5555int ScreenY ;
5656int ScrollTop ;
5757int ScrollBottom ;
58+ int LastCursorX ;
59+ int LastCursorY ;
5860
5961char * pSavedScreen = NULL ;
6062static COORD ZeroCoord = {0 ,0 };
@@ -1092,7 +1094,7 @@ void ConScrollDownEntireBuffer()
10921094
10931095 if (!GetConsoleScreenBufferInfo (hOutputConsole , & ConsoleInfo ))
10941096 return ;
1095- ConScrollDown (0 ,ConsoleInfo .dwSize .Y - 1 );
1097+ ConScrollDown (0 , ConsoleInfo .dwSize .Y - 1 );
10961098 return ;
10971099}
10981100
@@ -1102,7 +1104,7 @@ void ConScrollUpEntireBuffer()
11021104
11031105 if (!GetConsoleScreenBufferInfo (hOutputConsole , & ConsoleInfo ))
11041106 return ;
1105- ConScrollUp (0 ,ConsoleInfo .dwSize .Y - 1 );
1107+ ConScrollUp (0 , ConsoleInfo .dwSize .Y - 1 );
11061108 return ;
11071109}
11081110
@@ -1141,15 +1143,15 @@ void ConScrollUp(int topline,int botline)
11411143 Fill .Attributes = ConsoleInfo .wAttributes ;
11421144 Fill .Char .AsciiChar = ' ' ;
11431145
1144- ScrollConsoleScreenBuffer ( hOutputConsole ,
1146+ BOOL bRet = ScrollConsoleScreenBuffer ( hOutputConsole ,
11451147 & ScrollRect ,
11461148 & ClipRect ,
11471149 destination ,
11481150 & Fill
11491151 );
11501152}
11511153
1152- void ConScrollDown (int topline ,int botline )
1154+ void ConScrollDown (int topline , int botline )
11531155{
11541156 SMALL_RECT ScrollRect ;
11551157 SMALL_RECT ClipRect ;
@@ -1160,32 +1162,32 @@ void ConScrollDown(int topline,int botline)
11601162 if (!GetConsoleScreenBufferInfo (hOutputConsole , & ConsoleInfo ))
11611163 return ;
11621164
1163- if ((botline - topline ) == ConsoleInfo .dwSize .Y - 1 ) // scrolling whole buffer
1165+ if ((botline - topline ) == ConsoleInfo .dwSize .Y - 1 ) // scrolling whole buffer
11641166 {
11651167 ScrollRect .Top = topline ;
11661168 ScrollRect .Bottom = botline ;
11671169 }
11681170 else
11691171 {
1170- ScrollRect .Top = topline + ConsoleInfo .srWindow .Top + 1 ;
1172+ ScrollRect .Top = topline + ConsoleInfo .srWindow .Top + 1 ;
11711173 ScrollRect .Bottom = botline + ConsoleInfo .srWindow .Top ;
11721174 }
11731175
11741176 ScrollRect .Left = 0 ;
1175- ScrollRect .Right = ConScreenSizeX ()- 1 ;
1177+ ScrollRect .Right = ConScreenSizeX () - 1 ;
11761178
11771179 ClipRect .Top = ScrollRect .Top ;
11781180 ClipRect .Bottom = ScrollRect .Bottom ;
11791181 ClipRect .Left = ScrollRect .Left ;
11801182 ClipRect .Right = ScrollRect .Right ;
11811183
11821184 destination .X = 0 ;
1183- destination .Y = ScrollRect .Top - 1 ;
1185+ destination .Y = ScrollRect .Top - 1 ;
11841186
11851187 Fill .Attributes = ConsoleInfo .wAttributes ;
11861188 Fill .Char .AsciiChar = ' ' ;
11871189
1188- ScrollConsoleScreenBuffer ( hOutputConsole ,
1190+ BOOL bRet = ScrollConsoleScreenBuffer ( hOutputConsole ,
11891191 & ScrollRect ,
11901192 NULL ,
11911193 destination ,
@@ -1224,8 +1226,20 @@ void ConSetCursorPosition(int x, int y)
12241226 Coord .X = (short )(x );
12251227 Coord .Y = (short )(y );
12261228
1229+ if ((y > ConsoleInfo .dwSize .Y - 1 ) && y > LastCursorY ) {
1230+ for (int n = LastCursorY ; n < y ; n ++ )
1231+ GoToNextLine ();
1232+ }
1233+
1234+ if (y >= ConsoleInfo .dwSize .Y ) {
1235+ Coord .Y = ConsoleInfo .dwSize .Y - 1 ;
1236+ }
1237+
12271238 if (!SetConsoleCursorPosition (hOutputConsole , Coord ))
12281239 rc = GetLastError ();
1240+
1241+ LastCursorX = x ;
1242+ LastCursorY = y ;
12291243}
12301244
12311245BOOL ConChangeCursor ( CONSOLE_CURSOR_INFO * pCursorInfo )
0 commit comments