Skip to content
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 experimental emphasis support #961

Merged
merged 16 commits into from
Dec 6, 2018
Merged

Add experimental emphasis support #961

merged 16 commits into from
Dec 6, 2018

Conversation

Rakete1111
Copy link
Contributor

This patch adds support for text emphasis: bold and underline.

#define FMT_HEADER_ONLY
#include "include/fmt/color.h"
#include "include/fmt/format.h"

int main() {
  fmt::print(fmt::emphasis::bold, "bold\n");
  fmt::print(fmt::emphasis::underline, "underline\n");

  fmt::print(fmt::emphasis::bold, fmt::color::red, "bold and red\n");
  fmt::print(fmt::emphasis::underline, fmt::color::red, fmt::color::yellow,
             "underline, red and yellow\n");
}

@foonathan
Copy link
Contributor

I think the number of parameters here isn't going to scale well.

I'd suggest creating a single formatting options struct that can be created from a single formatting enum or maybe something like this fmt::emphasis::bold | fmt::color::red, but @vitaut decides.

@Rakete1111
Copy link
Contributor Author

Rakete1111 commented Dec 4, 2018

I was thinking about that, but then I decided against it, because I don't know how to differentiate between foreground and background colors. fg(fmt::color::red)? But that's not nice to look at IMO. Do you have any idea?

@foonathan
Copy link
Contributor

Right, good catch.

I'm actually not too opposed to something like fg(fmt::color::red).

@vitaut
Copy link
Contributor

vitaut commented Dec 5, 2018

I agree with @foonathan that we should have a single formatting style struct to keep the number of overloads manageable. Using fg(color) and bg(color) to differentiate seems fine. I like it better than the current positional API with arbitrary order.

@vitaut
Copy link
Contributor

vitaut commented Dec 5, 2018

And thanks for the PR! This is a cool feature.

@Rakete1111
Copy link
Contributor Author

Rakete1111 commented Dec 5, 2018

So, I introduced a new class text_format, which stores the text formatting:

fmt::print(fmt::emphasis::bold | fg(fmt::color::red), "Hello in bold and red\n");

fmt::text_format hackerman = bg(fmt::color::black) | fg(fmt::color::green);
fmt::print(hackerman | fmt::emphasis::bold, "imma hack u\n");

Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Just a few smallish comments.

include/fmt/color.h Outdated Show resolved Hide resolved
include/fmt/color.h Outdated Show resolved Hide resolved
include/fmt/color.h Outdated Show resolved Hide resolved
include/fmt/color.h Outdated Show resolved Hide resolved
include/fmt/color.h Outdated Show resolved Hide resolved
test/format-impl-test.cc Outdated Show resolved Hide resolved
include/fmt/color.h Outdated Show resolved Hide resolved
Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good, only gcc 4.4 looks unhappy: https://travis-ci.org/fmtlib/fmt/jobs/464344769

@vitaut vitaut merged commit 81b5c4a into fmtlib:master Dec 6, 2018
@vitaut
Copy link
Contributor

vitaut commented Dec 6, 2018

Merged, thanks!

@vitaut vitaut mentioned this pull request Dec 6, 2018
@Rakete1111
Copy link
Contributor Author

@vitaut Can you retroactively add a default constructor for text_style that I completely forgot? Thanks! :)

@vitaut
Copy link
Contributor

vitaut commented Dec 7, 2018

Can you retroactively add a default constructor for text_style that I completely forgot?

Sure, added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants