Hello !
In the project I’m working on (StreamPy), which is basically an implementation of the python console in a streamlit app, I need to redirect python stdin to a custom object with a readline() method supposed to take the input via some kind of text widget appearing on the app, rather than from the terminal. This would allow to use python ‘input’ command as usual and, more generally, deal with various scripts taking inputs from stdin (“press Enter to continue” and all that kind of stuff) directly from the app.
Otherwise, the app waits for input from the terminal… which is not really handy.
The issue here, is the intrinsic “blocking” behavior of reading from stdin. Whenever a program needs input from there, it pauses execution until the user completes the input, and then resumes executing.
Unfortunately the standard st.text_input widget doesn’t block script execution when called… it will just return None, every new refresh loop, until a string is entered. Which is not what we want here.
So, running the app locally on my computer, I tried to redirect stdin to a simple tkinter input box to achieve the desired behavior. Which worked rather well. But it’s not pretty, visually speaking, and won’t work if the app runs on the cloud’s server.
It would be prettier to use a special widget for that purpose, but this “text input” widget should be designed to render and immediately pause the app’s script execution until a string is returned.
I there a way to achieve this kind of “blocking” behavior for a text input widget ?
I mean, is this even possible to achieve with a custom component, given the current implementation of streamlit ?
Thanks for your help !
Cheers
Baptiste