Textualize / textual

The lean application framework for Python. Build sophisticated user interfaces with a simple Python API. Run your apps in the terminal and a web browser.
https://textual.textualize.io/
MIT License
24.07k stars 741 forks source link

Automatically detect terminal background color #4674

Open dhallas opened 1 week ago

dhallas commented 1 week ago

Add support for automatically detecting the background color of the terminal using operating system command escape sequence. The response is then parsed and used to determine if the background is light or dark.

fixes #2419

Please review the following checklist.

dhallas commented 1 week ago

I would like to get some feedback on the approach I have taken to add support for this.

I have only tested this with "Kitty" on Mac OS, more testing is needed.

Should the auto light/dark detection be configurable? And maybe off by default?

dhallas commented 1 week ago

@willmcgugan - can you take a look at this MR to check if I am heading in the right direction?

dhallas commented 23 hours ago

What happens on terminals that don't support this?

If you have a Mac, you might want to test terminal.app

I tested this with the terminal.app and to my pleasant surprise it just worked, meaning that the terminal actual supports this escape sequence and responds correctly.