Is there a better way to debug OS.read_string_from_stdin() ?
xyz idk how else explicitly to write this.. im trying to create console application. It runs, does its thing, prints out something to stdout()
, it donest matter.. what matter is that user needs to interact with it, so in order to make it "palatable" for users, i need the console app to keep my stdin
input on screen no matter what the console app is doing in the bg..
Im asking if its even possible.. and if it is how to do it?
xyz Prints are needed - its information about what going on. They happen as the code gets executed. Code execution is done from peers (outside) on demand basis.. i have no control when someone sends something to the console app and then the print out happens..
Its like any other linux app that prints out things and you can still enter commands and see your input and it can execute.. idk..
If its not possible this way then be it..
xyz Do you want to make me this application that i need?
I dont understand how print()
works, i thought it just a bg operation, and while im capturing stdin
in another thread that it could be overlayed on top of the console output.. but if its all in the same domain (it seems like it) then this is not possible the way im seeing it.
One way would be to do with https://docs.godotengine.org/en/stable/classes/class_semaphore.html like the main _process() does its thing and when its done then it lets the stdin
thread do its thing... idk, in no genius when it come to these things.. i just wanted to create a straight forward user friendly understandable interaction with the console application that im working with.. once its done ill post it here.. dont want to spill the beans..
- Edited
kuligs2 So you're using threads that print stuff to stdout? You should have mentioned that in the question.
But it seems that you really don't know what you want.
If you want to suspend threads that write to stdout until the current stdin readout is done, you can do this via mutexes or semaphores. You can even implement a custom print function that'll be muted if certain global condition is met.
If all your code is in the main thread then OS.read_string_from_stdin() will stop the execution until input is finalized (that's the blocking we mentioned earlier), but judging from what we've heard so far, this in not the case.
But the first step is to decide on the exact behavior and modalities of your input/output. Until that is clearly known, all we can say is: yeah, whatever
xyz i want both, print()
functions working alongside with stdin()
. Like i tried to tell you previously, i want so that the stdin
input varriable/string does not get scrolled away while im inputting it in and while other thread print(
) functions are printing to stdout
.
Im not sure if its even possible..
This is not trivial but a quality of life.. if its even possible..
Yeah i tried the mutex things but i dont understand how print() works, and when and how do i lock it up or what not.. I tried the example from the docs, but it dint work and threw me wierd kinds of errors and i didnt wanted to bother learning what mutex is..
Atm everything works if nothing is printing to stdout.. my stdin input stays on screen while im inputting..
- Edited
kuligs2 i want both, print() functions working alongside with stdin(). Like i tried to tell you previously, i want so that the stdin input varriable/string does not get scrolled away while im inputting it in and while other thread print() functions are printing to stdout.
Consoles are sequential and there is only one cursor. I'm sure you're aware of that
What you're talking about sounds like separate input and output widgets.
Something could possibly be patched with cursor movement escape sequences...
Do you have an example of a console application doing exactly what you want?
xyz Well that was my question, i guess you answered it, that the "cursor" is only one.. I was not aware of that, as im not in the know so to speak.. im just a hobbyist..
I dont have an example for what i want to achieve, need to dig around some linux cmd apps to make sure it exists as i thought.. Now that im thinking.. i think it might not exist.. i know when you tail for example log output the cursor is blocked, right? you need to end the tail command to input new command. Maybe im confusing the behavior that i want with some other application