-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Fix extra carriage returns in piped ANSI output on Windows #3442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LowLevelLore
wants to merge
10
commits into
gabime:v1.x
Choose a base branch
from
LowLevelLore:v1.x
base: v1.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
de0d0dc
Now lets test on windows
LowLevelLore 9397e31
Merge pull request #1 from LowLevelLore/tcp-timeout
LowLevelLore 4f9b630
I guess testing on windows passes.
LowLevelLore 6b23175
Update tcp_client-windows.h
LowLevelLore e8984f6
Final edit
LowLevelLore 7315943
Update tcp_client-windows.h
LowLevelLore ce53eae
Removed Extra Headers.
LowLevelLore 8a780f6
Robust implementation for getting handles.
LowLevelLore 322b7af
Merge branch 'gabime:v1.x' into v1.x
LowLevelLore d09e13d
ANSI color sink on Windows
LowLevelLore File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,10 @@ | |
| #include <spdlog/details/os.h> | ||
| #include <spdlog/pattern_formatter.h> | ||
|
|
||
| #if defined(_WIN32) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use #ifdef _WIN32 |
||
| #include <spdlog/details/windows_include.h> | ||
| #endif | ||
|
|
||
| namespace spdlog { | ||
| namespace sinks { | ||
|
|
||
|
|
@@ -113,14 +117,28 @@ SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::set_color_mode_(color_mode mode | |
| template <typename ConsoleMutex> | ||
| SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::print_ccode_( | ||
| const string_view_t &color_code) const { | ||
| #ifdef _WIN32 | ||
| DWORD bytes_written = 0; | ||
| HANDLE h = reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(target_file_))); | ||
| // WriteFile bypasses the extra \r injection | ||
| WriteFile(h, color_code.data(), static_cast<DWORD>(color_code.size()), &bytes_written, nullptr); | ||
| #else | ||
| details::os::fwrite_bytes(color_code.data(), color_code.size(), target_file_); | ||
| #endif | ||
| } | ||
|
|
||
| template <typename ConsoleMutex> | ||
| SPDLOG_INLINE void ansicolor_sink<ConsoleMutex>::print_range_(const memory_buf_t &formatted, | ||
| size_t start, | ||
| size_t end) const { | ||
| #ifdef _WIN32 | ||
| DWORD bytes_written = 0; | ||
| HANDLE h = reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(target_file_))); | ||
| WriteFile(h, formatted.data() + start, static_cast<DWORD>(end - start), &bytes_written, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. _get_osfhandle shoild be called only once at construction time and store the result in a class member |
||
| nullptr); | ||
| #else | ||
| details::os::fwrite_bytes(formatted.data() + start, end - start, target_file_); | ||
| #endif | ||
| } | ||
|
|
||
| template <typename ConsoleMutex> | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be included in https://github.com/gabime/spdlog/blob/v1.x/src/stdout_sinks.cpp instead