Index: base/shell/cmd/color.c =================================================================== --- base/shell/cmd/color.c (revision 58962) +++ base/shell/cmd/color.c (working copy) @@ -61,68 +61,69 @@ */ INT CommandColor (LPTSTR rest) { - WORD wColor; + WORD wColor = 0x00; + /* The user asked for help */ if (_tcsncmp (rest, _T("/?"), 2) == 0) { ConOutResPaging(TRUE,STRING_COLOR_HELP1); return 0; } - + + /* Let's prepare %ERRORLEVEL% */ nErrorLevel = 0; + /*No param. Set default colors */ if (rest[0] == _T('\0')) { - /* set default color */ wColor = wDefColor; SetScreenColor (wColor, FALSE); return 0; } - + /* Param is just one character: Sets Color Text */ if ( _tcslen(&rest[0])==1) { HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); if ( (_tcscmp(&rest[0], _T("0")) >=0 ) && (_tcscmp(&rest[0], _T("9")) <=0 ) ) { - SetConsoleTextAttribute (hConsole, (WORD)_ttoi(rest)); - return 0; + wColor |= _ttoi(rest); } else if ( (_tcscmp(&rest[0], _T("a")) >=0 ) && (_tcscmp(&rest[0], _T("f")) <=0 ) ) { - SetConsoleTextAttribute (hConsole, (WORD) (rest[0] + 10 - _T('a')) ); - return 0; + wColor |= (rest[0] + 10 - _T('a')); } else if ( (_tcscmp(&rest[0], _T("A")) >=0 ) && (_tcscmp(&rest[0], _T("F")) <=0 ) ) { - SetConsoleTextAttribute (hConsole, (WORD) (rest[0] + 10 - _T('A')) ); - return 0; + wColor |= (rest[0] + 10 - _T('A')); } - ConErrResPuts(STRING_COLOR_ERROR2); + else /* Invalid character */ + { + ConOutResPaging(TRUE,STRING_COLOR_HELP1); nErrorLevel = 1; return 1; + } + } + else if (StringToColor(&wColor, &rest) == FALSE) /* Advanced: "Color ON Color" , "For ON Bac" */ + { + ConOutResPaging(TRUE,STRING_COLOR_HELP1); + nErrorLevel = 1; + return 1; } - - if (StringToColor(&wColor, &rest) == FALSE) + + /* Foreground and Background colors can't be the same */ + if ((wColor & 0xF) == (wColor &0xF0) >> 4) { - ConErrResPuts(STRING_COLOR_ERROR2); nErrorLevel = 1; return 1; } if (((bc) && (bc->bEcho)) || !bc) { - ConErrResPrintf(STRING_COLOR_ERROR3, wColor); + ConErrResPrintf(STRING_COLOR_ERROR3, wColor); //"Color %x\n" } - - if ((wColor & 0xF) == (wColor &0xF0) >> 4) - { - ConErrResPrintf(STRING_COLOR_ERROR4, wColor); - nErrorLevel = 1; - return 1; - } - - /* set color */ + + /* Advanced: /-F to avoid changing already buffered foreground/background. */ SetScreenColor(wColor, (_tcsstr (rest,_T("/-F")) || _tcsstr (rest,_T("/-f"))));