Skip to content

Add global bg_color option#1979

Open
dastarruer wants to merge 8 commits intoClementTsang:mainfrom
dastarruer:add-global-bg-color-option
Open

Add global bg_color option#1979
dastarruer wants to merge 8 commits intoClementTsang:mainfrom
dastarruer:add-global-bg-color-option

Conversation

@dastarruer
Copy link

@dastarruer dastarruer commented Feb 13, 2026

Description

A description of the change, what it does, and why it was made. If relevant (e.g. UI changes), please also provide screenshots/recordings:
Add a bg_color option in WidgetStyle. Also add background color values for the gruvbox, nord, and default theme.

However, when I run with cargo run -- --theme nord, the background color does not apply, instead just using the gruvbox background from my terminal. I don't know what needs to be changed for this to work.

image

Issue

If applicable, what issue does this address?

Closes: #1978

Testing

If relevant, please state how this was tested (including steps):

If this change affects the program, please also indicate which platforms were tested:

  • Windows
  • macOS (specify version below)
  • Linux (specify distro below)
  • Other (specify below)

Distro is NixOS

Checklist

Ensure all of these are met:

  • If this is a code change, areas your change affects have been linted using (cargo fmt)
  • If this is a code change, your changes pass cargo clippy --all -- -D warnings
  • If this is a code change, new tests were added if relevant
  • If this is a code change, your changes pass cargo test
  • The change has been tested to work (see above) and doesn't appear to break other things
  • Documentation has been updated if needed (README.md, help menu, docs, configs, etc.)
  • There are no merge conflicts
  • You have reviewed the changes first
  • The pull request passes the provided CI pipeline

Other

Anything else that maintainers should know about this PR:
Just need help with doing this. Hopefully it's a simple change...

@dastarruer dastarruer force-pushed the add-global-bg-color-option branch from 8135a26 to 02775d1 Compare February 13, 2026 20:32
@ClementTsang
Copy link
Owner

ClementTsang commented Feb 13, 2026

Hmm... my gut reaction is that this something I was ever planning on adding, but maybe it's fine. I can see the use case.

I also do not want to add background colours to any of the existing colour schemes, so please remove that. The default behaviour should be to defer to the user's terminal colour, and I'm not changing that.


As for getting this to work, the thing is you would need to draw a background colour to every cell, not just text (including cells that we might currently not draw to). That's certainly doable, I guess, and not a hard change, but it's not a small change like what you have here.

I guess what you could do is if a background colour is set, before drawing, additionally do one pass on every cell in the terminal first. This could be done by getting a Rect of the terminal, then iterating on every Buffer slice cell and setting the colour. Then, any subsequent draws that may use the background colour can override if necessary. This may also need to alter the background colour settings for anything that doesn't have the background colour set, but I'm not 100% sure on that.

Hopefully this helps. If you would prefer to defer the issue to me I can also take a look.

Copy link
Owner

@ClementTsang ClementTsang left a comment

Choose a reason for hiding this comment

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

Please remove all of the bg colour settings you've changed here for the provided colour schemes. As mentioned in the other comment, I'm not going to change this behaviour (at least for now).

@dastarruer
Copy link
Author

I guess what you could do is if a background colour is set, before drawing, additionally do one pass on every cell in the terminal first. This could be done by getting a Rect of the terminal, then iterating on every Buffer slice cell and setting the colour. Then, any subsequent draws that may use the background colour can override if necessary. This may also need to alter the background colour settings for anything that doesn't have the background colour set, but I'm not 100% sure on that.I guess what you could do is if a background colour is set, before drawing, additionally do one pass on every cell in the terminal first. This could be done by getting a Rect of the terminal, then iterating on every Buffer slice cell and setting the colour. Then, any subsequent draws that may use the background colour can override if necessary. This may also need to alter the background colour settings for anything that doesn't have the background colour set, but I'm not 100% sure on that.

...might be in over my head with this one.

I don't understand the code too well (or ratatui), but can't the style of each Block returned from widget_block in src/canvas/drawing_utils.rs be used to change the background color? If what I'm saying makes absolutely no sense, then I would rather you take a look at this issue instead.

@ClementTsang
Copy link
Owner

A Block is just a thing that wraps a ratatui widget (e.g. the borders). You could also do it with that to get the same effect, by setting the style, though not everything uses it. I also don't know if it will set the style for things like graphs.

@dastarruer
Copy link
Author

Please remove all of the bg colour settings you've changed here for the provided colour schemes. As mentioned in the other comment, I'm not going to change this behaviour (at least for now).

Without the background-color settings, cargo refuses to build since bg_color_style does not get initialized. It would probably be better to figure out how to implement the feature first before I remove the setting with a crappy workaround.

@dastarruer dastarruer marked this pull request as draft February 13, 2026 22:41
@dastarruer dastarruer marked this pull request as draft February 13, 2026 22:41
@ClementTsang
Copy link
Owner

Also yeah I don't mind taking over for this as I don't think it's too bad, just a really messy codebase probably complicates it 😅

@ClementTsang
Copy link
Owner

cargo refused to build

You would want to use an Option for something like this in Rust.

@dastarruer
Copy link
Author

Also converted this to a draft.

@dastarruer
Copy link
Author

cargo refused to build

You would want to use an Option for something like this in Rust.

tried that a few minutes ago, and some macro somewhere was complaining... I don't know how to use macros...

@dastarruer dastarruer force-pushed the add-global-bg-color-option branch from 02775d1 to 0404bab Compare February 14, 2026 18:33
@ClementTsang
Copy link
Owner

Up to you, I can take a look at this later today.

@dastarruer dastarruer force-pushed the add-global-bg-color-option branch 2 times, most recently from bdf459b to 4100fee Compare February 14, 2026 23:27
Instead of iterating over every cell and setting the background color of that,
just set the color of each widget, which achieves the same effect. This can also be overriden if
we add the ability to set the background color of each widget.
@dastarruer dastarruer force-pushed the add-global-bg-color-option branch from 4100fee to 2779aa7 Compare February 14, 2026 23:43
@dastarruer dastarruer force-pushed the add-global-bg-color-option branch from a2d9084 to ad07d15 Compare February 15, 2026 00:22
@dastarruer
Copy link
Author

dastarruer commented Feb 15, 2026

The background color is now read from the config. I added another macro to set the background color, which also means that the user could theoretically configure each widget's background separate from each other. This should be trivial to implement, so let me know if this is something you'd consider worthwhile to add.

2026-02-14.20-38-13.mp4

@dastarruer dastarruer marked this pull request as ready for review February 15, 2026 00:43
@dastarruer dastarruer changed the title WIP: Add global bg_color option Add global bg_color option Feb 15, 2026
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.

Add a global bg_color config option

2 participants