Merge branch 'patch-2' of https://github.com/kwkam/aria2 into kwkam-patch-2

pull/573/head
Tatsuhiro Tsujikawa 2016-02-13 17:13:25 +09:00
commit 8684923344
1 changed files with 22 additions and 14 deletions

View File

@ -62,6 +62,8 @@ const WORD kForeground[] = {
FOREGROUND_WHITE // white
};
const int kForegroundSize = sizeof (kForeground) / sizeof (kForeground[0]);
const WORD kBackground[] = {
BACKGROUND_BLACK, // black
BACKGROUND_RED, // red
@ -73,6 +75,8 @@ const WORD kBackground[] = {
BACKGROUND_WHITE // white
};
const int kBackgroundSize = sizeof (kBackground) / sizeof (kBackground[0]);
} // namespace
namespace aria2 {
@ -82,26 +86,30 @@ WinConsoleFile::WinConsoleFile(DWORD stdHandle)
bold_(false),
underline_(false),
reverse_(false),
fg_(FOREGROUND_WHITE),
bg_(BACKGROUND_BLACK)
fg_(7),
bg_(0)
{
if (supportsColor()) {
CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo(handle(), &info);
info.wAttributes &=
~(COMMON_LVB_LEADING_BYTE | COMMON_LVB_TRAILING_BYTE |
COMMON_LVB_GRID_HORIZONTAL | COMMON_LVB_GRID_LVERTICAL |
COMMON_LVB_GRID_RVERTICAL | COMMON_LVB_REVERSE_VIDEO |
COMMON_LVB_UNDERSCORE);
fg_ = info.wAttributes &
~(BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED |
BACKGROUND_INTENSITY);
bg_ = info.wAttributes &
~(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED |
FOREGROUND_INTENSITY);
bg_ = (bg_ >> 4) & 0x0F;
bold_ = info.wAttributes & FOREGROUND_INTENSITY;
underline_ = info.wAttributes & BACKGROUND_INTENSITY;
int fgcolor = info.wAttributes &
(FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
for (int fg = 0; fg < kForegroundSize; fg++) {
if (kForeground[fg] == fgcolor) {
fg_ = fg;
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;
}
}
}
deffg_ = fg_;