Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ReadQueryResponses method that will read ansi responses on windows #249

Closed

Conversation

CannibalVox
Copy link

See #248

Non-windows systems have one way to read events from the terminal: Driver.ReadEvents calls Driver.readEvents, which pulls data from the CancellableReader and parses ANSI data into events.

Windows systems additionally have code that calls into the Windows ReadConsoleInput syscall, which can only read mouse and keyboard events, and will block until an event is received. This syscall cannot be cancelled or timed out.

Currently, there is no way to call the former (which works great!) on Windows. Bubbletea v2 seems to use code that does the latter from an input pump, and I assume it works great in that context. However, ReadEvents is used both for the bubbletea input pump and reading ANSI query responses in lipgloss v2. When used for the latter, the Windows code will hang because ReadConsoleInput isn't used for pulling ANSI query responses and can't be cancelled.

As a result, I would like to split the Driver API into two methods: ReadEvents, to be used from input pumps, and ReadQueryResponses, to be used from queryTerminal & equivalents.

I've verified that when plugged in to use the new method from windows terminal & standalone CMD terminals, lipgloss v2's BackgroundColor will successfully parse the primary DA response and immediately return a null background color. When used from the windows terminal preview version, lipgloss v2's BackgroundColor will actually return the correct background color.

aymanbagabas added a commit to charmbracelet/lipgloss that referenced this pull request Nov 8, 2024
This drops the dependency on `github.com/charmbracelet/x/input` and
`github.com/erikgeiser/coninput` by manually parsing the terminal
response to the background color query using `ansi`.

Since we moved `x/input` to Bubble Tea, and the code is no longer
maintained, we need a different approach to query the terminal for the
background color. This is basically doing the same thing as before, but
manually parsing the response instead of using the `x/input` package.

Fixes: charmbracelet/x#248
Supersedes: charmbracelet/x#249
@CannibalVox
Copy link
Author

@aymanbagabas put together the actually correct fix for this in charmbracelet/lipgloss#429

@CannibalVox CannibalVox closed this Nov 8, 2024
@CannibalVox CannibalVox deleted the fix-terminal-query branch November 8, 2024 04:26
aymanbagabas added a commit to charmbracelet/lipgloss that referenced this pull request Nov 12, 2024
This drops the dependency on `github.com/charmbracelet/x/input` and
`github.com/erikgeiser/coninput` by manually parsing the terminal
response to the background color query using `ansi`.

Since we moved `x/input` to Bubble Tea, and the code is no longer
maintained, we need a different approach to query the terminal for the
background color. This is basically doing the same thing as before, but
manually parsing the response instead of using the `x/input` package.

Fixes: charmbracelet/x#248
Supersedes: charmbracelet/x#249
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.

1 participant