Cygwin typing arrow keys gives "spurious" characters

0

When running a command line app (I'm going $ gradle run in fact, I don't know whether this might be significant), if I inadvertently press the up arrow and then press the down arrow to get back to the prompt line (i.e. in my app) and the press Return, and examine the string entered I'll see something like this:

No index open
> q
you entered: |a aaaq|

... here I only typed "q<Return>" after using the arrow keys... but they've added some funny stuff before the 'q'.

To obtain the user input I'm doing this (Groovy):

response = System.in.newReader().readLine()

Is there any way to make arrow keys (and others which might do something similar) "silent"? NB I have no idea whether this also applies to *nix BASH...

mike rodent

Posted 2018-02-28T19:59:59.603

Reputation: 367

Answers

1

As gradle is a Java program and Cygwin has not its own Java machine, you are running a Windows program (Java machine) inside the Mintty terminal.

As such the usual constraints apply:

When interacting with programs that use a native Windows API for command-line user interaction (“console mode”), a number of undesirable effects are observed; this is the pty incompatibility problem and the character encoding incompatibility problem. This basically affects all programs not compiled in a cygwin or msys environment (and note that MinGW is not msys in this context).

Further info and some possible partial workaround are reported on
https://github.com/mintty/mintty/wiki/Tips#inputoutput-interaction-with-alien-programs

matzeri

Posted 2018-02-28T19:59:59.603

Reputation: 1 662