cmd.exe: Add COLOR command.
This commit is contained in:
parent
a4b6ee366c
commit
e37463fab5
|
@ -47,7 +47,7 @@ struct env_stack *pushd_directories;
|
|||
|
||||
extern HINSTANCE hinst;
|
||||
extern char *inbuilt[];
|
||||
extern int echo_mode, verify_mode;
|
||||
extern int echo_mode, verify_mode, defaultColor;
|
||||
extern char quals[MAX_PATH], param1[MAX_PATH], param2[MAX_PATH];
|
||||
extern BATCH_CONTEXT *context;
|
||||
extern DWORD errorlevel;
|
||||
|
@ -1631,3 +1631,52 @@ void WCMD_assoc (char *command) {
|
|||
/* Clean up */
|
||||
RegCloseKey(key);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* WCMD_color
|
||||
*
|
||||
* Clear the terminal screen.
|
||||
*/
|
||||
|
||||
void WCMD_color (void) {
|
||||
|
||||
/* Emulate by filling the screen from the top left to bottom right with
|
||||
spaces, then moving the cursor to the top left afterwards */
|
||||
CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
|
||||
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
|
||||
if (param1[0] != 0x00 && strlen(param1) > 2) {
|
||||
WCMD_output ("Argument invalid\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (GetConsoleScreenBufferInfo(hStdOut, &consoleInfo))
|
||||
{
|
||||
COORD topLeft;
|
||||
DWORD screenSize;
|
||||
DWORD color = 0;
|
||||
|
||||
screenSize = consoleInfo.dwSize.X * (consoleInfo.dwSize.Y + 1);
|
||||
|
||||
topLeft.X = 0;
|
||||
topLeft.Y = 0;
|
||||
|
||||
/* Convert the color hex digits */
|
||||
if (param1[0] == 0x00) {
|
||||
color = defaultColor;
|
||||
} else {
|
||||
color = strtoul(param1, NULL, 16);
|
||||
}
|
||||
|
||||
/* Fail if fg == bg color */
|
||||
if (((color & 0xF0) >> 4) == (color & 0x0F)) {
|
||||
errorlevel = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Set the current screen contents and ensure all future writes
|
||||
remain this color */
|
||||
FillConsoleOutputAttribute(hStdOut, color, screenSize, topLeft, &screenSize);
|
||||
SetConsoleTextAttribute(hStdOut, color);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ void WCMD_batch (char *, char *, int, char *, HANDLE);
|
|||
void WCMD_call (char *command);
|
||||
void WCMD_change_tty (void);
|
||||
void WCMD_clear_screen (void);
|
||||
void WCMD_color (void);
|
||||
void WCMD_copy (void);
|
||||
void WCMD_create_dir (void);
|
||||
void WCMD_delete (char *);
|
||||
|
@ -157,9 +158,10 @@ struct env_stack
|
|||
#define WCMD_PUSHD 38
|
||||
#define WCMD_POPD 39
|
||||
#define WCMD_ASSOC 40
|
||||
#define WCMD_COLOR 41
|
||||
|
||||
/* Must be last in list */
|
||||
#define WCMD_EXIT 41
|
||||
#define WCMD_EXIT 42
|
||||
|
||||
/* Some standard messages */
|
||||
extern const char nyi[];
|
||||
|
|
|
@ -35,11 +35,11 @@ const char * const inbuilt[] = {"ATTRIB", "CALL", "CD", "CHDIR", "CLS", "COPY",
|
|||
"HELP", "IF", "LABEL", "MD", "MKDIR", "MOVE", "PATH", "PAUSE",
|
||||
"PROMPT", "REM", "REN", "RENAME", "RD", "RMDIR", "SET", "SHIFT",
|
||||
"TIME", "TITLE", "TYPE", "VERIFY", "VER", "VOL",
|
||||
"ENDLOCAL", "SETLOCAL", "PUSHD", "POPD", "ASSOC", "EXIT" };
|
||||
"ENDLOCAL", "SETLOCAL", "PUSHD", "POPD", "ASSOC", "COLOR", "EXIT" };
|
||||
|
||||
HINSTANCE hinst;
|
||||
DWORD errorlevel;
|
||||
int echo_mode = 1, verify_mode = 0;
|
||||
int echo_mode = 1, verify_mode = 0, defaultColor = 7;
|
||||
static int opt_c, opt_k, opt_s;
|
||||
const char nyi[] = "Not Yet Implemented\n\n";
|
||||
const char newline[] = "\n";
|
||||
|
@ -578,6 +578,9 @@ void WCMD_process_command (char *command)
|
|||
case WCMD_ASSOC:
|
||||
WCMD_assoc(p);
|
||||
break;
|
||||
case WCMD_COLOR:
|
||||
WCMD_color();
|
||||
break;
|
||||
case WCMD_EXIT:
|
||||
WCMD_exit ();
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue