f5d086704dbd8f077c56f2c083f0b19061fbfe55
[reactos.git] / rosapps / cmd / color.c
1 /*
2 * COLOR.C - color internal command.
3 *
4 *
5 * History:
6 *
7 * 13-Dec-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
8 * Started.
9 *
10 * 19-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
11 * Unicode ready!
12 *
13 * 20-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
14 * Redirection ready!
15 */
16
17 #define WIN32_LEAN_AND_MEAN
18
19 #include "config.h"
20
21 #ifdef INCLUDE_CMD_COLOR
22 #include <windows.h>
23 #include <tchar.h>
24 #include <string.h>
25 #include <stdlib.h>
26
27 #include "cmd.h"
28
29
30 VOID SetScreenColor (WORD wColor)
31 {
32 DWORD dwWritten;
33 CONSOLE_SCREEN_BUFFER_INFO csbi;
34 COORD coPos;
35
36 GetConsoleScreenBufferInfo (hOut, &csbi);
37
38 coPos.X = 0;
39 coPos.Y = 0;
40 FillConsoleOutputAttribute (hOut, wColor,
41 (csbi.dwSize.X)*(csbi.dwSize.Y),
42 coPos, &dwWritten);
43 SetConsoleTextAttribute (hOut, wColor);
44 }
45
46
47 /*
48 * color
49 *
50 * internal dir command
51 */
52 INT cmd_color (LPTSTR first, LPTSTR rest)
53 {
54 if (_tcsncmp (rest, _T("/?"), 2) == 0)
55 {
56 ConOutPuts (_T("Sets the default foreground and background colors.\n\n"
57 "COLOR [attr]\n\n"
58 " attr Specifies color attribute of console output\n\n"
59 "Color attributes are specified by TWO hex digits -- the first\n"
60 "corresponds to the background; the second to the foreground. Each digit\n"
61 "can be one of the following:\n"));
62
63 ConOutPuts (_T(" 0 = Black 8 = Gray\n"
64 " 1 = Blue 9 = Light Blue\n"
65 " 2 = Green A = Light Green\n"
66 " 3 = Aqua B = Light Aqua\n"
67 " 4 = Red C = Light Red\n"
68 " 5 = Purple D = Light Purple\n"
69 " 6 = Yellow E = Light Yellow\n"
70 " 7 = White F = Bright White\n"));
71 return 0;
72 }
73
74 if (rest[0] == _T('\0'))
75 {
76 /* set default color */
77 wColor = wDefColor;
78 SetScreenColor (wColor);
79 return 0;
80 }
81
82 if (_tcslen (rest) != 2)
83 {
84 ConErrPuts (_T("parameter error!"));
85 return 1;
86 }
87
88 wColor = (WORD)_tcstoul (rest, NULL, 16);
89
90 if ((wColor & 0xF) == (wColor &0xF0) >> 4)
91 {
92 ConErrPuts (_T("same colors error!"));
93 return 1;
94 }
95
96 /* set color */
97 SetScreenColor (wColor);
98
99 return 0;
100 }
101
102 #endif