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

Emitting mouse sequences? #21

Open
eaglgenes101 opened this issue Dec 2, 2019 · 3 comments
Open

Emitting mouse sequences? #21

eaglgenes101 opened this issue Dec 2, 2019 · 3 comments
Labels
question Further information is requested

Comments

@eaglgenes101
Copy link

Understandably, emitting escape sequences to generate terminal mouse sequences is rather niche, but is it within the scope of this project? I'm thinking of using it as part of a terminal multiplexer for forwarding mouse events to pseudoterminals.

@zrzka zrzka added the question Further information is requested label Dec 2, 2019
@zrzka
Copy link
Collaborator

zrzka commented Dec 2, 2019

Thanks for the issue. To answer your question, it really depends on how we're looking at the anes crate.

  • One view can be - foundation for crates like crossterm and then it's really out of scope.
    • These crates needs to emit stuff like colors, text attributes, move the cursor, ...
    • Consume input events mouse, key, resize, ...
    • But they do not need to emit mouse events for example.
  • Another view can be - anes states that it provides & parses ANSI escape sequences. Mouse event is an ANSI escape sequence for sure and then it isn't out of scope.

I wrote this crate for the first use case and it doesn't make much sense to add support for this. It's also a bit complicated, see below.


There's no single ANSI escape sequence type for mouse events. We have:

  • X10 compatibility mode - ESC [ M CB Cx Cy (6 bytes only)
  • Xterm - ESC [ < Cb ; Cx ; Cy (;) (M or m)
  • rxvt - ESC [ Cb ; Cx ; Cy ; M

Let's say we will implement Display for the Mouse enum:

https://github.com/zrzka/anes-rs/blob/378ac7461ecac29fde9e10df7b08359d1315a9ad/anes/src/parser/types.rs#L52-L65

Which variant should we emit? X10 compatibility mode? Xterm mode? Rxvt mode? Add special method just for the mouse to emit correct variant? We can introduce another enum like:

enum Mouse {
  Xterm(...),
  X10(...),
  Rxvt(...),
}

Then we will know what to emit, but we will complicate it for the Parser users - they want to know which mouse button was used & the location. They don't care about ANSI escape sequence type.


There's one thing you can do to forward mouse events. Skip the Parser and use Engine & Provide. Unfortunately, both these types are private, but I can make them public. Then you can implement your own provide_csi_sequence in this way:

impl Provider for MyType {
    fn provide_csi_sequence(&mut self, parameters: &[u64], ignored_count: usize, ch: char) {
        if ch == 'm' || ch == 'M' {
            // Mouse event - reconstruct ANSI sequence & forward it
        } else {
            // Not a mouse event
        }
    }
}

Not sure if I helped you. Thoughts?

@eaglgenes101
Copy link
Author

eaglgenes101 commented Dec 4, 2019

I think this makes sense. Thanks. The changes you floated will probably be helpful if they do come in a release, but I can make do without as well.

@zrzka
Copy link
Collaborator

zrzka commented Dec 4, 2019

@eaglgenes101 so for now, I'd recommend to copy & paste Engine & Provide to your code base. I'm still thinking how to expose these two types (directly via anes crate, move just these two types to a separate crate like anes-parser, ...). No decision made yet and I do not want to block you while thinking what would be the best option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants