diff --git a/reactos/base/shell/cmd/beep.c b/reactos/base/shell/cmd/beep.c index cb0c3126cd7..dc65bde921e 100644 --- a/reactos/base/shell/cmd/beep.c +++ b/reactos/base/shell/cmd/beep.c @@ -41,8 +41,8 @@ INT cmd_beep(LPTSTR param) if (bc == NULL) return 1; #endif - MessageBeep (-1); + ConRingBell(GetStdHandle(STD_OUTPUT_HANDLE)); return 0; } diff --git a/reactos/base/shell/cmd/cls.c b/reactos/base/shell/cmd/cls.c index 40fba204b2a..1e0f2c15ac9 100644 --- a/reactos/base/shell/cmd/cls.c +++ b/reactos/base/shell/cmd/cls.c @@ -32,34 +32,13 @@ INT cmd_cls(LPTSTR param) { - HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE); - CONSOLE_SCREEN_BUFFER_INFO csbi; - COORD coPos; - DWORD dwWritten; - if (!_tcsncmp(param, _T("/?"), 2)) { ConOutResPaging(TRUE, STRING_CLS_HELP); return 0; } - if (GetConsoleScreenBufferInfo(hOutput, &csbi)) - { - coPos.X = 0; - coPos.Y = 0; - FillConsoleOutputAttribute(hOutput, csbi.wAttributes, - csbi.dwSize.X * csbi.dwSize.Y, - coPos, &dwWritten); - FillConsoleOutputCharacter(hOutput, _T(' '), - csbi.dwSize.X * csbi.dwSize.Y, - coPos, &dwWritten); - SetConsoleCursorPosition(hOutput, coPos); - } - else - { - ConOutChar(_T('\f')); - } - + ConClearScreen(GetStdHandle(STD_OUTPUT_HANDLE)); return 0; } diff --git a/reactos/base/shell/cmd/cmd.c b/reactos/base/shell/cmd/cmd.c index f36a1d9d816..3c7aabf4117 100644 --- a/reactos/base/shell/cmd/cmd.c +++ b/reactos/base/shell/cmd/cmd.c @@ -1956,7 +1956,7 @@ Initialize(VOID) } if (wDefColor != 0) - SetScreenColor(wDefColor, FALSE); + ConSetScreenColor(wDefColor, TRUE); #endif if (!*ptr) diff --git a/reactos/base/shell/cmd/cmd.h b/reactos/base/shell/cmd/cmd.h index ce220330692..6dfd6cffea0 100644 --- a/reactos/base/shell/cmd/cmd.h +++ b/reactos/base/shell/cmd/cmd.h @@ -143,7 +143,6 @@ VOID PrintCommandList (VOID); LPCTSTR GetParsedEnvVar ( LPCTSTR varName, UINT* varNameLen, BOOL ModeSetA ); /* Prototypes for COLOR.C */ -BOOL SetScreenColor(WORD wColor, BOOL bNoFill); INT CommandColor(LPTSTR); VOID ConInDummy (VOID); @@ -179,6 +178,19 @@ VOID ConOutResPrintf (UINT resID, ...); VOID ConErrResPrintf (UINT resID, ...); VOID ConOutResPaging(BOOL NewPage, UINT resID); +#ifdef INCLUDE_CMD_BEEP +VOID ConRingBell(HANDLE hOutput); +#endif + +#ifdef INCLUDE_CMD_CLS +VOID ConClearScreen(HANDLE hOutput); +#endif + +#ifdef INCLUDE_CMD_COLOR +BOOL ConSetScreenColor(WORD wColor, BOOL bFill); +#endif + + /* Prototypes for COPY.C */ INT cmd_copy (LPTSTR); diff --git a/reactos/base/shell/cmd/color.c b/reactos/base/shell/cmd/color.c index bc2176df50c..b8ce74952cd 100644 --- a/reactos/base/shell/cmd/color.c +++ b/reactos/base/shell/cmd/color.c @@ -24,36 +24,6 @@ #ifdef INCLUDE_CMD_COLOR -BOOL SetScreenColor(WORD wColor, BOOL bNoFill) -{ - HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); - DWORD dwWritten; - CONSOLE_SCREEN_BUFFER_INFO csbi; - COORD coPos; - - /* Foreground and Background colors can't be the same */ - if ((wColor & 0x0F) == (wColor & 0xF0) >> 4) - return FALSE; - - /* Fill the whole background if needed */ - if (bNoFill != TRUE) - { - GetConsoleScreenBufferInfo(hConsole, &csbi); - - coPos.X = 0; - coPos.Y = 0; - FillConsoleOutputAttribute(hConsole, - wColor & 0x00FF, - csbi.dwSize.X * csbi.dwSize.Y, - coPos, - &dwWritten); - } - - /* Set the text attribute */ - SetConsoleTextAttribute(hConsole, wColor & 0x00FF); - return TRUE; -} - /* * color * @@ -76,7 +46,7 @@ INT CommandColor(LPTSTR rest) /* No parameter: Set the default colors */ if (rest[0] == _T('\0')) { - SetScreenColor(wDefColor, FALSE); + ConSetScreenColor(wDefColor, TRUE); return 0; } @@ -117,7 +87,7 @@ INT CommandColor(LPTSTR rest) * Set the chosen color. Use also the following advanced flag: * /-F to avoid changing already buffered foreground/background. */ - if (SetScreenColor(wColor, (_tcsstr(rest, _T("/-F")) || _tcsstr(rest, _T("/-f")))) == FALSE) + if (ConSetScreenColor(wColor, !_tcsstr(rest, _T("/-F")) && !_tcsstr(rest, _T("/-f"))) == FALSE) { /* Failed because foreground and background colors were the same */ ConErrResPuts(STRING_COLOR_ERROR1); diff --git a/reactos/base/shell/cmd/console.c b/reactos/base/shell/cmd/console.c index 29f9550ff1e..5bf08c49d32 100644 --- a/reactos/base/shell/cmd/console.c +++ b/reactos/base/shell/cmd/console.c @@ -566,4 +566,79 @@ VOID GetScreenSize(PSHORT maxx, PSHORT maxy) if (maxy) *maxy = csbi.dwSize.Y; } + + +#ifdef INCLUDE_CMD_BEEP +VOID ConRingBell(HANDLE hOutput) +{ +#if 0 + /* Emit an error beep sound */ + if (IsConsoleHandle(hOutput)) + Beep(800, 200); + else if (IsTTYHandle(hOutput)) + ConOutPuts(_T("\a")); // BEL character 0x07 + else +#endif + MessageBeep(-1); +} +#endif + +#ifdef INCLUDE_CMD_CLS +VOID ConClearScreen(HANDLE hOutput) +{ + CONSOLE_SCREEN_BUFFER_INFO csbi; + COORD coPos; + DWORD dwWritten; + + if (GetConsoleScreenBufferInfo(hOutput, &csbi)) + { + coPos.X = 0; + coPos.Y = 0; + FillConsoleOutputAttribute(hOutput, csbi.wAttributes, + csbi.dwSize.X * csbi.dwSize.Y, + coPos, &dwWritten); + FillConsoleOutputCharacter(hOutput, _T(' '), + csbi.dwSize.X * csbi.dwSize.Y, + coPos, &dwWritten); + SetConsoleCursorPosition(hOutput, coPos); + } + else + { + ConOutChar(_T('\f')); + } +} +#endif + +#ifdef INCLUDE_CMD_COLOR +BOOL ConSetScreenColor(WORD wColor, BOOL bFill) +{ + HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); + DWORD dwWritten; + CONSOLE_SCREEN_BUFFER_INFO csbi; + COORD coPos; + + /* Foreground and Background colors can't be the same */ + if ((wColor & 0x0F) == (wColor & 0xF0) >> 4) + return FALSE; + + /* Fill the whole background if needed */ + if (bFill) + { + GetConsoleScreenBufferInfo(hConsole, &csbi); + + coPos.X = 0; + coPos.Y = 0; + FillConsoleOutputAttribute(hConsole, + wColor & 0x00FF, + csbi.dwSize.X * csbi.dwSize.Y, + coPos, + &dwWritten); + } + + /* Set the text attribute */ + SetConsoleTextAttribute(hConsole, wColor & 0x00FF); + return TRUE; +} +#endif + /* EOF */