adamdruppe / arsd

This is a collection of modules that I've released over the years. Most of them stand alone, or have just one or two dependencies in here, so you don't have to download this whole repo.
http://arsd-official.dpldocs.info/arsd.html
530 stars 127 forks source link

Support readline keybindings #268

Closed moon-chilled closed 3 years ago

adamdruppe commented 3 years ago

oh this is gonna be merge conflict city since I'm in the middle of doing some very similar stuff on my copy....

adamdruppe commented 3 years ago

So another concern I have is changing those ctrl+x bindings. I almost made this change myself too.... but it is a little bit iffy for three reasons:

1) this is a breaking api change. A silent one too, no help from the compiler in realizing your code must now check it differently. I can live with this if the benefit is significant but I'm not sure it is a positive at all.

2) On some terminals, some of them are indistinguishable from other input. Like ctrl+h and backspace sending the same thing. So if someone tried to process ctrl+h distinct from '\b'... their code is mysteriously never triggered. When they share a char value at least it clues them into why.

BUT some terminals do have a feature to distinguish these! tell you! In my branch I'm processing that too but it is not general enough to rely on.

(and processing alt, oh dear that's so inconsistent, but that's another story. The esc prefix is the most common, but that's problematic - another timing hack to detect it - and some terminals set the high bit instead, which breaks utf-8 processors but it is still fairly common - and then there's that same opt-in xterm feature to make it relatively sane that I intend to do in the emulated terminal.)

3) The behavior is actually consistent cross-platform. The special feature some terminals have is explicitly opt in, otherwise both Windows and Linux do the ctrl+h sends char 8, etc., thing. So there's no need to translate to get a consistent cross platform experience.

So I thought about changing it then decided not to...

I might go ahead and merge this, but then undo the ctrl change.... like I think overall it isn't rally good or bad but there's the legacy compatibility to think about too...

adamdruppe commented 3 years ago

https://github.com/adamdruppe/arsd/commit/b1f57a3ef1643cbecb8b47c98ee641ce73f328e6

That seems to work pretty well without excessive duplication. Setting the flag anyway isn't strictly correct but I think good enough for practical purposes. Just handling both chars in the same case.

I still have to fix ctrl+space, that's actually sent as char 0. Yeah. lol

And then I'll do the terminal emulator side of the xterm feature and we will have joy because the xterm extension supports disambiguation and more!

moon-chilled commented 3 years ago

IMO it would be better to do something like dchar C(dchar x) { return x&0x1f; }, and then e.g. case 'b', C('b'). That way it's not just magic numbers.