Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Nghia Truong
iMSTK
Commits
f5efd023
Commit
f5efd023
authored
Jul 27, 2019
by
Sreekanth Arikatla
Browse files
Merge branch 'addColorOnWindows' into 'master'
ENH: Add color to the stdout on windows See merge request
iMSTK/iMSTK!353
parents
7ceb347c
d4897b81
Changes
1
Hide whitespace changes
Inline
Side-by-side
Source/Core/imstkLogUtility.cpp
View file @
f5efd023
...
...
@@ -20,6 +20,10 @@ limitations under the License.
=========================================================================*/
#include
"imstkLogUtility.h"
#ifdef WIN32
#include
<windows.h>
#endif
namespace
imstk
{
stdSink
::
FG_Color
...
...
@@ -40,6 +44,21 @@ stdSink::GetColor(const LEVELS level) const
return
WHITE
;
}
#ifdef WIN32
#define WIN_CONSOLE_RED 4
#define WIN_CONSOLE_LIGHT_GRAY 7
#define WIN_CONSOLE_YELLOW 14
void
setColorWin
(
const
int
colCode
)
{
WORD
wColor
=
((
0
&
0x0F
)
<<
4
)
+
(
colCode
&
0x0F
);
// black background
SetConsoleTextAttribute
(
GetStdHandle
(
STD_OUTPUT_HANDLE
),
wColor
);
}
#endif
void
stdSink
::
ReceiveLogMessage
(
g3
::
LogMessageMover
logEntry
)
{
...
...
@@ -52,9 +71,18 @@ stdSink::ReceiveLogMessage(g3::LogMessageMover logEntry)
<<
message
<<
"
\033
[m"
<<
std
::
endl
;
#else
if
(
level
.
value
==
WARNING
.
value
||
level
.
value
==
FATAL
.
value
)
if
(
level
.
value
==
WARNING
.
value
)
{
setColorWin
(
WIN_CONSOLE_YELLOW
);
std
::
cerr
<<
message
<<
std
::
endl
;
setColorWin
(
WIN_CONSOLE_LIGHT_GRAY
);
}
else
if
(
level
.
value
==
FATAL
.
value
)
{
setColorWin
(
WIN_CONSOLE_RED
);
std
::
cerr
<<
message
<<
std
::
endl
;
setColorWin
(
WIN_CONSOLE_LIGHT_GRAY
);
}
else
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment