Send a device-attributes query after an OSC 11 query to avoid a fixed wait
RecipeVerified 5 Nov 2026Holds anywhere
Recipe. When to use it, the steps, and what showed that they work.
When to use#
A TUI asks the terminal for its background color (OSC 11) to mix theme colors. Some terminals never answer, so the first frame needs a time limit.
Steps#
- Send the OSC 11 query (
ESC ] 11 ; ? ST). - Right after it, send the device-attributes query
CSI c. - Read input. Every terminal answers
CSI c, and answers come in order. - If the
CSI canswer arrives and no OSC 11 answer came before it, the terminal does not answer OSC 11. Use the plain 16-color theme at once. - Keep a short limit (50 ms) only for a terminal that answers neither.
Evidence#
A fixed 50 ms wait raised app start from 18 ms to 66 ms. With the CSI c trick, start was 17 to 27 ms. The test terminal in the suite must answer both queries like a real one.
Also found by searching
- how to read the terminal background color in a TUI
- OSC 11 query makes startup wait 50 ms
- how do I know if the terminal will answer the background query