0

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.

Charles
  • 1
  • 2
  • 1
    You can't disable arrow keys. Either the application reading the input knows how to interpret them (like `bash` does) or they just get echoed as raw escape sequences. – Barmar Sep 20 '16 at 17:48
  • 1
    `stty -echo` turns off **all** echoing, not just escape sequences. – Barmar Sep 20 '16 at 17:48
  • Thank you for your comment. You are right. I mean, I want to prevent echoing only from these escape sequences. I am looking for such options or some other ways if exist. – Charles Sep 20 '16 at 18:23
  • You should search for information about reading from the terminal in raw mode in Fortran. – Barmar Sep 20 '16 at 19:12
  • I changed your tags. Your question is about Fortran, not bash. While a program is running, the shell is not involved. All it does is start the program, it has nothing to do with I/O to the program. – Barmar Sep 20 '16 at 19:13

0 Answers0