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

Implement way to automatically detect dark/light terminal #150

Open
cmer opened this issue May 23, 2021 · 6 comments
Open

Implement way to automatically detect dark/light terminal #150

cmer opened this issue May 23, 2021 · 6 comments

Comments

@cmer
Copy link

cmer commented May 23, 2021

I'd like to propose the following:

If MCFLY_LIGHT is set to TRUE or FALSE, force McFly to display in the specified mode.

If MCFLY_LIGHT is NOT set, make a best effort guess to determine which mode to display in, otherwise fall back to dark mode. I was able to detect light/dark mode in some terminals (but not all) with the following Fish script:

  if string match -r '\;15$' $COLORFGBG &> /dev/null
    set -gx MCFLY_LIGHT TRUE
  end

It'd be awesome if McFly could perform this check every time it is triggered when MCFLY_LIGHT is not set to any particular value.

The COLORFGBG environment variable is set by many terminals such as iTerm2, Rxvt and Konsole. macOS Terminal does NOT set it, however.

@jltml
Copy link

jltml commented May 23, 2021

Totally agreed; this would be wonderful! For anyone stumbling upon this who uses zsh on Mac with Terminal.app, this is what I have in the interim:

mcfly_auto_light_mode() {
  if [[ $(defaults read -g AppleInterfaceStyle) != 'Dark' ]]; then
    export MCFLY_LIGHT=TRUE
  fi
}
zsh-defer mcfly_auto_light_mode

(the zsh-defer is from this plugin)

@cantino
Copy link
Owner

cantino commented May 23, 2021

I'm game if you want to make this change @cmer. I think the determination should be in the mcfly.bash / mcfly.zsh / mcfly.fish scripts that then set the ENV.

@cmer
Copy link
Author

cmer commented May 25, 2021

I have submitted a PR.

@WladyX
Copy link

WladyX commented Dec 1, 2021

This would apply only to new terminal/tabs right? ie it would not apply for existing ones.
I have hacked my .p10k so this gets set on each prompt iteration:

POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS+=(mcfly_theme)
function prompt_mcfly_theme() {
  if grep -q 'light' ~/.theme_status; then
    export MCFLY_LIGHT=TRUE
  else unset MCFLY_LIGHT
  fi
}

i update ~/.theme_status dinamically with dark-notify

would love for mcfly to have a config where i could set this (so it checks for the theme on each run) and i could update that file with https://github.com/cormacrelf/dark-notify

@Tealk
Copy link

Tealk commented Dec 16, 2022

For Gnome 43 it works like this:

colorscheme="$(gsettings get org.gnome.desktop.interface color-scheme)"
if [ ! "$colorscheme" = "'prefer-dark'" ]; then
  export MCFLY_LIGHT=TRUE
fi

@rhersel
Copy link

rhersel commented Dec 16, 2022

dconf read /org/gnome/desktop/interface/color-scheme
'default' --> light theme
'prefer-dark' --> dark theme

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

6 participants