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

Be able to switch color theme when system switches to darkmode #5999

Closed
chtenb opened this issue Apr 15, 2022 · 32 comments
Closed

Be able to switch color theme when system switches to darkmode #5999

chtenb opened this issue Apr 15, 2022 · 32 comments

Comments

@chtenb
Copy link

chtenb commented Apr 15, 2022

I have my system setup in a way that it switches to and from darkmode based on the time of day. Most applications are able to detect this and be configured to switch to and from a dark color theme. Can alacritty support this as well?

@chrisduerr
Copy link
Member

The config supports live-reload. You're free to switch your theme whenever you want, however you want.

@chtenb
Copy link
Author

chtenb commented Apr 15, 2022

I know that the config has live reload, that's not what meant. @chrisduerr

Most applications are able to detect this and be configured to switch to and from a dark color theme

I meant that you would be able to configure a light and a dark theme in the config, and that alacritty would automatically choose depending on whether your system is in dark mode or light mode.

@chrisduerr
Copy link
Member

I meant that you would be able to configure a light and a dark theme in the config, and that alacritty would automatically choose depending on whether your system is in dark mode or light mode.

There is no desire to add this. Again the existing mechanisms are sufficient.

@chtenb
Copy link
Author

chtenb commented Apr 16, 2022

I just expressed that desire. Why can't this be an open feature request?

I don't mean to sound rude, I just don't understand your reasoning.

@chrisduerr
Copy link
Member

Why can't this be an open feature request?

Because I don't want it to be one.

@ferologics
Copy link

wow.

@chtenb
Copy link
Author

chtenb commented Apr 25, 2022

I've found that wezterm is able to to this @ferologics in case you're interested in this feature

@ferologics
Copy link

@chtenb i think i'm just gonna go with the stock terminal app, the friction with setting up something custom is becoming too painful to justify for.

@ferologics
Copy link

but thx

@chtenb
Copy link
Author

chtenb commented Apr 25, 2022

@ferologics That makes sense, it can be quite a hassle :) If you ever feel like tweaking your setup again feel free to steal my config at https://github.com/chtenb/dotfiles/blob/master/wezterm.lua as a first start.

@SaahilParikh
Copy link

+1

@zaz
Copy link

zaz commented Jun 24, 2023

Again the existing mechanisms are sufficient.

How do we use these? Do we have to run a separate script to check whether the system theme is light or dark? That script would then change the Alacritty config and prompt it to reload? Is that the idea?

Would you accept a patch that adds this feature to Alacritty? What about a patch to add a small bash script that does the above?

This is a really useful feature, so we really should have a way for users to do it easily.

Thank you for your work on Alacritty!

@kchibisov
Copy link
Member

There are plenty resources available online on how to switch themes globally or hook to system theme switching and run arbitrary scripts, alacritty is not a separate citizen here, since you have to do the same for your terminal editor if you're using light/dark themes in it, etc. For alacritty you can have your themes in separate files and import the one you need (import section in the config), the config is live reloaded so it'll be picked up right away.

it's really nothing special here.

@vittorio-c
Copy link

I would love such a feature as well !

in the meantime, could someone put me in the right direction in order to create a bash script that would hook to system theme switching and run something like

sed -i 's/catppuccin-mocha/catppuccin-latte/' ~/.config/alacritty/alacritty.yml

