Skip to content

Conversation

@saschatx
Copy link
Contributor

In this pull request, I try to address the issue I mentioned in #24

The Issue

On certain (rare) occasions, the OSC response containing the terminal color that is parsed in _get_terminal_color might have an unexpected format. In these cases, the current implementation might freeze.

I was not able to reliably reproduce the issue, however it's possible to simulate the issue by replacing the expected "end of OSC response" character in line 163 by an incorrect character, e.g. "!". Then, the function should always freeze, if the OSC response is less than 50 characters long.

The solution

My suggested solution is to set sys.stdin to perform non-blocking reads. In my tests, that resolved the issue.
I have to admit that I am not an expert when it comes to these Python functions. I'm not sure if the try-except block is required (it wasn't in any of my tests, but a quick Google search revealed that these exception might be or have been raised here).

Set stdin to non-blocking before reading the OSC response in
_get_terminal_color to avoid freezes due to unexpected response formats.
Added try block to catch exceptions that might occur.
@saschatx
Copy link
Contributor Author

While this works fine on my local machine, I just realized that in GitHub Codespaces it leaks characters to the terminal.
I might have another look at some point.

@patrick91
Copy link
Owner

@saschatx just tested this locally and it fixes a similar but with iTerm, I think we can ship and then maybe do another fix for codespaces? 😊

@saschatx saschatx marked this pull request as ready for review March 29, 2025 17:13
@saschatx
Copy link
Contributor Author

@patrick91 Looks like the latest commit I pushed fixed the issue. From my point of view, this can be merged.

@patrick91 patrick91 merged commit fd98711 into patrick91:main Mar 30, 2025
6 checks passed
@patrick91
Copy link
Owner

thank you @saschatx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants