diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2016-02-13 17:13:25 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2016-02-13 17:13:25 +0900 |
| commit | 8684923344172f3772a0a8fd8e7ef21d9352f35b (patch) | |
| tree | 3d37bd6f03683cb466e981253694c99076ed2f9e | |
| parent | c245c5ecc67b3a7acc7b76d57832ca8bcd85aa87 (diff) | |
| parent | 04eacf05e71314dffafd4b83284aa5594596190b (diff) | |
Merge branch 'patch-2' of https://github.com/kwkam/aria2 into kwkam-patch-2
| -rw-r--r-- | src/WinConsoleFile.cc | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/src/WinConsoleFile.cc b/src/WinConsoleFile.cc index 41ccd8ed..8f6b4ac7 100644 --- a/src/WinConsoleFile.cc +++ b/src/WinConsoleFile.cc @@ -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_; |
