src/WinConsoleFile.cc: fix colour

Try to make it less confusing
pull/569/head
kwkam 2016-02-13 16:01:41 +08:00
parent 25ae17b490
commit 1c573c9708
1 changed files with 19 additions and 20 deletions

View File

@ -86,34 +86,33 @@ WinConsoleFile::WinConsoleFile(DWORD stdHandle)
bold_(false), bold_(false),
underline_(false), underline_(false),
reverse_(false), reverse_(false),
deffg_(FOREGROUND_WHITE), fg_(7),
defbg_(BACKGROUND_BLACK) bg_(0)
{ {
if (supportsColor()) { if (supportsColor()) {
CONSOLE_SCREEN_BUFFER_INFO info; CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo(handle(), &info); GetConsoleScreenBufferInfo(handle(), &info);
deffg_ = info.wAttributes &
(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
defbg_ = info.wAttributes &
(BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED);
bold_ = info.wAttributes & FOREGROUND_INTENSITY; bold_ = info.wAttributes & FOREGROUND_INTENSITY;
underline_ = info.wAttributes & BACKGROUND_INTENSITY; underline_ = info.wAttributes & BACKGROUND_INTENSITY;
} int fgcolor = info.wAttributes &
(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
for (int i = 0; i < kForegroundSize; i++) { for (int fg = 0; fg < kForegroundSize; fg++) {
if (deffg_ == kForeground[i]) { if (kForeground[fg] == fgcolor) {
deffg_ = i; fg_ = fg;
break; break;
}
}
int bgcolor = info.wAttributes &
(BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED);
for (int bg = 0; bg < kBackgroundSize; bg++) {
if (kBackground[bg] == bgcolor) {
bg_ = bg;
break;
}
} }
} }
for (int i = 0; i < kBackgroundSize; i++) { deffg_ = fg_;
if (defbg_ == kBackground[i]) { defbg_ = bg_;
defbg_ = i;
break;
}
}
fg_ = deffg_;
bg_ = defbg_;
} }
bool WinConsoleFile::supportsColor() bool WinConsoleFile::supportsColor()