-
Notifications
You must be signed in to change notification settings - Fork 57
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 support for custom parsing of APC, SOS and PM sequences. #115
base: master
Are you sure you want to change the base?
Conversation
46e444a
to
04fbc6e
Compare
04fbc6e
to
255c2fe
Compare
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.
I'll give a detailed review later today/tomorrow, but assuming that this was benchmarked it seems like a reasonable approach.
Generally I think the VTE crate needs a little rewrite, but I don't want to hold up other changes for that since it will likely take a long time before I get around to that.
I ran I don't expect any performance impact since I've added no new state and I've only added tailed branches to an already-long match expression, but you never know until you test... |
You can open a PR against alacritty with your changes, so we can use our bot for it. But generally you just build alacritty with your changes and run the |
Thanks! Here are the results: Master Branch:
This PR:
The |
@boazy just open a PR against alacritty's repo, it should better for us to review that way, since we can run the bot. |
@kchibisov I've added a pull request. I'm not sure how to trigger the benchmarks bot. |
You can't. I did. |
Fix typo (case) Co-authored-by: Christian Duerr <[email protected]>
Fix typo (period) Co-authored-by: Christian Duerr <[email protected]>
@boazy This has stalled out for a while now, are you still interested in working on this? I'm slightly concerned because the longer we wait, the higher the chance that a vte rewrite will make all your work worthless. |
I didn't have time for a while, but I've had some time again today and I've checked your suggestion. Unfortunately, I don't think it would be possible without completely re-architecting the way state works. As I've mentioned before, we only have 4 bits for actions that change the state, but we also only have 4 bits for the state itself, and here all possible values (0-15) are used. If we want to support three sets of functions, we would need to track three separate states for each type of string (SOS, PM, APC). This is not possible without either:
The only thing I can do without any major change is to have 3 different functions instead of |
Just to recap because this is quickly fading into obscurity and I don't want to forget about it entirely: Splitting But couldn't you just store that on I believe that's kinda your first suggestion? Why do you think this would impact performance? |
I honestly don't know. I assumed the size is important for performance since we want to be able to have all state transitions in one table (which only has 256 entries?). If we go back to the start, I created this PR trying to answer the comments to the original PR that tried to add APC support (#110), particularly this comment:
I realize I can add additional state that doesn't affect OSC sequences, but seeing this comment I was a bit worried. Do you believe adding an additional field to |
Yeah that's fair. This would make this a slow sloppy implementation and it might not be worth adding it for that reason. But that applies to your current solution too and the only alternative is a bigger rework that integrates this as a core part of our parser.
I think we should either do this, or go for something that properly integrates everything into our standard processing pipeline, which of course is difficult without affecting performance. I'm very hesitant to accept this sort of "second rate escape sequence", but I would prefer that over the current implementation. |
Ok, I think I've understood you now. I'll modify the pull request along these lines. |
9038add
to
cbbdde3
Compare
Split the `opaque_[start|put|end]()` set of functions into 3 different sets of functions for SOS, PM and APC sequences.
cbbdde3
to
45061fd
Compare
Nightly cargo fmt seems to have added new rules since the last commit, so the code (including code that I didn't touch in this PR) doesn't past `cargo fmt +nightly -- --check` anymore.
d511cdd
to
4839d4d
Compare
Going it tenatively approve the current revision, I don't think there's any other changes necessary from your end. While I'm not entirely convinced I'll give this a closer look and if there are no performance regressions it should be fine. |
Fixes #109.
This attempts the same goal at John-Toohey's PR #110, but since this PR was was not accepted, I wanted to try another approach and see whether it is acceptable.
Rationale for support
APC sequences are rarely supported by general-purpose terminals (if we put aside Kermit clients, tmux and screen), but there is one exception: The Kitty Terminal Graphics Protocol. While the Kitty Image Protocol is not as ubiquitous as Sixel, it is more robust, accurate and powerful and it's implemented by several prominent terminal emulators:
It's also supported by a large number of programs and libraries, some of them are mentioned here.
Design
Design Goals
Design Choices
Reorder actions into packable and non-packable actions
Currently, resulting state and actions are packed into an 8-bit value in the state change table (with a 4-bit nibble allocated for each). All values from 0 to 15 for both state and actions are used, so I could not add new states and action that would be packable. Unfortunately, I needed to support a state change with the
OpaquePut
action. The best way I've found is to separate the integer values of actions that do not need to be packed into the state change table (such asHook,
Unhookand
Clear`) into a value higher than 15 and reserve lower values for actions that need to be packedI'm not sure if my current solution is acceptable or not but I have no other idea on how to resolve this situation without repurposing the
OscString
state and actions and re-introducing an embedded parser.Action matching order
This should have minimal impact, but in order to avoid any performance impact for programs which do not use APC sequences, I made sure that when matching APC/SOS/PM-specific actions, they are always matched last.
Streaming
Unlike #110, this PR does not collect the sequence payload inside an array. Instead, the sequence payload is streamed directly to the
Perform
trait, one byte at a time. I believe this approach is more flexible and would lead to better performance overall. The key gains here are:osc_raw
and in any case we would have to increase its default size to 4096 to be compatible with the max payload size).Names
I've changed
SosPmApcString
toOpaqueString
, since I wanted to have a general name for all these types of sequences where the VTE parser has no understanding of the internal structure of the sequence payload. This is difference from OSC and CSI sequences where the VTE parser is aware of the high-level structure of the sequence (if not the semantics).