idris-community / inigo

Inigo: A Package Manager for Idris2
https://inigo.pm
MIT License
61 stars 7 forks source link

inigo exec inserts input to stdin #6

Closed bbarker closed 3 years ago

bbarker commented 4 years ago

Or at least, that is seemingly the case:

[nix-shell:~/workspace/WTInterp]$ inigo exec
Executing WTInterp with args []...
Enter a number: 0

[nix-shell:~/workspace/WTInterp]$ idris2 -o WTInterp WTInterp.idr 

[nix-shell:~/workspace/WTInterp]$ ./build/exec/WTInterp
Enter a number: 5
15

So as you can see, when using inigo exec, the program does not wait for input, but does when it is run directly from the command line.

Here is a repository demonstrating the issue: https://github.com/bbarker/WTInterp

hayesgm commented 4 years ago

Yes, this is currently an issue in how we execute the system function in Inigo. We should hook in stdin and connect properly to the process. We specifically call child_process.spawn with this foreign: https://github.com/hayesgm/inigo/blob/master/Inigo/Async/Base.idr#L15

I actually think the Unix-way to complete this process would be to fork into the new process, but at least for the Node codegen, we're constrained to the NodeJS standard libraries (which have the benefit of generally being cross-platform).

hayesgm commented 4 years ago

The JavaScript code that currently runs, expanded out is:

(cmd, args, detached, verbose) =>
    new Promise((resolve,reject) => {
        let opts = {
            detached:detached===0n,
            stdio: ['ignore', process.stdout, process.stderr]
        };
        __require_child_process
            .spawn(cmd, toArray(args), opts)
            .on('close', (code) => resolve(code));
    })

The goal is to find a good JavaScript standard lib function or set of functions which let the new process take over the tty input.