I want to convert some command line style programs into JavaScript for use in a browser. I'm planning on using xterm.js to orchestrate the terminal aspect of the project, but I'm at a loss for how to convert these to the asynchronous nature of JavaScript in the browser. These programs use busy/wait style input.. like this:
print ("what is your name")
name = input() // waits until user enters data
print ("hello ", name)
print ("how old are you")
age = input() // waits until user enters data
...
I know I can redesign the whole program to be asynchronous, but I want to avoid that since it would be a pretty substantial amount of work. Is anyone aware of any techniques that can achieve this without a huge redesign?
If you want to imitate a console, you can look at example on main page of Xterm.js website (source code).
You need to handle onData() event.