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

Provide entry point for color customization #41791

Closed
Arkoniak opened this issue Aug 5, 2021 · 5 comments · Fixed by #49586
Closed

Provide entry point for color customization #41791

Arkoniak opened this issue Aug 5, 2021 · 5 comments · Fixed by #49586

Comments

@Arkoniak
Copy link
Contributor

Arkoniak commented Aug 5, 2021

Julia uses hardcoded colors for generating output (for example stacktraces) and unfortunately color choice is not always suitable for all users for various reasons.

I propose to use the following approach instead of colors hardcoding:

# define somewhere at the beginning

const COLOR = Ref((; foo = :red, bar = :green))

# and later in the code, when color is needed
printstyled("what you need to print", COLOR[].foo)

This simple change does not provide full-fledged color theme switching by itself (this probably should be implemented #41435), but it provides an entry point for all future color theme related stuff. I.e. all user level convenience functions would just modify this variable one way or another. And anyway this proposal allows color customization right here and now (maybe slightly cumbersome) unlike the current situation.

Implementing this feature looks like a good beginner PR, doesn't require large modifications of the code base and it solves color issues.

@simeonschaub
Copy link
Member

Is that different from the current mechanism where you can modify Base.text_colors? E.g. the following already works:

julia> Base.text_colors[:red] = Base.text_colors[:blue]
"\e[34m"

julia> printstyled("Foobar"; color=:red) # displays as blue
Foobar

@KristofferC
Copy link
Sponsor Member

Could be discussed in #41435?

@Arkoniak
Copy link
Contributor Author

Arkoniak commented Aug 5, 2021

Yes it could, but this proposal can be implemented before #41435 is fully resolved. As far as I understand #41435 is mostly about proper way of defining configuration, like TOML format and whether to use hex colors or meaningful names. But at some point somebody have to go through the code base and change all hardcoded values to config references. This proposal can be considered as low-level implementation config-agnostic detail. You can have any config setup you want and translate it to COLOR variable at some point.

@Arkoniak
Copy link
Contributor Author

Arkoniak commented Aug 5, 2021

Is that different from the current mechanism where you can modify Base.text_colors? E.g. the following already works:

julia> Base.text_colors[:red] = Base.text_colors[:blue]
"\e[34m"

julia> printstyled("Foobar"; color=:red) # displays as blue
Foobar

No, it is not the same. Changing Base.text_color affects all colors everywhere. It may not always be the intended case, though. For example it could be possible that the user wants to change the red color in some random message (if he does not think that in this particular message red color should be used), but he still may need red color in error message.

@KristofferC
Copy link
Sponsor Member

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 a pull request may close this issue.

4 participants