Ray's Knowledge Base
Unlock

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#

  1. Send the OSC 11 query (ESC ] 11 ; ? ST).
  2. Right after it, send the device-attributes query CSI c.
  3. Read input. Every terminal answers CSI c, and answers come in order.
  4. If the CSI c answer arrives and no OSC 11 answer came before it, the terminal does not answer OSC 11. Use the plain 16-color theme at once.
  5. 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