Comments (8)
Thanks. Closing. BTW I've updated the sample code above to handle interruption during searching.
from editline.
We have the new alternate interface, for event loops, bc7fc7e, which may be of interest to you.
There is also the option of using a different rl_getc_function
. Editline defaults to use the local rl_getc()
fucntion which uses read()
, which is wrapped in a do-while(EINTR)-loop to handle aborted syscalls due to signals. So if you like you could do another implementation of that and install a signal handler in the thread (to prevent the thread from dying), upon return from readline()
the TTY will be restored by el_deprep()
.
Maybe GNU Readline has some other API or method for this, but at this point I haven't looked into that.
from editline.
Thanks. I'll take a look. I was trying to modify rl_getc()
just now.
from editline.
I added a reference implementation for the alternate API in examples/excallback.c
. Having everything in the same thread/process is sometimes the preferred way to go. In particular if you use libev or some other neat event loop instead of rolling your own (as the example does).
from editline.
If I'm correct, current implementation of rl_getc()
ignores SIGINT directly, thus I need a new implementation anyway, even if I go for the alternate API approach. Created PR #29 for this.
The links you provided in #28 is useful for this discussion:
- Signals handling: http://www.delorie.com/gnu/docs/readline/rlman_43.html
- Example of alternate API: https://stackoverflow.com/a/27662212
from editline.
You're almost correct. The rl_getc()
implementation ignores any signal by checking for EINTR
and restarting the syscall. This is common practice in UNIX.
from editline.
FWIW, my implementation of rl_getc()
looks like:
static int interrupted = false;
static int interruptible_getc(void)
{
int r;
char c;
if (interrupted)
return EOF;
r = read(0, &c, 1); // read from stdin, will return -1 when interrupted by a signal
if (r == -1 && errno == EINTR)
interrupted = true;
return r == 1 ? c : EOF;
}
seems work for me.
EDIT: updated the code to make it work when got interrupted when searching
from editline.
Yup, that definitely looks like it should work for you. You may want to keep a list of which signals your application handles and add a check in interruptible_getc()
to make sure you only return EOF when there is SIGINT and not another signal ...
... so maybe we can close this issue now?
from editline.
Related Issues (20)
- Pressing Ctrl+C when searching sends SIGINT after next command HOT 1
- Support for Latin-1? HOT 1
- Cannot find sgstat.h or modes.h. HOT 2
- Request for UTF-8 support HOT 16
- read() returns greater than 1 with some C standard library implementations (i.e. newlib) HOT 13
- Example Step 2 needs header file <stdio.h> HOT 1
- Inclusion in a debian repository HOT 4
- Run with mpi HOT 4
- Address sanitizer reports error HOT 12
- How to call function 'el_bind_key' HOT 3
- The process that uses editline does not respect CTRL+Z HOT 1
- Request for \1 and \2 (RL_PROMPT_START_IGNORE, RL_PROMPT_END_IGNORE) support HOT 1
- ctrl-v for verbatim input
- Prompt not redisplayed after displaying completion possibilities HOT 3
- Need to press CTRL+Z twice to have process (that consumes editline) to go in the background HOT 1
- rl_point is always zero HOT 3
- fileman.c example. Error free(): double free detected in tcache 2 HOT 1
- Can you state in the source it's licensed under Apache-2.0? HOT 3
- Does not compile cleanly HOT 6
- Prompt not displayed on non-interactive sessions, inconsistent with GNU readline HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from editline.