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

Make ctrl left and right #131

Open
JelteF opened this issue Nov 24, 2016 · 8 comments
Open

Make ctrl left and right #131

JelteF opened this issue Nov 24, 2016 · 8 comments

Comments

@JelteF
Copy link

JelteF commented Nov 24, 2016

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

@Sonophoto
Copy link

Sonophoto commented Nov 24, 2016

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 :-)

@lethosor
Copy link

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.

@lethosor
Copy link

lethosor commented Nov 24, 2016

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.

@lethosor
Copy link

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.

@lethosor
Copy link

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.

@c-cube
Copy link

c-cube commented Mar 9, 2018

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 : ocaml-community/ocaml-linenoise@c3d130c

@JelteF
Copy link
Author

JelteF commented Mar 9, 2018

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

@Sonophoto
Copy link

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

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

No branches or pull requests

4 participants