Linenoise: Make ctrl left and right

Created on 24 Nov 2016  ·  8Comments  ·  Source: antirez/linenoise

These keyboard shortcuts are super useful when navigating an already existing line quickly. Is there any reason why they are not implemented?

All 8 comments

A: This is not a typical movement command in POSIX / UNIX. Linenoise is 100% POSIX.

However, it would be easy to add this to your own copy of linenoise. A lot of people that use linenoise hack it for one reason or another. It is very easy to understand and mod.

Here is a chart that compares control key usage on Win/Unix/Emacs: https://en.wikipedia.org/wiki/Control_key


What to do?

on line # 41 in linenoise.c you will find a discussion of how the cursor is controlled.

On line # 768 you will find
static int linenoiseEdit(int stdin_fd, int stdout_fd, char *buf, size_t buflen, const char *prompt)

If you were to change editing functionality it would be here in this function.

Also remember that multi-line editing must be turned on with the API call:

linenoiseSetMultiLine(1);

I hope this helps and Happy Thanksgiving! (no matter where you are :-)

Is this referring to the same idea as #64 and #92, or something else?

I don't think linenoise restricts itself to line editing features defined by POSIX (and I couldn't even find a source of specific escape sequences that POSIX defines, although I found a lot of information on vi/emacs/readline back-word and forward-word sequences). You might be thinking of the fact that linenoise relies on a POSIX environment, but that only means it has to stay away from OS-specific calls.

Maybe I was unclear - I'm aware that control+left doesn't correspond to a control character (in the way that ctrl+a corresponds to \01, etc.). A lot of terminal emulators produce a different escape sequence for this, though (like \033[1;5D or \033f), which some line editing libraries bind by default to navigate forward/backward by a word. At least, I assume that's what this issue is suggesting.

If you've found something that lists which line editing escape sequences POSIX does(n't) define, or something that states that linenoise won't implement any that aren't part of the POSIX standard, please do let me know, as I've been unable to find it.

Edit: if you're referring to the table you linked above, although that isn't referring to POSIX, I think I see your point. I'm not arguing in favor of ctrl+left/right specifically, though, but I don't think some sequence is a bad idea. Also, that isn't a complete list of key combinations or readline bindings - I believe readline binds esc-b/f (and possibly other, longer escape sequences) to back/forward-word by default, which aren't listed there.

I think the feature JelteF wants involves extending the input escape sequences linenoise handles (here, e.g. the sequences generated by pressing arrow keys or delete), and you're referring to output escape sequences (e.g. sequences sent to output to actually move the cursor). I do agree that dealing with termcap is beyond the scope of linenoise, and I appreciate the fact that linenoise is implemented with as few commands as it is.

Perhaps @JelteF could clarify what exactly this feature request is asking for. I thought it was about handling two extra sequences in linenoiseEdit(), but I could be wrong.

Just fyi, if it's about moving one word left/right when ctrl-left or ctrl-right is pressed (with the corresponding long escape sequences \033[5;D and C respectively, I have a patch for that in the OCaml bindings : https://github.com/fxfactorial/ocaml-linenoise/commit/c3d130cd62419ed3e77203bea392b12830c3e593

@c-cube is right that tha's what I meant. Sorry for not responding earlier.

haha, its only been a year and a half, thats nothing in internet time. And right there in linenoiseEdit() too. Thanks @c-cube :+1:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

denisvm picture denisvm  ·  9Comments

ghost picture ghost  ·  4Comments

ozancaglayan picture ozancaglayan  ·  21Comments

fatcerberus picture fatcerberus  ·  5Comments

krux02 picture krux02  ·  8Comments