Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
spdlog
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
spdlog
Commits
3e689e70
Commit
3e689e70
authored
Feb 13, 2021
by
Gabi Melman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle return values of win32 color functions in wincolor sink
parent
a9964afc
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
5 deletions
+12
-5
include/spdlog/sinks/wincolor_sink-inl.h
include/spdlog/sinks/wincolor_sink-inl.h
+12
-5
No files found.
include/spdlog/sinks/wincolor_sink-inl.h
View file @
3e689e70
...
...
@@ -133,12 +133,17 @@ template<typename ConsoleMutex>
std
::
uint16_t
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
set_foreground_color_
(
std
::
uint16_t
attribs
)
{
CONSOLE_SCREEN_BUFFER_INFO
orig_buffer_info
;
::
GetConsoleScreenBufferInfo
(
static_cast
<
HANDLE
>
(
out_handle_
),
&
orig_buffer_info
);
if
(
!::
GetConsoleScreenBufferInfo
(
static_cast
<
HANDLE
>
(
out_handle_
),
&
orig_buffer_info
))
{
return
WHITE
;
}
WORD
back_color
=
orig_buffer_info
.
wAttributes
;
// retrieve the current background color
back_color
&=
static_cast
<
WORD
>
(
~
(
FOREGROUND_RED
|
FOREGROUND_GREEN
|
FOREGROUND_BLUE
|
FOREGROUND_INTENSITY
));
// keep the background color unchanged
::
SetConsoleTextAttribute
(
static_cast
<
HANDLE
>
(
out_handle_
),
static_cast
<
WORD
>
(
attribs
)
|
back_color
);
auto
ignored
=
::
SetConsoleTextAttribute
(
static_cast
<
HANDLE
>
(
out_handle_
),
static_cast
<
WORD
>
(
attribs
)
|
back_color
);
(
void
)(
ignored
);
return
static_cast
<
std
::
uint16_t
>
(
orig_buffer_info
.
wAttributes
);
// return orig attribs
}
...
...
@@ -147,7 +152,8 @@ template<typename ConsoleMutex>
void
SPDLOG_INLINE
wincolor_sink
<
ConsoleMutex
>::
print_range_
(
const
memory_buf_t
&
formatted
,
size_t
start
,
size_t
end
)
{
auto
size
=
static_cast
<
DWORD
>
(
end
-
start
);
::
WriteConsoleA
(
static_cast
<
HANDLE
>
(
out_handle_
),
formatted
.
data
()
+
start
,
size
,
nullptr
,
nullptr
);
auto
ignored
=
::
WriteConsoleA
(
static_cast
<
HANDLE
>
(
out_handle_
),
formatted
.
data
()
+
start
,
size
,
nullptr
,
nullptr
);
(
void
)(
ignored
);
}
template
<
typename
ConsoleMutex
>
...
...
@@ -155,7 +161,8 @@ void SPDLOG_INLINE wincolor_sink<ConsoleMutex>::write_to_file_(const memory_buf_
{
auto
size
=
static_cast
<
DWORD
>
(
formatted
.
size
());
DWORD
bytes_written
=
0
;
::
WriteFile
(
static_cast
<
HANDLE
>
(
out_handle_
),
formatted
.
data
(),
size
,
&
bytes_written
,
nullptr
);
auto
ignored
=
::
WriteFile
(
static_cast
<
HANDLE
>
(
out_handle_
),
formatted
.
data
(),
size
,
&
bytes_written
,
nullptr
);
(
void
)(
ignored
);
}
// wincolor_stdout_sink
...
...
Write
Preview
Markdown
is supported
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