mintty / wsltty

Mintty as a terminal for Bash on Ubuntu on Windows / WSL
Other
3.12k stars 104 forks source link

get/read theme name from terminal #280

Closed habamax closed 3 years ago

habamax commented 3 years ago

Is there a way (some environment variable?) to get current theme wsltty uses?

image

(I want my vim to apply colorscheme depending on what wsltty has)

PS, I could probably read and parse config file, but there might be already smth in place?

mintty commented 3 years ago

I could add an OSC sequence to set and query the theme but I think what you really want is to adjust colour usage to the actual current setting. This is only pre-determined by a theme and can be adjusted by individual OSC dynamic colour settings for which corresponding queries already exist. That might be better for the use case.

habamax commented 3 years ago

Not sure I understand :) what queries and how to use them. To avoid XY problem:

  1. I have 2 colorschemes for vim dark and light and 2 matched themes for wsltty.
  2. Colorschemes and themes have the same name (doesn't matter actually)
  3. When I start vim I would like to check what theme wsltty has and apply colorscheme of my preference.

I have tried your script that does the 'opposite' -- changing wsltty theme from the shell but it doesn't work for me -- hangs and does nothing.

mintty commented 3 years ago

what queries

OSC 4;n;?, OSC 10;?, OSC 11;?, see https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands

I'm not sure in what way you'd like to adjust colour usage to the terminal theme. If it's just about determining the colours of your choice you could simply do that by using true colour.

habamax commented 3 years ago

I'm not sure in what way you'd like to adjust colour usage to the terminal theme. If it's just about determining the colours of your choice you could simply do that by using true colour.

I do manually change theme of the wsltty -- that is ok -- depending on the mood or environment I would like to have either light or dark background (and corresponding colors) of the terminal.

So my vimrc has colorscheme mydarkcolors which I would like to change to smth like:

if expand("$WSLTTY_THEME") == 'arbitrary_theme_name_which_I_know_is_dark'
    colorscheme mydarkcolors
else
   colorscheme mylightcolors
endif

And I can already do it -- abstracting expand("$WSLTTY_THEME") condition with a function that reads config file and extracts theme name. Was thinking if wsltty has other means of getting current theme name... which it looks like it hasn't.

habamax commented 3 years ago

I could have used background option of vim

if &background == 'dark'
    colorscheme mydarkcolors
else
    colorscheme mylightcolors
endif

But with wsltty it is always 'light' no matter what theme I apply. Ppl suggest that terminal is not properly setup, whatever it means.

Also vim help explains that background detection depends on: image

habamax commented 3 years ago

Both in tmux and plain wsltty vim's background is always 'light'

UPD: this is actually incorrect, see later messages.

mintty commented 3 years ago

You commented just before (apparently deleted) that tmux would make the difference. Please confirm. And if possible please find out how vim determined its &background flag. I guess that's OSC 11 so I don't see why it should fail in plain wsltty.

habamax commented 3 years ago

You commented just before (apparently deleted) that tmux would make the difference. Please confirm. And if possible please find out how vim determined its &background flag. I guess that's OSC 11 so I don't see why it should fail in plain wsltty.

Hmm, I have double checked again with vim -Nu NONE and :echo &background:

So my deleted message was actually correct :)

habamax commented 3 years ago

Ok, I end up reading the config file :)

vim-wsltty-theme

Sorry for inconvenience :)

mintty commented 3 years ago

Actually pass-through for certain sequences was just an issue with tmux. Maybe you should just upgrade or look out for its next release.