1

I'm using the python readline module (and using the input() function, which readline modifies). Everything is working, but I would like to add a feature to call a custom python function when a certain key is pressed during input (the function would record that the key was pressed, change the prompt on the current line, and call redisplay to display the new prompt).

Essentially, I want to call rl_bind_key in the underling readline library, but give it a python function as a callback instead of a C function.

Is there a way of doing this short of writing my own extension for the readline library? Does such a thing already exist?

Other than that I don't want to write a new extension if I can avoid it, I would also like this to work when the readline module is compiled with editline, and it seems that would be tricky (mostly to know how to build my extension based on how the readline module was compiled).

2
  • If you want that kind of control over interactivity, perhaps you would be better served using ncurses directly. Commented Jun 14, 2024 at 17:48
  • The application may generate a lot of terminal output, so I don't want to pay the overhead of using curses. I've done this before in perl and C, and it doesn't require anything beyond readline/editline, but I'm not sure how to access it from python. Commented Jun 14, 2024 at 20:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.