Open eaglgenes101 opened 4 years ago
Thanks for the issue. To answer your question, it really depends on how we're looking at the anes
crate.
crossterm
and then it's really out of scope.
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:
ESC [ M CB Cx Cy
(6 bytes only)ESC [ < Cb ; Cx ; Cy (;) (M or m)
ESC [ Cb ; Cx ; Cy ; M
Let's say we will implement Display
for the Mouse
enum:
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?
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.
@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.
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.