cantino / mcfly

Fly through your shell history. Great Scott!
MIT License
6.97k stars 178 forks source link

Implement way to automatically detect dark/light terminal #150

Open cmer opened 3 years ago

cmer commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

I have submitted a PR.

WladyX commented 3 years ago

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 commented 1 year ago

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 commented 1 year ago

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