readline() support in Text widget?

Getting readline() working in a terminal app is trivially easy:

import readline

Now calls to input()/raw_input() have readline support. Done.

But I want to make a graphical app that happens to have a large text input area. I want readline() to work in that text area. I'm not seeing how to make this work.

I thought idle probably did something similar, but there's two problems there. First, it turns out it doesn't support readline(). But even if it did, it is implementing basically an entire shell/editor window from scratch. I don't really want to do that either.

The simplest thing to do would be to embed an xterm inside my app and run the simple terminal readline() program inside it. But then how do I communicate the commands inside the terminal to the surrounding graphical app? Sockets? Seems a little hokey. But it's the only thing I've thought of.

Any ideas?

Posted Nov 16, 2018, 2:53 PM UTC

06
chillermane•

Not an answer to your question, but why do you need readline module to get readline support. Like input() already reads lines so what is it’s purpose

1
DaysBeforeSpringOP•

Really nice editing with hotkeys and history are killer features. In fact, I'm basically working with 1.5 hands tied behind my back without them.

1
chillermane•

I still have no idea why you’re using the readline module

1
DaysBeforeSpringOP•

Write a simple REPL-like program using raw_input(). Start typing. Then press C-a, then C-k.

Now put import readline at the top and try it again.

0
superhappyrobots•

I think you're perhaps a little too focused on one specific tool here, and phrasing the question oddly as a result.

What I think you're really asking is:

"How do I make a GUI text box with readline like features?"

Is that correct? Or do you actually have to use readline specifically, for some reason?

1
DaysBeforeSpringOP•

Well maybe. I mean, yes, I could write all that functionality from scratch...but I'm not going to. It has to exist already. It doesn't have to be literal readline() I guess, but it'll have to be a drop in replacement from the user's POV.

0