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

Added support for rgb color output. #767

Closed
wants to merge 2 commits into from
Closed

Conversation

Remotion
Copy link
Contributor

@Remotion Remotion commented Jun 7, 2018

#include <fmt/colors.h>

int main() {
    std::tuple tup = {1, '1', "10", std::string("20"), std::string_view{"30"}};
    fmt::print("{}\n", tup);
    fmt::print(fmt::rgb(10,100,200),"{}\n", tup);
    fmt::print(fmt::rgb(200,100,200),"{}\n", tup);
    fmt::print(fmt::rgb(20,200,20),"{}\n", tup);
    fmt::print(fmt::rgb(20,0,250),"{}\n", tup);
}

}


enum hex : uint32_t { // use enum class ?
Copy link
Contributor

Choose a reason for hiding this comment

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

This would probably be better as an enum class. Also, maybe rename it to something more descriptive, like color? I'm also not sure of the CamelCasing of the variants, and if it's consistent with the rest of the library.

Copy link
Contributor Author

@Remotion Remotion Jun 7, 2018

Choose a reason for hiding this comment

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

This would probably be better as an enum class.
Probably but I really do not want this to be too long.

fmt::print(fmt::Coral, "message {}\n", msg);
fmt::print(fmt::colors::Coral, "message {}\n", msg);

Also color names are from this list
Color Names Supported by All Browsers

Also Visual Studio and VS Code can directly show colors in the editor using this names.

Color Picker

VS Color Picker

Color Highlight

Unfortunately I could not find a way to support hex colors like #FFFFFF in C++.

Alternative would be to use color names like this, but this is even less readable.

    fmt::print(fmt::darkgoldenrod, "message {}\n", msg);
    // fmt::print(fmt::DarkGoldenRod, "message {}\n", msg);

Copy link
Contributor

Choose a reason for hiding this comment

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

What I meant was more like using snake_case instead of CamelCase since the library and C++ code in general tends to prefer the former over the latter. But you're right about those extensions, they seem to require the color names to be lowercase or CamelCase.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @eliaskosunen's points that it should be a enum class color with snake case enum constants for consistency with the rest of the code:

enum class colors : uint32_t {
  alice_blue = ...
};

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. One minor comment inline and could you add a section to https://raw.githubusercontent.com/fmtlib/fmt/master/doc/api.rst describing this functionality in a separate PR.

}


enum hex : uint32_t { // use enum class ?
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @eliaskosunen's points that it should be a enum class color with snake case enum constants for consistency with the rest of the code:

enum class colors : uint32_t {
  alice_blue = ...
};

Renamed from hex to color.
Changed colr names to snake case.
@vitaut
Copy link
Contributor

vitaut commented Jun 8, 2018

Merged with minor tweaks, thanks!

@vitaut vitaut closed this Jun 8, 2018
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