summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2017-11-05 16:01:53 +0900
committerGitHub <noreply@github.com>2017-11-05 16:01:53 +0900
commit16f458c9a4dcd2c7e8c476a2f71cbcaddd370a38 (patch)
treef00df49250e7d479c8ab3e22d04342aae5c012ee
parentf198cd4ad1cbbd542050726ba5fd95ec6b073fab (diff)
parenta45390c80bf3510a3eac384a286c44b5d9af8af1 (diff)
Merge pull request #1058 from kwkam/patch-2
WinConsoleFile: fix colour properly
-rw-r--r--src/WinConsoleFile.cc19
-rw-r--r--src/WinConsoleFile.h4
2 files changed, 14 insertions, 9 deletions
diff --git a/src/WinConsoleFile.cc b/src/WinConsoleFile.cc
index 35ddf42a..55268e53 100644
--- a/src/WinConsoleFile.cc
+++ b/src/WinConsoleFile.cc
@@ -90,28 +90,31 @@ WinConsoleFile::WinConsoleFile(DWORD stdHandle)
bg_(0)
{
if (supportsColor()) {
+ int color;
CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo(handle(), &info);
bold_ = info.wAttributes & FOREGROUND_INTENSITY;
underline_ = info.wAttributes & BACKGROUND_INTENSITY;
- int fgcolor = info.wAttributes &
- (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
+ color = info.wAttributes &
+ (FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
for (int fg = 0; fg < kForegroundSize; fg++) {
- if (kForeground[fg] == fgcolor) {
+ if (kForeground[fg] == color) {
fg_ = fg;
break;
}
}
- int bgcolor = info.wAttributes &
- (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED);
+ color = info.wAttributes &
+ (BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED);
for (int bg = 0; bg < kBackgroundSize; bg++) {
- if (kBackground[bg] == bgcolor) {
+ if (kBackground[bg] == color) {
bg_ = bg;
break;
}
}
}
+ defbold_ = bold_;
+ defunderline_ = underline_;
deffg_ = fg_;
defbg_ = bg_;
}
@@ -216,9 +219,11 @@ size_t WinConsoleFile::writeColorful(const std::wstring& str)
}
for (const int a : args) {
if (a == 0) {
+ bold_ = defbold_;
+ underline_ = defunderline_;
+ reverse_ = false;
fg_ = deffg_;
bg_ = defbg_;
- bold_ = underline_ = reverse_ = false;
}
else if (30 <= a && a <= 37) {
fg_ = a - 30;
diff --git a/src/WinConsoleFile.h b/src/WinConsoleFile.h
index 19aaaa44..ae899c9e 100644
--- a/src/WinConsoleFile.h
+++ b/src/WinConsoleFile.h
@@ -55,8 +55,8 @@ public:
private:
DWORD stdHandle_;
- bool bold_;
- bool underline_;
+ bool bold_, defbold_;
+ bool underline_, defunderline_;
bool reverse_;
WORD fg_, deffg_;
WORD bg_, defbg_;