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

Include the ANSI escape sequence that caused the instantiation of an events.Key in the events.Key class #2347

Closed
barisione opened this issue Apr 21, 2023 · 5 comments

Comments

@barisione
Copy link

From what I can see in src/textual/_xterm_parser.py and src/textual/_ansi_sequences.py, ANSI escape sequences get parsed and generate instances of events.Key as needed.

My terminal widget needs to generate ANSI escape sequences back from key events but this is non-trivial if you want to support different terminals. This could be easier if events.Key had an optional field containing the original ANSI escape sequence.

@github-actions
Copy link

We found the following entry in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

@willmcgugan
Copy link
Collaborator

Not opposed to it. But there isn't a one to one mapping of key events to escape sequences. Might complicate things.

When you say terminal widget, do you mean a terminal widget that runs inside Textual ?

@barisione
Copy link
Author

barisione commented Apr 21, 2023

Not opposed to it. But there isn't a one to one mapping of key events to escape sequences. Might complicate things.

Yes but what I was suggesting is that you don't discard the initial information on the escape sequence instead of reconstructing it. This way the sequence should be correct for the specific terminal in use as that terminal sent it in the first place.

When you say terminal widget, do you mean a terminal widget that runs inside Textual ?

Yes, using pyte. I'm aware there's already a similar 3rd-party widget but it's GPL3 so I cannot use it (or look at its code!).

For now I'm just converting key strokes in a naive way. For instance, if I get an "up" key I alway send "\N{ESCAPE}OA" to the TTY for the program running inside the terminal.

@willmcgugan
Copy link
Collaborator

I don't think this is practical, given the somewhat inconsistent ways terminals deal with keys.

@willmcgugan willmcgugan closed this as not planned Won't fix, can't repro, duplicate, stale Sep 27, 2024
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

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

No branches or pull requests

2 participants