2 * COLOR.C - color internal command.
7 * 13-Dec-1998 (Eric Kohl)
10 * 19-Jan-1999 (Eric Kohl)
13 * 20-Jan-1999 (Eric Kohl)
16 * 14-Oct-1999 (Paolo Pantaleo <paolopan@freemail.it>)
17 * 4nt's syntax implemented.
19 * 03-Apr-2005 (Magnus Olsen <magnus@greatlord.com>)
20 * Move all hardcoded strings in En.rc.
25 #ifdef INCLUDE_CMD_COLOR
27 BOOL
SetScreenColor(WORD wColor
, BOOL bNoFill
)
29 HANDLE hConsole
= GetStdHandle(STD_OUTPUT_HANDLE
);
31 CONSOLE_SCREEN_BUFFER_INFO csbi
;
34 /* Foreground and Background colors can't be the same */
35 if ((wColor
& 0x0F) == (wColor
& 0xF0) >> 4)
38 /* Fill the whole background if needed */
41 GetConsoleScreenBufferInfo(hConsole
, &csbi
);
45 FillConsoleOutputAttribute(hConsole
,
47 csbi
.dwSize
.X
* csbi
.dwSize
.Y
,
52 /* Set the text attribute */
53 SetConsoleTextAttribute(hConsole
, wColor
& 0x00FF);
60 * internal dir command
62 INT
CommandColor(LPTSTR rest
)
66 /* The user asked for help */
67 if (_tcsncmp(rest
, _T("/?"), 2) == 0)
69 ConOutResPaging(TRUE
, STRING_COLOR_HELP1
);
73 /* Let's prepare %ERRORLEVEL% */
76 /* No parameter: Set the default colors */
77 if (rest
[0] == _T('\0'))
79 SetScreenColor(wDefColor
, FALSE
);
83 /* The parameter is just one character: Set color text */
84 if (_tcslen(rest
) == 1)
86 if ((rest
[0] >= _T('0')) && (rest
[0] <= _T('9')))
88 wColor
= (WORD
)_ttoi(rest
);
90 else if ((rest
[0] >= _T('a')) && (rest
[0] <= _T('f')))
92 wColor
= (WORD
)(rest
[0] + 10 - _T('a'));
94 else if ((rest
[0] >= _T('A')) && (rest
[0] <= _T('F')))
96 wColor
= (WORD
)(rest
[0] + 10 - _T('A'));
98 else /* Invalid character */
100 ConOutResPaging(TRUE
, STRING_COLOR_HELP1
);
105 /* Color string: advanced choice: two-digits, "Color ON Color" , "Foreground ON Background" */
106 else if (StringToColor(&wColor
, &rest
) == FALSE
)
108 /* Invalid color string */
109 ConOutResPaging(TRUE
, STRING_COLOR_HELP1
);
114 TRACE("Color %02x\n", wColor
);
117 * Set the chosen color. Use also the following advanced flag:
118 * /-F to avoid changing already buffered foreground/background.
120 if (SetScreenColor(wColor
, (_tcsstr(rest
, _T("/-F")) || _tcsstr(rest
, _T("/-f")))) == FALSE
)
122 /* Failed because foreground and background colors were the same */
123 ConErrResPuts(STRING_COLOR_ERROR1
);
132 #endif /* INCLUDE_CMD_COLOR */