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

[Issue] Foot terminal loses color theming #927

Open
NotAF0e opened this issue Nov 5, 2024 · 6 comments
Open

[Issue] Foot terminal loses color theming #927

NotAF0e opened this issue Nov 5, 2024 · 6 comments

Comments

@NotAF0e
Copy link

NotAF0e commented Nov 5, 2024


The issue

Foot terminal loses color theming temporarily, perhaps when a reset command is sent by a cli app.

To see if you can reproduce it run pipes.sh -R and wait for it to complete 1 run. After the next run terminal colors will be reset.

@SeeStarz
Copy link

SeeStarz commented Nov 6, 2024

my workaround is to change the terminal emulator's color config directly everytime the wallpaper change is triggered instead of relying on escape codes (which does get reset). if you are interested i can give you an example.

@NotAF0e
Copy link
Author

NotAF0e commented Nov 6, 2024

Yeah sure! I saw colour configurations in the foot.ini perhaps disable the auto then add them manually or change the theme script to modify the ini directly

@SeeStarz
Copy link

SeeStarz commented Nov 6, 2024

Place this script somewhere, I know it's scuffed but it works. Don't forget to change the paths

#!/usr/bin/python
import os
import sys

# TODO: change username, i haven't looked up how to get the usual home dir and stuff in python
color_path = "/home/fahri/.cache/ags/user/generated/material_colors.scss"
foot_config_path = "/home/fahri/.config/foot/colors.ini"

# Generate and replace colors.ini
def generate_foot_colors():
    # Read the material color file and create a dictionary of relevant colors (term[0-15])
    term_colors = {}
    with open(color_path, "r") as file:
        for line in file:
            tokens = line.split()
            if len(tokens) > 0 and tokens[0][:5] == "$term":
                # print(tokens)
                name = tokens[0].lstrip("$").rstrip(":")
                value = tokens[1].lstrip("#").rstrip(";")
                # print(name, value)
                term_colors[name] = value

    # Basically make another dictionary, now with key that is usable for foot config
    foot_colors = {"background": ""} | {
        "regular" + str(i): "" for i in range(8)} | {"bright" + str(i): "" for i in range(8)}
    for color in foot_colors:
        if color[:7] == "regular":
            foot_colors[color] = term_colors["term" + color[7]]
        elif color[:6] == "bright":
            foot_colors[color] = term_colors["term" + str(int(color[6]) + 8)]
        else:
            foot_colors[color] = term_colors["term0"]

    # Write the result to the config file
    with open(foot_config_path, "w") as file:
        file.write("[colors]\n")
        for color in foot_colors:
            file.write(color + "=" + foot_colors[color] + "\n")

if __name__ == "__main__":
    generate_foot_colors()

In ~/.config/hypr/custom/keybinds.conf add this two lines, adjust according to your script path

unbind = Ctrl+Super, T
bind = Ctrl+Super, T, exec, ${HOME}/.config/ags/scripts/color_generation/switchwall.sh ; /home/fahri/Scripts/change_wallpaper.py

In ~/.config/foot/foot.ini add

[main]
include=~/.config/foot/colors.ini

After changing wallpaper, ~/.config/foot/colors.ini should contain something like this

[colors]
background=1A1A1D
regular0=1A1A1D
regular1=8681FF
regular2=64DCF0
regular3=FFDCF3
regular4=8BADD4
regular5=9DA5EF
regular6=95D0FB
regular7=E8D3DE
bright0=C3B5C0
bright1=BCB9FF
bright2=F7FDFF
bright3=FFFFFF
bright4=C8DEF5
bright5=D6D6FF
bright6=F8FBFF
bright7=E0E3E8

Do note that as far as I know, changing the config will only affect subsequent runs of foot terminal but not the current sessions. This shouldn't be an issue if you're not changing wallpaper that often (some other apps won't update automatically either, only after restart)

@NotAF0e
Copy link
Author

NotAF0e commented Nov 7, 2024

Thanks this works! Perhaps we can get a pr to merge this in? (I don't know how to make one)

@nx-smul
Copy link

nx-smul commented Nov 9, 2024

Place this script somewhere, I know it's scuffed but it works. Don't forget to change the paths

#!/usr/bin/python
import os
import sys

# TODO: change username, i haven't looked up how to get the usual home dir and stuff in python
color_path = "/home/fahri/.cache/ags/user/generated/material_colors.scss"
foot_config_path = "/home/fahri/.config/foot/colors.ini"

# Generate and replace colors.ini
def generate_foot_colors():
    # Read the material color file and create a dictionary of relevant colors (term[0-15])
    term_colors = {}
    with open(color_path, "r") as file:
        for line in file:
            tokens = line.split()
            if len(tokens) > 0 and tokens[0][:5] == "$term":
                # print(tokens)
                name = tokens[0].lstrip("$").rstrip(":")
                value = tokens[1].lstrip("#").rstrip(";")
                # print(name, value)
                term_colors[name] = value

    # Basically make another dictionary, now with key that is usable for foot config
    foot_colors = {"background": ""} | {
        "regular" + str(i): "" for i in range(8)} | {"bright" + str(i): "" for i in range(8)}
    for color in foot_colors:
        if color[:7] == "regular":
            foot_colors[color] = term_colors["term" + color[7]]
        elif color[:6] == "bright":
            foot_colors[color] = term_colors["term" + str(int(color[6]) + 8)]
        else:
            foot_colors[color] = term_colors["term0"]

    # Write the result to the config file
    with open(foot_config_path, "w") as file:
        file.write("[colors]\n")
        for color in foot_colors:
            file.write(color + "=" + foot_colors[color] + "\n")

if __name__ == "__main__":
    generate_foot_colors()

In ~/.config/hypr/custom/keybinds.conf add this two lines, adjust according to your script path

unbind = Ctrl+Super, T
bind = Ctrl+Super, T, exec, ${HOME}/.config/ags/scripts/color_generation/switchwall.sh ; /home/fahri/Scripts/change_wallpaper.py

In ~/.config/foot/foot.ini add

[main]
include=~/.config/foot/colors.ini

After changing wallpaper, ~/.config/foot/colors.ini should contain something like this

[colors]
background=1A1A1D
regular0=1A1A1D
regular1=8681FF
regular2=64DCF0
regular3=FFDCF3
regular4=8BADD4
regular5=9DA5EF
regular6=95D0FB
regular7=E8D3DE
bright0=C3B5C0
bright1=BCB9FF
bright2=F7FDFF
bright3=FFFFFF
bright4=C8DEF5
bright5=D6D6FF
bright6=F8FBFF
bright7=E0E3E8

Do note that as far as I know, changing the config will only affect subsequent runs of foot terminal but not the current sessions. This shouldn't be an issue if you're not changing wallpaper that often (some other apps won't update automatically either, only after restart)

try this

color_path = os.path.expanduser("~/.cache/ags/user/generated/material_colors.scss")

foot_config_path = os.path.expanduser("~/.config/foot/colors.ini")

@SeeStarz
Copy link

SeeStarz commented Nov 9, 2024

Thanks this works! Perhaps we can get a pr to merge this in? (I don't know how to make one)

I'm not really interested in making a pull request of this horrible code (I don't really want to fix it either), though if anyone wants to do so then by all means go ahead. Even then most of the scripts are written in bash, so it will look a little out of place at best.

try this
color_path = os.path.expanduser("~/.cache/ags/user/generated/material_colors.scss")
foot_config_path = os.path.expanduser("~/.config/foot/colors.ini")

Thanks @nx-smul that's a good quick fix.

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

No branches or pull requests

3 participants