[Winbash-checkins] CVS: winbash/lib/readline display.c,1.7,1.8
Brought to you by:
enricobrunetta,
xks
From: kevin s. <xk...@us...> - 2002-03-29 10:51:31
|
Update of /cvsroot/winbash/winbash/lib/readline In directory usw-pr-cvs1:/tmp/cvs-serv9563 Modified Files: display.c Log Message: fixed (i hope) problems with scrolling/display when the end of the screen buffer has been reached. Index: display.c =================================================================== RCS file: /cvsroot/winbash/winbash/lib/readline/display.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- display.c 26 Mar 2002 17:20:27 -0000 1.7 +++ display.c 29 Mar 2002 10:51:28 -0000 1.8 @@ -1323,12 +1323,56 @@ int to; { CONSOLE_SCREEN_BUFFER_INFO csbi; + if ( (_rl_last_v_pos != to) && (to <= _rl_screenheight) && haveConsole && GetConsoleScreenBufferInfo(hStdout, &csbi) ) { csbi.dwCursorPosition.Y += to - _rl_last_v_pos; - if ( SetConsoleCursorPosition(hStdout, csbi.dwCursorPosition) ) - _rl_last_v_pos = to; + + /* if moving past the end of the screen buffer, + we need to scroll the screen buffer up, discarding + the top n lines, where n=to-_rl_last_v_pos + + XXX be wary of off-by-one errors here... */ + if (csbi.dwCursorPosition.Y >= csbi.dwSize.Y) + { + SMALL_RECT scroll; + COORD new_coord; + CHAR_INFO fillchar; + + /* discard the to n lines */ + scroll.Top = to - _rl_last_v_pos; + scroll.Bottom = csbi.dwSize.Y - 1; + scroll.Left = 0; + scroll.Right = csbi.dwSize.X - 1; + + /* scroll region is moving to beginning of screen + buffer */ + new_coord.X = 0; + new_coord.Y = 0; + + /* fill the right character and attributes */ + fillchar.Char.AsciiChar = ' '; + fillchar.Attributes = csbi.wAttributes; + + /* scrolling the console buffer moves to cursor, + so adjust _rl_last_v_pos here */ + if (ScrollConsoleScreenBuffer(hStdout, + &scroll, + NULL, /* no clipping region */ + new_coord, + &fillchar)) + { + _rl_last_v_pos = to; + } + } + else + { + /* if not moving past the end of the screen buffer, just move + the cursor */ + if ( SetConsoleCursorPosition(hStdout, csbi.dwCursorPosition) ) + _rl_last_v_pos = to; + } } } |