Imported bzip2 modified to build a decompression only dll for use by the ramdisk...
[reactos.git] / rosapps / cmd / color.c
1 /* $Id: color.c,v 1.4 1999/12/04 14:54:50 ekohl Exp $
2 *
3 * COLOR.C - color internal command.
4 *
5 *
6 * History:
7 *
8 * 13-Dec-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
9 * Started.
10 *
11 * 19-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
12 * Unicode ready!
13 *
14 * 20-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
15 * Redirection ready!
16 *
17 * 14-Oct-1999 (Paolo Pantaleo <paolopan@freemail.it>)
18 * 4nt's syntax implemented
19 */
20
21 #include "config.h"
22
23 #ifdef INCLUDE_CMD_COLOR
24 #include <windows.h>
25 #include <tchar.h>
26 #include <string.h>
27 #include <stdlib.h>
28
29 #include "cmd.h"
30
31 static VOID ColorHelp (VOID)
32 {
33 ConOutPuts (_T(
34 "Sets the default foreground and background colors.\n"
35 "\n"
36 "COLOR [attr [/F]] \n\n"
37 " attr Specifies color attribute of console output\n"
38 " /F fill the console with color attribute\n"
39 "\n"
40 "There are three ways to specify the colors:"
41 ));
42
43 ConOutPuts (_T(
44 "\n"
45 "1) [bright] name on [bright] name (only the first three letters are required)\n"
46 "2) decimal on decimal\n"
47 "3) two hex digits\n"
48 "\n"
49 "Colors are:"
50 ));
51
52 ConOutPuts (_T(
53 "dec hex name dec hex name\n"
54 "0 0 Black 8 8 Gray(Bright black)\n"
55 "1 1 Blue 9 9 Bright Blue\n"
56 "2 2 Green 10 A Bright Green\n"
57 "3 3 Cyan 11 B Bright Cyan\n"
58 "4 4 Red 12 C Bright Red\n"
59 "5 5 Magenta 13 D Bright Magenta\n"
60 "6 6 Yellow 14 E Bright Yellow\n"
61 "7 7 White 15 F Bright White"));
62 }
63
64
65 VOID SetScreenColor (WORD wColor, BOOL bFill)
66 {
67 DWORD dwWritten;
68 CONSOLE_SCREEN_BUFFER_INFO csbi;
69 COORD coPos;
70
71 if (bFill == TRUE)
72 {
73 GetConsoleScreenBufferInfo (hOut, &csbi);
74
75 coPos.X = 0;
76 coPos.Y = 0;
77 FillConsoleOutputAttribute (hOut,
78 (WORD)(wColor & 0x00FF),
79 (csbi.dwSize.X)*(csbi.dwSize.Y),
80 coPos,
81 &dwWritten);
82 }
83 SetConsoleTextAttribute (hOut, (WORD)(wColor & 0x00FF));
84 }
85
86
87 /*
88 * color
89 *
90 * internal dir command
91 */
92 INT CommandColor (LPTSTR first, LPTSTR rest)
93 {
94 if (_tcsncmp (rest, _T("/?"), 2) == 0)
95 {
96 ColorHelp ();
97 return 0;
98 }
99
100 if (rest[0] == _T('\0'))
101 {
102 /* set default color */
103 wColor = wDefColor;
104 SetScreenColor (wColor, TRUE);
105 return 0;
106 }
107
108 if (StringToColor (&wColor, &rest) == FALSE)
109 {
110 ConErrPuts("error in color specification");
111 return 1;
112 }
113
114 ConErrPrintf ("Color %x\n", wColor);
115
116 if ((wColor & 0xF) == (wColor &0xF0) >> 4)
117 {
118 ConErrPuts (_T("same colors error!"));
119 return 1;
120 }
121
122 /* set color */
123 SetScreenColor (wColor,
124 (_tcsstr (rest,"/F") || _tcsstr (rest,"/f")));
125
126 return 0;
127 }
128
129 #endif /* INCLUDE_CMD_COLOR */
130
131 /* EOF */