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

Fix issue 244 #245

Merged
merged 12 commits into from
Aug 10, 2021
Merged

Fix issue 244 #245

merged 12 commits into from
Aug 10, 2021

Conversation

mcDevnagh
Copy link
Contributor

@mcDevnagh mcDevnagh commented Jun 20, 2021

Added support for Terminal Default Colors (which may or may not be transparent)

  • Specifying "none" in your config file sets the color to the default color of the terminal, or tcell.ColorDefault, as defined here.
  • Invalid colors still result in an error, so malformed config files alert the user instead of setting the color to the default.
  • Updated the default config and color string for cview color tags to reflect this

On terminals which support transparency and are configured as such, setting bg = "none" keeps the transparency

example with the simple terminal using the alpha patch:
example

Copy link
Owner

@makew0rld makew0rld left a comment

Choose a reason for hiding this comment

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

Nice solution, thank you. And it looks good in your screenshot! I've never seen Amfora like that before, it's the right way to go.

Since your solution only works for backgrounds (for text it just seems to use white every time) I've suggested a change that will make it only apply when used with bg. Please note that in default-config.toml.

Also, this should be changed from "none" to "default", I think that name works better.

After making your changes, run make gen (or just go generate ./...), like I did for this PR earlier in df21b0b. This will copy the config change into the code.

@makew0rld makew0rld added this to the v1.9.0 milestone Jun 24, 2021
@mcDevnagh
Copy link
Contributor Author

Sure thing! I'll get right to working on that.
Are you sure you want to limit it just to just bg? I think the user could decide what to make the default

Maybe, limit default only to values which affect the <background> of color tags [<foreground>:<background>:<flags>], which I'm assuming is all the settings ending in bg, but I'll double check before finalizing the PR, if this is the way you'd like to go.

Also, no need to worry about the "transparency". It will always show right through the terminal instead of revealing any widgets behind, because the background isn't really transparent, it's "filled" with the color, and overwrites the pixels there. Transparency to reveal other widgets would require this

Here is an example where both the bg and info_modal_bg are set to "none", soon to be "default". (I also set info_modal_text = "slateblue" to make it more readable)
transparent-bg-and-modal.png

@makew0rld
Copy link
Owner

Maybe, limit default only to values which affect the <background> of color tags

Sounds good to me! Good point that those ones could make use of this setting as well.

@mcDevnagh
Copy link
Contributor Author

@makeworld-the-better-one
I completed what you asked of me.
I also found a UI quirk:
When a UI element was selected, the bg and text would swap. However, the if bg was "default", which could be dark, now the text was "default", which is always white. This lead to light text on a light background. I circumvent this with a new function GetTextColor(key, bg string) tcell.Color, which, can return black or white depending on the brightness of bg, only if the key is ColorDefault. Otherwise it just returns the color in the theme map
pic-full-210629-180837
pic-full-210629-180845

Also, "default" is valid for all theme settings ending in "bg", and if the user tries setting anything else to "default", they get the following error:
pic-selected-210629-1758-02

@makew0rld
Copy link
Owner

Thanks for updating!

the text was "default", which is always white. This lead to light text on a light background. This lead to light text on a light background. I circumvent this with a new function

I mentioned that in my previous comment. I don't think this function should happen. Until using default for text can work, whatever the user specified for text color (even white on white) should be respected.

@mcDevnagh
Copy link
Contributor Author

Yes, so the user cannot specify "default" for text, but because they can specify UI elements to have a background of "default", and the text and bg switch colors on focus, text can become ColorDefault on focus.

My code always respects the user's config. The only time the text can change depending on the background is when a UI element is focused, and its background is "default". The effect of my code is the same as yours otherwise

@mcDevnagh mcDevnagh requested a review from makew0rld June 30, 2021 13:09
config/theme.go Outdated
Comment on lines 101 to 102
const gray = 0x88 + 0x88 + 0x88 // The sum of gray's R, G, and B
if r+g+b > gray {
Copy link
Owner

Choose a reason for hiding this comment

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

The "middle gray" as perceived by humans is 119. So I would set gray equal to that. I would calculate the gray value of the color more accurately as 77*r+150*g+29*b + (1<<7) >> 8, and then compare that to gray. Overall this will be more accurate in determining color luminance.

Otherwise looks good, thank you!

@mcDevnagh mcDevnagh requested a review from makew0rld July 6, 2021 11:42
Copy link
Owner

@makew0rld makew0rld left a comment

Choose a reason for hiding this comment

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

Sorry to keep going back and forth on this, just noticed some more things as I went through the PR. Thanks for your work.

form.SetButtonBackgroundColorFocused(config.GetColor("btn_text"))
form.SetButtonTextColorFocused(config.GetColor("btn_bg"))
form.SetButtonTextColorFocused(config.GetTextColor("btn_bg", "btn_text"))
Copy link
Owner

Choose a reason for hiding this comment

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

Isn't this function call, and all the others in this PR, incorrect? The function signature for GetTextColor is GetTextColor(key, bg string) tcell.Color, which would indicate having "btn_bg" second and "btn_text" first. Or am I misunderstanding?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for focused UI elements, the text color and bg color swap. When focused, the button has text color of whatever "btn_bg" is set to, and a bg of whatever color "btn_text" is set to.

Because "default" is not a valid text color in the config, this function is always called with a key ending with bg as its key, and a bg ending with text.

I tried to be as concise as possible with the naming. Maybe SwapColor(new_text_key, new_bg_key string) or something similar would be less confusing.

Copy link
Owner

Choose a reason for hiding this comment

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

No, I think it's good the way it is then, I just misunderstood.

mcDevnagh and others added 3 commits July 7, 2021 18:54
Co-authored-by: makeworld <25111343+makeworld-the-better-one@users.noreply.github.com>
Co-authored-by: makeworld <25111343+makeworld-the-better-one@users.noreply.github.com>
@mcDevnagh mcDevnagh requested a review from makew0rld July 8, 2021 01:18
@makew0rld makew0rld merged commit 3929c97 into makew0rld:master Aug 10, 2021
@makew0rld
Copy link
Owner

Thank you for working on this! Sorry for sleeping on it, don't be afraid to ping if you need in the future.

makew0rld added a commit that referenced this pull request Aug 10, 2021
@mcDevnagh
Copy link
Contributor Author

happy to help :)

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.

2 participants