我在 Windows 7 64 位操作系统上的 Cygwin mintty 终端中使用 Bash(version 4.3.46(6)) shell,并尝试使用 Fortran 90 制作简单的 CUI 应用程序。我的简化源代码是这样的。
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
其中第 6 行的 write 语句是可选的(仅用于检查)。
这似乎适用于可打印字符。我观察到来自 stdin 的字符串在终端上回显,并将字符串保存到 variablemybuffer
中。
但是当我输入箭头键时,会发生同样的回声,这一次是没有希望的。
在我的终端中,我已经检查(使用此源代码)向上箭头键代码\x1B\x5B\x41
是\e[A
.
然后我认为可能是stty((GNU coreutils)8.25)的问题,所以我尝试了
stty --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
因此,我尝试像这样在 fortran90 源代码中指定这些选项。
call system ( '/usr/bin/stty -echo' )
read ( * , '(a)' ) mybuffer
call system ( '/usr/bin/stty echo' )
但它们似乎都不起作用。
有人请解释我如何禁用箭头键的回声。