-
Notifications
You must be signed in to change notification settings - Fork 13
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
add bindings for the readline callback interface #8
base: master
Are you sure you want to change the base?
Conversation
add bindings for `rl_callback_handler_install`, `rl_callback_read_char`, and `rl_callback_handler_remove`, as well as two private utility functions and a global store for the non-extern handler.
/// panicking. | ||
pub fn rl_callback_handler_install(prompt: &str, lhandler: fn(Option<String>)) { | ||
let cprmt = CString::new(prompt).unwrap().as_ptr(); | ||
unsafe { _lhandler = Some(lhandler); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmmm. Not sure how I feel about this. lhandler
is left as a Some
value but it won't be useful to the next caller. what if coerced_callback
was used as a curried/partial function instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I would like to do in the ideal case, however I don't know how to correctly pass a curried function (=closure) as a pointer to a c function.
I like the idea of this patch. However, I am not sold on the dangling static |
You're right; that's definitely a hack. I've been contemplating this for a bit, but I haven't thought of anything better (yet, hopefully!) The primary issue is that readline really wants a pointer to a (extern c) function, and I'm not sure how to coerce any kind of closure to that. |
I will take a swing at it but it might be a few days. |
Could you either update example.rs or include a new async-example.rs that demonstrates the use of the new routines? I am a big fan of shipping tests with code. Plus, it gives me something to work with when I try to experiment with patches. |
Done. It's pretty simple, closely paralleling the other example, and doesn't usefully use the aynchronous property of the callback interface, but it demos how it works. It may be worth abstracting from the C interface such that rl_callback_read_char() returns an Option directly, but the obvious way to do this still involves nasty bare globals. |
Perfect. Thank you. |
add bindings for
rl_callback_handler_install
,rl_callback_read_char
,and
rl_callback_handler_remove
, as well as two private utilityfunctions and a global store for the non-extern handler.