-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add file stream support for stylized text printing. #967
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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 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 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
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.
What is this for?
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.
If I do
fmt::print(stderr, fmt::emphasis::bold, "");
, OR kicks in. It has a lot of candidates:Normally, one would expect the first one to get called, but that's not the case. This is due to variadic templates being greedy.
fmt::emphasis::bold
is not atext_style
and sincestderr
is a pointer toT
, the second overload above is taken, which then fails with an assertion failure becausestd::FILE
is not a valid character type.I'm adding this so that fmt doesn't think that
stderr
is a valid format string - This never was an issue before because there were always exact matches.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.
Wouldn't it be much nicer to disregard all pointer types
cv T *
for which no specializationstd::char_traits<T>
exists? May be by detecting the existence of thestd::char_traits<T>::char_type
type member which requires only type-SFINAE and should work on all compilers.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.
@DanielaE Didn't want to change this for such a patch, but yeah that's the better solution. I'll update my PR then :) thanks
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.
In this case I'd rather split the PR into two: the first one laying the
cv T *
groundwork and then the second one actually addressing issue #944 taking advantage of the first PR. This looks cleaner to me but at the end of the day it's up to Victor.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.
Yeah, it looks like
std::char_traits
is defined for everything includingFILE
=), so we'll have to rely on some mechanism within {fmt} to detect char types.to_string_view
is indeed our current way to detect string types and therefore character types, so unless there are better ideas let's go with the currentto_string_view
-based solution but please add a comment briefly explaining what's going on.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.
😢 This sounds like a language or library defect. Characters are fundamental entities in the language and there are predicates to detect almost any kind of trait, but a well-defined predicate to detect the "character-ness" type trait seems to be missing. I've sifted through MSVC's library and found the catch-all primary template of
std::char_traits
which defines thechar_type
member toT
. Interestingly enough, only in this non-character case theint_type
is defined tolong
. But this cannot be relied on because the specification in the standard is weasel-wordy in the case of non-required specializations.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.
One more thing:
to_string_view(const std::FILE *)
should probably go tofmt/color.h
since it is only relevant for theprint
overloads there.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.
@vitaut It doesn't seem to work when I move the overload to
color.h
- don't know why. So I changed it to two explicit specializations instead. Hope that's ok too :)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.
I think specializations are even clearer.