Bugfix: Restore Command Line Color Scheme

pafish modifies the command-line color scheme but does not restore
original color scheme after execution. Not cool. This commit fixes the
issue.
This commit is contained in:
Sanchit Karve 2015-02-12 00:30:04 -08:00
parent 9fb472d7da
commit 084eb6726d
3 changed files with 20 additions and 3 deletions

View File

@ -6,9 +6,21 @@
#include "common.h" #include "common.h"
void init_cmd_colors() { unsigned short init_cmd_colors() {
CONSOLE_SCREEN_BUFFER_INFO csbi;
unsigned short original_colors = 0;
HANDLE handler = GetStdHandle(STD_OUTPUT_HANDLE); HANDLE handler = GetStdHandle(STD_OUTPUT_HANDLE);
// Get original console colors
GetConsoleScreenBufferInfo(handler, &csbi);
SetConsoleTextAttribute(handler, FOREGROUND_INTENSITY); SetConsoleTextAttribute(handler, FOREGROUND_INTENSITY);
// Return original console colors
return csbi.wAttributes;
}
void restore_cmd_colors(unsigned short original_colors) {
HANDLE handler = GetStdHandle(STD_OUTPUT_HANDLE);
// Restore original console colors
SetConsoleTextAttribute(handler, original_colors);
} }
void print_header() { void print_header() {

View File

@ -2,7 +2,9 @@
#ifndef COMM_H #ifndef COMM_H
#define COMM_H #define COMM_H
void init_cmd_colors(); unsigned short init_cmd_colors();
void restore_cmd_colors(unsigned short);
void print_header(); void print_header();

View File

@ -36,10 +36,11 @@ int main(int argc, char *argv[])
{ {
char icon[] = "Blue fish icon thanks to http://www.fasticon.com/", winverstr[32], aux[1024]; char icon[] = "Blue fish icon thanks to http://www.fasticon.com/", winverstr[32], aux[1024];
OSVERSIONINFO winver; OSVERSIONINFO winver;
unsigned short original_colors = 0;
write_log("Start"); write_log("Start");
init_cmd_colors(); original_colors = init_cmd_colors();
print_header(); print_header();
winver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); winver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
@ -335,6 +336,8 @@ int main(int argc, char *argv[])
fflush(stdin); fflush(stdin);
getchar(); getchar();
/* Restore Original Console Colors */
restore_cmd_colors(original_colors);
return 0; return 0;
} }