[CMD]: Little refactoring to lay out the way to using the CONUTILS library in CMD.
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 30 Sep 2017 14:10:21 +0000 (14:10 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sat, 30 Sep 2017 14:10:21 +0000 (14:10 +0000)
- 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.

svn path=/trunk/; revision=76000

reactos/base/shell/cmd/beep.c
reactos/base/shell/cmd/cls.c
reactos/base/shell/cmd/cmd.c
reactos/base/shell/cmd/cmd.h
reactos/base/shell/cmd/color.c
reactos/base/shell/cmd/console.c

index cb0c312..dc65bde 100644 (file)
@@ -41,8 +41,8 @@ INT cmd_beep(LPTSTR param)
     if (bc == NULL)
         return 1;
 #endif
     if (bc == NULL)
         return 1;
 #endif
-    MessageBeep (-1);
 
 
+    ConRingBell(GetStdHandle(STD_OUTPUT_HANDLE));
     return 0;
 }
 
     return 0;
 }
 
index 40fba20..1e0f2c1 100644 (file)
 
 INT cmd_cls(LPTSTR param)
 {
 
 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 (!_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;
 }
 
     return 0;
 }
 
index f36a1d9..3c7aabf 100644 (file)
@@ -1956,7 +1956,7 @@ Initialize(VOID)
     }
 
     if (wDefColor != 0)
     }
 
     if (wDefColor != 0)
-        SetScreenColor(wDefColor, FALSE);
+        ConSetScreenColor(wDefColor, TRUE);
 #endif
 
     if (!*ptr)
 #endif
 
     if (!*ptr)
index ce22033..6dfd6cf 100644 (file)
@@ -143,7 +143,6 @@ VOID PrintCommandList (VOID);
 LPCTSTR GetParsedEnvVar ( LPCTSTR varName, UINT* varNameLen, BOOL ModeSetA );
 
 /* Prototypes for COLOR.C */
 LPCTSTR GetParsedEnvVar ( LPCTSTR varName, UINT* varNameLen, BOOL ModeSetA );
 
 /* Prototypes for COLOR.C */
-BOOL SetScreenColor(WORD wColor, BOOL bNoFill);
 INT CommandColor(LPTSTR);
 
 VOID ConInDummy (VOID);
 INT CommandColor(LPTSTR);
 
 VOID ConInDummy (VOID);
@@ -179,6 +178,19 @@ VOID ConOutResPrintf (UINT resID, ...);
 VOID ConErrResPrintf (UINT resID, ...);
 VOID ConOutResPaging(BOOL NewPage, 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);
 
 /* Prototypes for COPY.C */
 INT cmd_copy (LPTSTR);
 
index bc2176d..b8ce749 100644 (file)
 
 #ifdef INCLUDE_CMD_COLOR
 
 
 #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
  *
 /*
  * color
  *
@@ -76,7 +46,7 @@ INT CommandColor(LPTSTR rest)
     /* No parameter: Set the default colors */
     if (rest[0] == _T('\0'))
     {
     /* No parameter: Set the default colors */
     if (rest[0] == _T('\0'))
     {
-        SetScreenColor(wDefColor, FALSE);
+        ConSetScreenColor(wDefColor, TRUE);
         return 0;
     }
 
         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.
      */
      * 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);
     {
         /* Failed because foreground and background colors were the same */
         ConErrResPuts(STRING_COLOR_ERROR1);
index 29f9550..5bf08c4 100644 (file)
@@ -566,4 +566,79 @@ VOID GetScreenSize(PSHORT maxx, PSHORT maxy)
     if (maxy) *maxy = csbi.dwSize.Y;
 }
 
     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 */
 /* EOF */