Fix and bullet-proof terminal querying for background colors.

Review Request #14249 — Created Nov. 15, 2024 and submitted — Latest diff uploaded

Information

rbinstall
master

Reviewers

When querying the terminal for background colors, an assumption was made
that we'd always have input. We'd block forever with the assumption that
we had data to read, and this wasn't always the case. It'd then require
mashing on keys until the read buffer was filled, if the terminal and
pipes indeed even fed the keyboard input to the process.

We now put stdin in non-blocking mode and read so long as there's data
to read, until we hit a result with a terminator, fill up the buffer, or
time out.

Along with this, we had a bug where we were looking for the wrong
terminator, which contributed to this blocking issue. The correct
terminator is now used.

Reproduced on a system that was blocking on startup and then interfering
with reading stdin. Verified this fixed the issue I was able to
reproduce.

Commits

Files