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

[REQUEST]Automatic switch theme from dark to light based on Gnome theme #928

Open
lamyergeier opened this issue Sep 17, 2024 · 2 comments
Open
Assignees
Labels
enhancement New feature or request

Comments

@lamyergeier
Copy link

Is your feature request related to a problem? Please describe.
I would like to switch from solarized light to solarized dark depending on if on Gnome it is dark theme enabled or not.

Describe the solution you'd like
Automatic switch theme from dark to light based on Gnome theme, or atleast when it is starting it should be mindful of the Gnome dark theme settings

Additional

Please give CLI option to set theme, so that I can atleast automate through a bash function

@lamyergeier lamyergeier added the enhancement New feature or request label Sep 17, 2024
@imwints
Copy link
Contributor

imwints commented Sep 19, 2024

The first problem is that there is no mapping of [Light <-> Dark] themes. There are a couple of themes that only have one variant. So btop doesn't know (and probably shouldn't care) if you're theme is dark or light. The other thing is that this would tie a CLI application to a desktop, and I'm not sure if this is good idea.

Please give CLI option to set theme, so that I can atleast automate through a bash function

This seems reasonable.

As a workaround, this wrapper script edits the config based on the theme type you provide it.
You still need to talk to gnome and parse it's mode and pass either dark or light to the script.

#!/usr/bin/env python3

import os
import subprocess
import sys
from pathlib import Path

# Mode is the first command line argument
# As an alternative, set mode based on gnome's theme type here
mode = sys.argv[1]

# Path to btop's config file in the user's home
config = (
    Path(os.path.expanduser("~"))
    .joinpath(".config")
    .joinpath("btop")
    .joinpath("btop.conf")
)

# Read the config, replacing the `color_theme` statement based on the `mode`
with config.open() as file:
    lines = [
        line if "color_theme" not in line else f'color_theme = "solarized_{mode}"\n'
        for line in file
    ]

# Write the new config
with config.open("w") as file:
    for line in lines:
        file.write(line)

# Launch btop
subprocess.run(["btop"], check=False)

@lamyergeier
Copy link
Author

@imwints Could you provide a CLI Option --theme?

So users can start btop as follows

btop --theme "Solarized dark"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants