WIP: Read the terminal colour scheme on REPL startup#59958
WIP: Read the terminal colour scheme on REPL startup#59958tecosaur wants to merge 1 commit intoJuliaLang:masterfrom
Conversation
5633335 to
7e22584
Compare
7e22584 to
c89eef3
Compare
80b448e to
0c05f5b
Compare
Any issue that we can file upstream? This is a fairly common configuration, esp. since iTerm2 has tmux integration |
Potentially, there seem to be a few closed OSC-related issues on tmux's repo. I'm also not 100% on the performance: it might be passing through fg/bg info, in which case as of some recent (unpushed) improvements we will still be able to set pick light/dark appropriately and set fg/bg colours. Testing tmux locally myself, I see that it does pass through OSC 10 and OSC 11 codes (these are the fg/bg codes): |
|
I'm not sure what's a good idea to do here in terms of unit testing, since this should be tested against a collection of different terminal emulators. |
Yes please! |
0c05f5b to
9869f0c
Compare
|
I now plan on getting this merged after #60527, and have adjusted the PR accordingly. |
| end | ||
|
|
||
| const PENDING_RESPONSES = OSCResponse[] | ||
| const RESPONSE_POLLERS = Tuple{Function, Timer}[] |
There was a problem hiding this comment.
Why does this architecture need to be so complicated with the pollers and the timeouts, why not just set the colors when the response comes in whatever time that might be.
There was a problem hiding this comment.
Because we want to set the colours all at once after 16 responses have come in, but some terminals only partially respond (and so we'd be waiting forever without a timeout).
There was a problem hiding this comment.
So why isn't that an integer that just counts how many you got and runs the function when that integer hits 16.
There was a problem hiding this comment.
Because then we'd never apply the partial response (foreground + background only), which is what we rely on the timeout for.
There was a problem hiding this comment.
So two integers then. I really don't see the point of the timeout.
There was a problem hiding this comment.
How do we know if we should keep on waiting without a timeout?
|
Given #61151 and and (my) interest in supporting KKP eventually, it would probably be good to support non-OSC queries too, specifically primary device attributes (DA1: As it is, OSC support lets us query more than just colour: such as clipboard contents (when possible), and OSC 99 support. |
This is prepratory work for #61151 and #59958. The key problem is that when we issue informational queries to the terminal emulator, we don't really have any way of knowing when they'll come back. There could be arbitrary amount of actual user input before or after. Thus, any code that would attempt to read from the terminal inline to read OSC responses faces the problem of accidentally getting user input and likewise, the REPL may see delayed OSC responses that are not inteded for it. To avoid all that complication, just put the REPL in charge of OSC response processing. The idea here is that at some point something issues the OSC query (possibly at startup) and whenever the response comes in, the REPL will just process it as if it was user input. This PR intentionally does not define a query interface, which is delagated to the follow on PRs that actually make use of this information. Example: ``` julia> write(stdout, "\e[c") 3 julia> 52 in Base.active_repl.mistate.terminal_properties.da1 true ```
This is prepratory work for #61151 and #59958. The key problem is that when we issue informational queries to the terminal emulator, we don't really have any way of knowing when they'll come back. There could be arbitrary amount of actual user input before or after. Thus, any code that would attempt to read from the terminal inline to read OSC responses faces the problem of accidentally getting user input and likewise, the REPL may see delayed OSC responses that are not inteded for it. To avoid all that complication, just put the REPL in charge of OSC response processing. The idea here is that at some point something issues the OSC query (possibly at startup) and whenever the response comes in, the REPL will just process it as if it was user input. This PR intentionally does not define a query interface, which is delagated to the follow on PRs that actually make use of this information. Example: ``` julia> write(stdout, "\e[c") 3 julia> 52 in Base.active_repl.mistate.terminal_properties.da1 true ```
This is prepratory work for #61151 and #59958. The key problem is that when we issue informational queries to the terminal emulator, we don't really have any way of knowing when they'll come back. There could be arbitrary amount of actual user input before or after. Thus, any code that would attempt to read from the terminal inline to read OSC responses faces the problem of accidentally getting user input and likewise, the REPL may see delayed OSC responses that are not inteded for it. To avoid all that complication, just put the REPL in charge of OSC response processing. The idea here is that at some point something issues the OSC query (possibly at startup) and whenever the response comes in, the REPL will just process it as if it was user input. This PR intentionally does not define a query interface, which is delagated to the follow on PRs that actually make use of this information. Example: ``` julia> write(stdout, "\e[c") 3 julia> 52 in Base.active_repl.mistate.terminal_properties.da1 true ```
This is prepratory work for #61151 (and could be extended in #59958). The key problem is that when we issue informational queries to the terminal emulator, we don't really have any way of knowing when they'll come back. There could be arbitrary amount of actual user input before or after. Thus, any code that would attempt to read from the terminal inline to read OSC responses faces the problem of accidentally getting user input and likewise, the REPL may see delayed OSC responses that are not inteded for it. To avoid all that complication, just put the REPL in charge of OSC response processing. The idea here is that at some point something issues the OSC query (possibly at startup) and whenever the response comes in, the REPL will just process it as if it was user input. This PR intentionally does not define a query interface, which is delagated to the follow on PRs that actually make use of this information. Example: ``` julia> write(stdout, "\e[c") 3 julia> 52 in Base.active_repl.mistate.terminal_properties.da1 true ```
This is prepratory work for #61151 (and could be extended in #59958). The key problem is that when we issue informational queries to the terminal emulator, we don't really have any way of knowing when they'll come back. There could be arbitrary amount of actual user input before or after. Thus, any code that would attempt to read from the terminal inline to read OSC responses faces the problem of accidentally getting user input and likewise, the REPL may see delayed OSC responses that are not inteded for it. To avoid all that complication, just put the REPL in charge of OSC response processing. The idea here is that at some point something issues the OSC query (possibly at startup) and whenever the response comes in, the REPL will just process it as if it was user input. This PR intentionally does not define a query interface, which is delagated to the follow on PRs that actually make use of this information. Example: ``` julia> write(stdout, "\e[c") 3 julia> 52 in Base.active_repl.mistate.terminal_properties.da1 true ```
This is prepratory work for #61151 and #59958. The key problem is that when we issue informational queries to the terminal emulator, we don't really have any way of knowing when they'll come back. There could be arbitrary amount of actual user input before or after. Thus, any code that would attempt to read from the terminal inline to read OSC responses faces the problem of accidentally getting user input and likewise, the REPL may see delayed OSC responses that are not inteded for it. To avoid all that complication, just put the REPL in charge of OSC response processing. The idea here is that at some point something issues the OSC query (possibly at startup) and whenever the response comes in, the REPL will just process it as if it was user input. This PR intentionally does not define a query interface, which is delagated to the follow on PRs that actually make use of this information. Example: ``` julia> write(stdout, "\e[c") 3 julia> 52 in Base.active_repl.mistate.terminal_properties.da1 true ``` Written by Claude.
This is prepratory work for #61151 and #59958. The key problem is that when we issue informational queries to the terminal emulator, we don't really have any way of knowing when they'll come back. There could be arbitrary amount of actual user input before or after. Thus, any code that would attempt to read from the terminal inline to read OSC responses faces the problem of accidentally getting user input and likewise, the REPL may see delayed OSC responses that are not inteded for it. To avoid all that complication, just put the REPL in charge of OSC response processing. The idea here is that at some point something issues the OSC query (possibly at startup) and whenever the response comes in, the REPL will just process it as if it was user input. This PR intentionally does not define a query interface, which is delagated to the follow on PRs that actually make use of this information. Example: ``` julia> write(stdout, "\e[c") 3 julia> 52 in Base.active_repl.mistate.terminal_properties.da1 true ``` Written by Claude. (cherry picked from commit 331421e)
Wouldn't it be nice if Julia/the REPL knew what your terminal colours were, and displayed content appropriately?
useful description coming soon-ish
Sneak peek:
Query durations
Important
This is asynchronous, and does not impact startup latency
Tested terminals
Test script
Everything works
Misbehaving (terminal's fault)
Misbehaving (our fault)
This is not ready for review yet, I just want CI to build it so that helpful testers on Zulip (:wave:) can try this with
juliaup add +pr59958.