Dave \Crash\ Dummy
7/18/2011 1:34:00 PM
"Ben Bacarisse" <ben.usenet@bsb.me.uk> schrieb im Newsbeitrag
news:0.dac296d5b2e0c6dcc860.20110718123404BST.87ei1nesb7.fsf@bsb.me.uk...
....
> Almost all "console programs" run in a window (or maybe even real
> hardware) that understands ANSI control sequences. If all you want to
> do is a few simple operations like clearing the screen, you could write
> short functions that produce the correct sequence. For example,
>
> void screen_clear(void) { puts("\x1b[H\x1b[2J"); }
>
> moves the cursor to the top of the screen and the clears it.
....
The windows console does not natively understand ANSI control sequences. You
would explicitely have to load the ANSI driver. And I was told not to use
hardcoded ANSI control sequences on Unix either.
my code for clearing the screen is the following (working with Turbo C 2.0,
Borland C++Builder 5, MSVC, Linux, SCO Unix, SINIX). clear() is defined on
Unix in curses.h . clrscr() is defined on Turbo C in conio.h , but on
Borland C++Builder clrscr() does not clear more then 44 lines (a Windows
console may have more).
#if defined(sinix) || defined(SNI) || defined(M_UNIX) ||
defined(linux)
#define Unix
#endif
#ifdef Unix
#include <termios.h>
#include <curses.h>
#else
#include <conio.h>
#endif
#ifdef __TURBOC__
#if __TURBOC__ <= 0x0200
#define clear clrscr
#else
#define ReplaceConio
#include <windows.h>
#endif
#endif
#ifdef MSDOS
#define clear() _clearscreen(_GCLEARSCREEN)
#endif
#ifdef _MSC_VER
#define ReplaceConio
#include <windows.h>
#include <wincon.h>
#endif
#ifdef ReplaceConio
void clear(void)
{
COORD coordScreen;
DWORD cCharsWritten,
dwConSize;
HANDLE hConsole;
CONSOLE_SCREEN_BUFFER_INFO csbi;
coordScreen.X = 0;
coordScreen.Y = 0;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsole, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter(hConsole, ' ', dwConSize,
coordScreen, &cCharsWritten);
FillConsoleOutputAttribute(hConsole, csbi.wAttributes,
dwConSize, coordScreen,
&cCharsWritten);
SetConsoleCursorPosition(
GetStdHandle(STD_OUTPUT_HANDLE), coordScreen);
}
#endif