[Winbash-checkins] CVS: winbash/lib/readline display.c,1.6,1.7
Brought to you by:
enricobrunetta,
xks
From: kevin s. <xk...@us...> - 2002-03-26 17:20:32
|
Update of /cvsroot/winbash/winbash/lib/readline In directory usw-pr-cvs1:/tmp/cvs-serv22830 Modified Files: display.c Log Message: implement _rl_clear_screen for windows console app. Index: display.c =================================================================== RCS file: /cvsroot/winbash/winbash/lib/readline/display.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- display.c 26 Mar 2002 00:33:42 -0000 1.6 +++ display.c 26 Mar 2002 17:20:27 -0000 1.7 @@ -1587,20 +1587,73 @@ return; } -#endif /* __MINGW32__ */ +/* Standard error macro for reporting API errors */ +#define PERR(bSuccess, api){if(!(bSuccess)) \ + printf("%s:Error %d from %s on line %d\n", __FILE__, GetLastError(), api, __LINE__);} + +/** + * screen clearing function found at: + * ftp://ftp.microsoft.com/developr/win32dk/kb/q99/2/61.txt + */ +static void cls( HANDLE hConsole ) +{ + COORD coordScreen = { 0, 0 }; /* here's where we'll home the + cursor */ + BOOL bSuccess; + DWORD cCharsWritten; + CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */ + DWORD dwConSize; /* number of character cells in + the current buffer */ + + /* get the number of character cells in the current buffer */ + + bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi ); + PERR( bSuccess, "GetConsoleScreenBufferInfo" ); + dwConSize = csbi.dwSize.X * csbi.dwSize.Y; + + /* fill the entire screen with blanks */ + + bSuccess = FillConsoleOutputCharacter( hConsole, (TCHAR) ' ', + dwConSize, coordScreen, &cCharsWritten ); + PERR( bSuccess, "FillConsoleOutputCharacter" ); + + /* get the current text attribute */ + + bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi ); + PERR( bSuccess, "ConsoleScreenBufferInfo" ); + + /* now set the buffer's attributes accordingly */ + + bSuccess = FillConsoleOutputAttribute( hConsole, csbi.wAttributes, + dwConSize, coordScreen, &cCharsWritten ); + PERR( bSuccess, "FillConsoleOutputAttribute" ); + + /* put the cursor at (0, 0) */ + + bSuccess = SetConsoleCursorPosition( hConsole, coordScreen ); + PERR( bSuccess, "SetConsoleCursorPosition" ); + return; +} void _rl_clear_screen () { + cls(hStdout); + cr(); +} + +#endif /* __MINGW32__ */ + #ifndef __MINGW32__ +void +_rl_clear_screen () +{ if (_rl_term_clrpag) tputs (_rl_term_clrpag, 1, _rl_output_character_function); else -#endif rl_crlf (); } -#ifndef __MINGW32__ /* Insert COUNT characters from STRING to the output stream. */ static void insert_some_chars (string, count) |