I am using Bash(version 4.3.46(6)) shell in Cygwin mintty terminal on Windows 7 64bit OS, and trying to make simple CUI application using Fortran 90. My simplified source-code is like this.
integer :: i
character ( len = 500 ) :: mybuffer
do
write ( * , '(a)' , advance = 'no' ) 'PROMPT> '
read ( * , '(a)' ) mybuffer
write ( * , '(500Z3)' ) ( iachar ( mybuffer ( i : i ) ) , i = 1 , 6 )
end do
end
where write statement on line 6 is optional (just for check).
This seemed to work well for printable characters. I have observed the string from stdin is echoed back on terminal and the string saved into variable mybuffer
.
but when I type arrow keys, this same echo back happens, which is not hopeful for this time.
In my terminal, I have checked (with this source code) that up-arrow key code is \x1B\x5B\x41
which is \e[A
.
Then I thought it might be the matter of stty ((GNU coreutils) 8.25), so I tried
stty --help
and found this (I consider is most related) part in the help.
Local settings:
[-]crterase echo erase characters as backspace-space-backspace
* crtkill kill all line by obeying the echoprt and echoe settings
* -crtkill kill all line by obeying the echoctl and echok settings
* [-]ctlecho echo control characters in hat notation ('^c')
[-]echo echo input characters
* [-]echoctl same as [-]ctlecho
[-]echoe same as [-]crterase
[-]echok echo a newline after a kill character
* [-]echoke same as [-]crtkill
[-]echonl echo newline even if not echoing other characters
* [-]flusho discard output
[-]icanon enable special characters: erase, kill, werase, rprnt
[-]iexten enable non-POSIX special characters
[-]isig enable interrupt, quit, and suspend special characters
[-]noflsh disable flushing after interrupt and quit special characters
* [-]tostop stop background jobs that try to write to the terminal
I therefore tried to specify these options in fortran90 source code like this.
call system ( '/usr/bin/stty -echo' )
read ( * , '(a)' ) mybuffer
call system ( '/usr/bin/stty echo' )
but none of them seemed to work.
Someone please explain me how to disable echo back from arrow keys.