Currently I am trying to listen to user input from the command line in my swift application.
I am aware of the readLine()
method but it does not really fit my needs. I want to listen for data being inserted on the command line. Like when a user is pressing the ‘up key’ inside the terminal.
Something like what can be done in Node.js:
stdin.on( 'data', function( key ){
if (key === '\u0003' ) {
process.exit();
} // write the key to stdout all normal like
process.stdout.write( key );
});
I tried searching but I couldn’t find an equivalent to this in Swift. I thought maybe something with ‘Inputstream’ but didn’t a find a appropriate solution either.
If someone could give me some hints on how to do something like this in Swift I would highly appreciate it.