Author: hbelusca
Date: Sat Sep 30 14:10:21 2017
New Revision: 76000
URL:
http://svn.reactos.org/svn/reactos?rev=76000&view=rev
Log:
[CMD]: Little refactoring to lay out the way to using the CONUTILS library in CMD.
- Move the code used to beep, clear screen, and color the screen into console.c ;
- Rename SetScreenColor into ConSetScreenColor, and invert its second parameter (bNoFill
-> bFill); its default behaviour is to fill all the screen.
Modified:
trunk/reactos/base/shell/cmd/beep.c
trunk/reactos/base/shell/cmd/cls.c
trunk/reactos/base/shell/cmd/cmd.c
trunk/reactos/base/shell/cmd/cmd.h
trunk/reactos/base/shell/cmd/color.c
trunk/reactos/base/shell/cmd/console.c
Modified: trunk/reactos/base/shell/cmd/beep.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/beep.c?rev=…
==============================================================================
--- trunk/reactos/base/shell/cmd/beep.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/beep.c [iso-8859-1] Sat Sep 30 14:10:21 2017
@@ -41,8 +41,8 @@
if (bc == NULL)
return 1;
#endif
- MessageBeep (-1);
+ ConRingBell(GetStdHandle(STD_OUTPUT_HANDLE));
return 0;
}
Modified: trunk/reactos/base/shell/cmd/cls.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cls.c?rev=7…
==============================================================================
--- trunk/reactos/base/shell/cmd/cls.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/cls.c [iso-8859-1] Sat Sep 30 14:10:21 2017
@@ -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;
}
Modified: trunk/reactos/base/shell/cmd/cmd.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmd.c?rev=7…
==============================================================================
--- trunk/reactos/base/shell/cmd/cmd.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/cmd.c [iso-8859-1] Sat Sep 30 14:10:21 2017
@@ -1956,7 +1956,7 @@
}
if (wDefColor != 0)
- SetScreenColor(wDefColor, FALSE);
+ ConSetScreenColor(wDefColor, TRUE);
#endif
if (!*ptr)
Modified: trunk/reactos/base/shell/cmd/cmd.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/cmd.h?rev=7…
==============================================================================
--- trunk/reactos/base/shell/cmd/cmd.h [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/cmd.h [iso-8859-1] Sat Sep 30 14:10:21 2017
@@ -143,7 +143,6 @@
LPCTSTR GetParsedEnvVar ( LPCTSTR varName, UINT* varNameLen, BOOL ModeSetA );
/* Prototypes for COLOR.C */
-BOOL SetScreenColor(WORD wColor, BOOL bNoFill);
INT CommandColor(LPTSTR);
VOID ConInDummy (VOID);
@@ -178,6 +177,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);
Modified: trunk/reactos/base/shell/cmd/color.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/color.c?rev…
==============================================================================
--- trunk/reactos/base/shell/cmd/color.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/color.c [iso-8859-1] Sat Sep 30 14:10:21 2017
@@ -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 @@
/* No parameter: Set the default colors */
if (rest[0] == _T('\0'))
{
- SetScreenColor(wDefColor, FALSE);
+ ConSetScreenColor(wDefColor, TRUE);
return 0;
}
@@ -117,7 +87,7 @@
* 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);
Modified: trunk/reactos/base/shell/cmd/console.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/console.c?r…
==============================================================================
--- trunk/reactos/base/shell/cmd/console.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/console.c [iso-8859-1] Sat Sep 30 14:10:21 2017
@@ -566,4 +566,79 @@
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 */