Crtl-C gives a new line when reading input
[reactos.git] / reactos / subsys / system / 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 * 14-Oct-1999 (Paolo Pantaleo <paolopan@freemail.it>)
17 * 4nt's syntax implemented.
18 *
19 * 03-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
20 * Move all hardcoded strings to En.rc.
21 */
22
23 #include <precomp.h>
24 #include "resource.h"
25
26 #ifdef INCLUDE_CMD_COLOR
27
28
29
30
31
32 VOID SetScreenColor (WORD wColor, BOOL bNoFill)
33 {
34 DWORD dwWritten;
35 CONSOLE_SCREEN_BUFFER_INFO csbi;
36 COORD coPos;
37
38
39 if ((wColor & 0xF) == (wColor &0xF0) >> 4)
40 {
41 ConErrResPuts(STRING_COLOR_ERROR1);
42 }
43 else
44 {
45 if (bNoFill != TRUE)
46 {
47 GetConsoleScreenBufferInfo (hConsole, &csbi);
48
49 coPos.X = 0;
50 coPos.Y = 0;
51 FillConsoleOutputAttribute (hConsole,
52 (WORD)(wColor & 0x00FF),
53 (csbi.dwSize.X)*(csbi.dwSize.Y),
54 coPos,
55 &dwWritten);
56 }
57 SetConsoleTextAttribute (hConsole, (WORD)(wColor & 0x00FF));
58 }
59 }
60
61
62 /*
63 * color
64 *
65 * internal dir command
66 */
67 INT CommandColor (LPTSTR first, LPTSTR rest)
68 {
69 TCHAR szMsg[RC_STRING_MAX_SIZE];
70
71 if (_tcsncmp (rest, _T("/?"), 2) == 0)
72 {
73 ConOutResPaging(TRUE,STRING_COLOR_HELP1);
74 return 0;
75 }
76
77 nErrorLevel = 0;
78
79 if (rest[0] == _T('\0'))
80 {
81 /* set default color */
82 wColor = wDefColor;
83 SetScreenColor (wColor, FALSE);
84 return 0;
85 }
86
87
88 if ( _tcslen(&rest[0])==1)
89 {
90 if ( (_tcscmp(&rest[0], _T("0")) >=0 ) && (_tcscmp(&rest[0], _T("9")) <=0 ) )
91 {
92 SetConsoleTextAttribute (hConsole, (WORD)_ttoi(rest));
93 return 0;
94 }
95 else if ( (_tcscmp(&rest[0], _T("a")) >=0 ) && (_tcscmp(&rest[0], _T("f")) <=0 ) )
96 {
97 SetConsoleTextAttribute (hConsole, (WORD) (rest[0] + 10 - _T('a')) );
98 return 0;
99 }
100 else if ( (_tcscmp(&rest[0], _T("A")) >=0 ) && (_tcscmp(&rest[0], _T("F")) <=0 ) )
101 {
102 SetConsoleTextAttribute (hConsole, (WORD) (rest[0] + 10 - _T('A')) );
103 return 0;
104 }
105 ConErrResPuts(STRING_COLOR_ERROR2);
106 nErrorLevel = 1;
107 return 1;
108 }
109
110 if (StringToColor(&wColor, &rest) == FALSE)
111 {
112 ConErrResPuts(STRING_COLOR_ERROR2);
113 nErrorLevel = 1;
114 return 1;
115 }
116
117 LoadString(CMD_ModuleHandle, STRING_COLOR_ERROR3, szMsg, RC_STRING_MAX_SIZE);
118 ConErrPrintf(szMsg, wColor);
119
120 if ((wColor & 0xF) == (wColor &0xF0) >> 4)
121 {
122 LoadString(CMD_ModuleHandle, STRING_COLOR_ERROR4, szMsg, RC_STRING_MAX_SIZE);
123 ConErrPrintf(szMsg, wColor);
124 nErrorLevel = 1;
125 return 1;
126 }
127
128 /* set color */
129 SetScreenColor(wColor,
130 (_tcsstr (rest,_T("/-F")) || _tcsstr (rest,_T("/-f"))));
131
132 return 0;
133 }
134
135 #endif /* INCLUDE_CMD_COLOR */
136
137 /* EOF */