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

Weird handling of Ctrl+C #3

Open
pkoch opened this issue May 4, 2020 · 5 comments
Open

Weird handling of Ctrl+C #3

pkoch opened this issue May 4, 2020 · 5 comments

Comments

@pkoch
Copy link

pkoch commented May 4, 2020

When I add the following to my init.pl:

:- set_prolog_flag(readline, readline).                                        
[library(readline)].

readline does get used. However, pressing Ctrl+C doesn't make the shell immediately react. I have to press it again, and then some other key, leaving me with the message:

?- asdas<press Ctrl+C twice, then another key (like an arrow)>
WARNING: By typing Control-C twice, you have forced an asynchronous
WARNING: interrupt.  Your only SAFE operations are: c(ontinue), p(id),
WARNING: s(stack) and e(xit).  Notably a(abort) often works, but
WARNING: leaves the system in an UNSTABLE state

Action (h for help) ? Unknown option (h for help)
Action (h for help) ? 

Did I mess something up? What can I do to move this closer to the current behaviour when using editline? Would a PR fixing this be accepted?

@JanWielemaker
Copy link
Member

Only set the flag, don't load the library. The startup sequence will do that if the session is interactive.

^C while editing doesn't seem to work. I'm happy to get a PR that fixes this. Otherwise I consider it low priority as there is no point to interrupt editing and the libedit command line editor is the default anyway.

@pkoch
Copy link
Author

pkoch commented May 4, 2020

Thank you for your reply and tips! It feels great to be addressed! :)

Do you have any pointers for where I should start looking to fix that? Are there perhaps examples I can take a look (how is this handled with libedit)? Any inspiration would be appreciated.

@JanWielemaker
Copy link
Member

The sources are in packages/readline. Libedit won't help you much. The APIs of the two command line editors are quite different. IMO the readline one carries a bit too much history, but true, GNU readline is a more capable editor. libedit can be programmed from Prolog though and can provide command line editing from multiple inputs, for example when using the ssh package.

Fixing will require some knowledge about C and Unix signal handling ...

@pkoch
Copy link
Author

pkoch commented May 4, 2020

Pretty comfortable with C and Unix. I'm not familiar with swipl (handling of signals, building it, etc).

I'm guessing I should start by studying this part of the sources?

Signal handling wrapper.

@JanWielemaker
Copy link
Member

That is a good start. I'd build the system for debugging so you can see what happens and where the ^C ends up. It is not very hard. See https://www.swi-prolog.org/build/unix.html and CMAKE.md in the topdir (the last fro setting up the debug build).

pkoch added a commit to pkoch/yadm that referenced this issue May 5, 2020
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

2 participants