(from https://shapeshed.com/vim-tmux-alacritty-theme-switcher/https://shapeshed.com/vim-tmux-alacritty-theme-switcher/)

I've searched on the internet, but the closest topic I've found to achieve that is a one related to Emacs : https://emacs.stackexchange.com/questions/55417/change-theme-when-os-dark-mode-changes

I'm using Manjaro with Gnome

@kchibisov
Copy link
Member

kchibisov commented Aug 5, 2023

On gnome you'd need to hook to dbus monitor stuff and look for changes on color-scheme variant iirc. Because the dark/light is a dbus property.

org.gnome.desktop.interface color-scheme 'prefer-dark'.

There're also some portal, but it's in dbus all.

@vyas-n
Copy link

vyas-n commented Sep 20, 2023

@kchibisov,

There are plenty resources available online on how to switch themes globally or hook to system theme switching and run arbitrary scripts, alacritty is not a separate citizen here

I greatly appreciate your help, many of us are using custom terminal emulators for the first time and don't know the nomenclature needed to find the solution online.

Would you mind providing links to the "plenty resources available online"?

@tonsky
Copy link

tonsky commented Oct 22, 2023

+1 for this feature. I switch my system between light and dark occasionally, and almost every app follows, except for Alacritty

@nixpulvis
Copy link
Contributor

How do we use these? Do we have to run a separate script to check whether the system theme is light or dark? That script would then change the Alacritty config and prompt it to reload? Is that the idea?

In short, yes.

@vyas-n
Copy link

vyas-n commented Oct 27, 2023

While this feature isn't a dealbreaker, there is a notable dearth of documentation and general unfriendliness of the alacritty configuration system.

It's not the first time I've tried to configure Alacritty and haven't been able to get very far after weeks of searching.

Until alacritty's documentation improves to better show how to configure it, I'm switching to https://github.com/wez/wezterm

@christianfosli
Copy link

I made a quick rust-based service to do this for my personal config files.
(this meaning updating/renaming config files such that the theme changes)
See https://github.com/christianfosli/on-colorscheme-changed

It is written specifically for my config files, but feel free to base your own solutions off of it if you'd like 😄

@martin-braun
Copy link

Why can't this be an open feature request?

Because I don't want it to be one.

I just came across alacritty due to a recommendation, but this sort of response will make me look elsewhere. Sorry for the off-topic. Surely, you are free to do what you want and somebody can still fork and implement it on their own, but it's still such a rude response.

@seguri
Copy link

seguri commented Feb 2, 2024

Such a rude response requires at least a quick & dirty solution for all the poor souls that stumble upon this thread.
This has been tested on macOS.

Requirements:

  • node
  • npm i -g alacritty-themes dark-mode-cli

Add this to your crontab (crontab -e):

* * * * * /path/to/alacritty-themes "$(/bin/test $(/path/to/dark-mode status) = off && /bin/echo Brewer.light || /bin/echo Brewer.dark)"

Don't forget to adapt your full paths (/path/to), e.g. /Users/mark/.volta/bin/alacritty-themes, and change the light and dark themes to your preferred ones.
I've added a && rm ~/.config/alacritty/alacritty.yml.*.bak at the end of mine crontab cause alacritty-themes otherwise generates a backup file every minute.

@onkoe
Copy link

onkoe commented Feb 13, 2024

Sorry to necropost. That said, we shouldn't assert that this functionality already exists.

You must run a daemon alongside the terminal to follow the standard system theming behavior. That's not remotely part of Alacritty. By this logic, you state that Alacritty supports any feature, as a user can write a program with that feature.

It'd be better to say that you don't plan to implement this feature and its functionality doesn't exist.

In addition, I'd suggest maintaining a list of unplanned features (or perhaps a GitHub Issues tag) so users don't get their hopes up. Seeing this issue closed, I assumed that Alacritty had implemented it already! 😖️

@pavlix
Copy link

pavlix commented Feb 26, 2024

So you say I should rather try wezterm?

@seguri
Copy link

seguri commented Feb 27, 2024

So you say I should rather try wezterm?

Because of the attitude? Maybe. Because of night mode? No, you can hack your way around it, even with the new version that has deprecated YAML in favour of TOML.

@dee-kryvenko
Copy link

dee-kryvenko commented Mar 19, 2024

For some reason I hate how unreliable string parsing with sed or equivalents can be, and I would not do these rituals described above personally... but there's always another way.

I did clone https://github.com/alacritty/alacritty-theme

mkdir -p ~/.config/alacritty/themes
git clone https://github.com/alacritty/alacritty-theme ~/.config/alacritty/themes

I did add to my ~/.config/alacritty/alacritty.toml:

import = [
    "~/.config/alacritty/themes/themes/_active.toml"
]

And I did add the following to my ~/.zprofile:

alias aladark="ln -fs ~/.config/alacritty/themes/themes/one_dark.toml ~/.config/alacritty/themes/themes/_active.toml"
alias alalight="ln -fs ~/.config/alacritty/themes/themes/pencil_light.toml ~/.config/alacritty/themes/themes/_active.toml"
func alatheme() {
  ln -fs ~/.config/alacritty/themes/themes/$1.toml ~/.config/alacritty/themes/themes/_active.toml
}

Works like a charm, I just switch on demand running aladark or alalight. Sucks that this is not automatic, but neither it is automatic for nvim, and other terminals that I tried on my mac all have problems with the meta key as left option (including iterm2) and alacritty is the only one that works flawlessly, so I'll take that. Thanks for the project.

@xqm32
Copy link

xqm32 commented Apr 13, 2024

For some reason I hate how unreliable string parsing with sed or equivalents can be, and I would not do these rituals described above personally... but there's always another way.

I did clone https://github.com/alacritty/alacritty-theme

mkdir -p ~/.config/alacritty/themes
git clone https://github.com/alacritty/alacritty-theme ~/.config/alacritty/themes

I did add to my ~/.config/alacritty/alacritty.toml:

import = [
    "~/.config/alacritty/themes/themes/_active.toml"
]

And I did add the following to my ~/.zprofile:

alias aladark="ln -fs ~/.config/alacritty/themes/themes/one_dark.toml ~/.config/alacritty/themes/themes/_active.toml"
alias alalight="ln -fs ~/.config/alacritty/themes/themes/pencil_light.toml ~/.config/alacritty/themes/themes/_active.toml"
func alatheme() {
  ln -fs ~/.config/alacritty/themes/themes/$1.toml ~/.config/alacritty/themes/themes/_active.toml
}

Works like a charm, I just switch on demand running aladark or alalight. Sucks that this is not automatic, but neither it is automatic for nvim, and other terminals that I tried on my mac all have problems with the meta key as left option (including iterm2) and alacritty is the only one that works flawlessly, so I'll take that. Thanks for the project.

Very good idea, thanks @dee-kryvenko! I did some extra work to make it slightly more automated.

I added to my ~/.config/alacritty/alacritty.toml:

[env]
ALACRITTY = "true"

And then I added to my ~/.zshrc:

if [ "$ALACRITTY" = "true" ]
then
  theme() {
    ln -sf $HOME/.config/alacritty/themes/themes/$1.toml $HOME/.config/alacritty/active.toml
  }
  local ALACRITTY_THEME=$(defaults read -g AppleInterfaceStyle 2>/dev/null || echo "Light")
  if [ "$ALACRITTY_THEME" = "Dark" ]
  then
    theme "github_dark"
  else
    theme "github_light"
  fi
fi

Now Alacritty can automatically switch the theme when it starts!

I have written a gist for the whole step: https://gist.github.com/xqm32/17777d035930d622d0ff7530bfab61fd

@nilobarp
Copy link

I have always used the following two functions in my .zshrc

function dark() {
        ln -fs ~/.config/alacritty/themes/catppuccin-frappe.yml ~/.config/alacritty/themes/_active.yml
        touch ~/.config/alacritty/alacritty.yml
}
function light() {
        ln -fs ~/.config/alacritty/themes/catppuccin-latte.yml ~/.config/alacritty/themes/_active.yml
        touch ~/.config/alacritty/alacritty.yml
}

in alacritty config the simlink is imported

import:
  - ~/.config/alacritty/themes/_active.yml

since the config file is touched, alacritty auto loads after the function executes.

@midsorbet
Copy link

Got it working with home-manager + darkman based on #5999 (comment):

  services.darkman = {
    enable = true;
    darkModeScripts = {
      alacritty-theme = ''
        ln -fs ${config.xdg.configHome}/alacritty/dark.toml ${config.xdg.configHome}/alacritty/_active.toml
      '';
    };
    lightModeScripts = {
      alacritty-theme = ''
        ln -fs ${config.xdg.configHome}/alacritty/light.toml ${config.xdg.configHome}/alacritty/_active.toml
      '';
    };
    settings = {
      usegeoclue = true;
    };
  };
  xdg.configFile.alacritty = {
    source = ../config/alacritty;
    recursive = true;
  };

And, I have my themes within my config/alacritty directory

@o-be-one
Copy link

o-be-one commented Oct 25, 2024

Woaw that answer from alacritty dev is really poor!
Thanks to people who built something around to support a simple feature that is now available in most OS and in more and more apps.

@houtianze
Copy link

houtianze commented Mar 2, 2025

Nice, just uninstalled Alacritty after reading this, we have iTerm, WezTerm, Kitty and many more open source ones to choose from.

@ebr
Copy link

ebr commented Mar 19, 2025

Because I don't want it to be one.

OK, well that sucks.

I've been using alacritty for years, but guess might as well switch to another terminal. As an OSS maintainer myself, I'd never condone being this rude to the community, even as a "benevolent dictator". ick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests