-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Adaptive Theme Selection Based on the Terminal Color Scheme #12098
base: master
Are you sure you want to change the base?
Conversation
1b0d526
to
30da0f9
Compare
There seems to be a small bug when this runs via |
This bug turns out to be a bit trickier. I've spent a few hours and couldn't come up with a clean solution. Crossterm and Colorsaurus are interfering with each other here because Colorsaurus, instead of querying the operating system, uses ANSI escape codes to get the terminal background color and determines the active color scheme that way. This approach has some benefits like allowing theme detection through an ssh session. I believe the interference is happening as soon as the future from the async function I've pondered a bit and could think of the following workarounds:
Some(event) = input_stream.next() => {
// <-- theme detection works here without interference
self.handle_terminal_events(event).await;
// <-- also here
}
Let me know what your thoughts on this are. |
That would be very limiting and render this feature useless for some. People that want to specify two color schemes are likely to switch between light/dark regularly. Ideally, the change of theme should be detected automatically, some how. I don't know if there is a standard way to do it without polling. |
I fully agree with you, but I would leave this decision to the maintainers as they are the ones having to maintain that code in the long run.
On Windows, there's the The Maybe allow the user to switch between different implementations?: theme = "solarized_dark" # static
theme = { source = "os", light = "solarized_light", dark = "solarized_dark" } # Based on the OS Theme
theme = { source = "terminal", light = "solarized_light", dark = "solarized_dark" } # Based on the Terminal color scheme This would increase implementation complexity though. |
One possible alternative approach would be to send out the OSC query on startup and on config reload. Then process the response in I'd be open to exposing more low-level functions in colorsaurus as needed (i.e. Unsolicited info dump regarding change detection Detecting changes directly from the OS is really annoying on macOS (requires an initialized NSApplication) and Windows (requires a running event loop). I have some of those caveats documented here: https://docs.rs/mundy/latest/mundy/struct.Preferences.html#method.subscribe There's currently no way that I'm aware of to be notified by the terminal about theme changes. |
Nit-pick: It does on |
I threw together a prototype based on the idea proposed in my previous comment: #12238 It requires changes to terminal-colorsaurus (of which I am the owner and can publish as needed) and crossterm (no clue if they would accept my change). @luca-schlecker feel free to adopt anything from my prototype PR. |
Just to add, I believe |
Fixes #8899, #10281
Overview
Introduce
theme = { light = "<name>", dark = "<name>" }
syntax insideconfig.toml
to allow adaptive theme selection based on the terminal color scheme.Theme selection is based on terminal-colorsaurus which has also been used in delta and bat.
Considerations