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
Emit focus events #689
Emit focus events #689
Conversation
This document specifies what is supported by windows: https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences |
It doesn't seem from the specs they support this yet. So then option two seems a good way to do this. Its quite simple to add custom logic for windows only systems by implementing this function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
a8ff0c7
to
d75ec20
Compare
OK, option 2 implemented! Seems to work on Windows and I believe this is ready to merge. I couldn't think of a straightforward way to test an actual terminal gaining and losing focus. I only wrote a unit test as a result. @TimonPost I've rebased it on #690 to get it to compile on Windows. If this PR looks good, you can merge this one and close 690. If this still needs work, you may want to merge 690 to fix Windows compilation in the meantime. |
src/style.rs
Outdated
@@ -366,6 +366,16 @@ impl Command for SetStyle { | |||
|
|||
Ok(()) | |||
} | |||
|
|||
#[cfg(windows)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you rebase on main, i'll approve and merge. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
4f232ec
to
0287275
Compare
0287275
to
b45e338
Compare
I'd like to receive focus change events from crossterm to let me save on loss of focus in Helix.
This adds focus emitting on Unix, though I still need to add documentation and tests.
I wanted to open a PR now as I'm not clear on the best way to support this on Windows.
Option 1: Windows Terminal added these Unix-style focus events in 1.14.186. That came out a couple weeks ago. I think we'd be able to get those codes since we're enabling virtual terminal processing in Windows, but I don't know enough about the Windows terminal to be sure. I don't see us parsing ansi codes anywhere else in the Windows code, so that makes me worry it's not the case. It would also restrict this to really recent Windows terminal versions.
Option 2: Listen for the FOCUS_EVENT_RECORD in crossterm-winapi. That would be hacky as that focus record is supposed to be internal. It looks like that's what they're using in Windows Terminal to emit the Unix-style codes, so I'm guessing we could use it.
I'm open to any other options, of course. Thoughts?
P.S. This is the first Rust code I've written, and it was super easy to drop it in and modify the example to try it. Thanks for putting together such a well structured project!