-
-
Notifications
You must be signed in to change notification settings - Fork 675
Set screen formatter colours based on terminal BG #1276
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
base: main
Are you sure you want to change the base?
Conversation
Two-stage background detection: $COLORFGBG followed by OSC11. Fallback to dark if colour can't be detected using the methods above. Can be overriden by $BANDIT_LIGHT_BG environment variable.
Ping @ericwb , @lukehinds , @sigmavirus24 |
Fix the broken CI then someone may spend the time reviewing this |
Two-stage background detection: $COLORFGBG followed by OSC11. Fallback to dark if colour can't be detected using the methods above. Can be overriden by $BANDIT_LIGHT_BG environment variable.
e5a0303
to
9d0cea6
Compare
@sigmavirus24 I take you meant to say "please fix your contribution", not "fix our broken CI" :) Running tests as per CONTRIBUTING.md:
From the list above:
|
https://github.com/PyCQA/bandit/actions/runs/15929218056/job/44934249349#step:5:42 That's failing due to your change. If you're unwilling to contribute in good faith and instead are going to be hyper-literal, I'm not sure it's worth my spending more time helping you land this |
@sigmavirus24 , I have no clue what are you talking about. I have tested the patch in I have ticked the box "allow edits by maintainers" (which you are). You are very welcome to do further changes that will satisfy the CI. If GitHub machinery can be changed in a way that allows me to see these errors as well - I am equally happy to take a look at them myself. |
You say pep8 "implodes spectacularly" but you don't share the implosion or try to fix it.
Is what is in the logs. I don't know what's wrong with your browser configuration that you cannot see the logs but I can always see the logs on any project I contribute to regardless of whether I'm a maintainer or not.
If you see def term_detect_bg() -> bool | None: You can use import typing as t
# ...
def term_detect_bg() -> t.Optional[bool]: I'm uninterested in merging this as it doesn't scratch any itch I have so I will not fix this for you. |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
tox run -e pep8
tox run -e pep8 from Python 3.9 / Debian 11 container
The
Anyway, with the latest changes the code should work with Python 3.9-3.13. |
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.
So Bandit already has a dependency on rich
. I'd rather see a solution that can utilize the rich
library to do theming or Styles based on a configurable light or dark mode. I believe this is the direction you're going somewhat now. So how can we capitalize on rich to do it.
https://rich.readthedocs.io/en/stable/style.html#style-themes
@ericwb , I'd be happy to, however I am not certain where and how this would work. def term_serve_colourscheme() -> Dict[str, Style]:
light = term_detect_bg()
return {
"DEFAULT": Style(),
"HEADER": Style(color="blue", bold=True) if light else Style(color="cyan", bold=True),
"LOW": Style(color="green", bold=True) if light else Style(color="green", bold=True),
"MEDIUM": Style(color="magenta", bold=True) if light else Style(color="yellow", bold=True),
"HIGH": Style(color="red", bold=True) if light else Style(color="red", bold=True),
} ...but then we will need to change the rest of the code that relies on In regards to the colour detection itself - I have not found anything of use in the documentation, certainly not a "please tell me if it's a dark terminal" utility. Thoughts? |
Two-stage background detection: $COLORFGBG followed by OSC11.
Fallback to dark if colour can't be detected using the methods above.
Can be overriden by $BANDIT_LIGHT_BG environment variable.
Resolves: #1271
Bright BG
Dark BG