1

メソッドには 2 つのバージョンがありますが、両方で同じ問題が発生します。

バージョン 1

def read_char
  $stdin.raw!
  input = $stdin.getc.chr
  if input == "\e" then
     input << $stdin.read_nonblock(3) rescue nil
     input << $stdin.read_nonblock(2) rescue nil
  end
ensure
  $stdin.cooked!
  return input
 end

バージョン 2

def read_char
  system("stty raw -echo") 
  input = $stdin.getc.chr
  if input == "\e" then
    input << $stdin.read_nonblock(3) rescue nil
    input << $stdin.read_nonblock(2) rescue nil
  end
ensure
  system("stty -raw echo")  
  return input
end

私は両方に同じ問題を抱えています。具体的には、Kernel#system コマンドの動作を変更します。

例として:

system("irb")
c=read_char
system("irb")

システムの動作が変更されたことは簡単にわかります。2 番目のバージョンでは、inout が tty から引き出されていません。

これは、任意のキーを押した場合には発生しないことに注意してください。カーソル キーなどのエスケープ シーケンスに変換されるキーだけです。

では、これはどのように修復されるのでしょうか。

PS

2 番目の場所で system("strace -o logfile irb") を実行し、読み取りステートメントを確認することを誰かが提案しました。代わりに、両方の irbs をたどって比較しました。読み取りステートメントは、最後のものを除いてすべて同じであり、すべてそうでした。最終的な読み取りは異なって見えました:

1st system: read(0, "1\n", 1024)                    = 2
2nd system: read(0, 0x7ff805a53000, 1024)           = -1 EAGAIN (Resource temporarily unavailable)

0x7ff805a53000 is the address of a memory mapped region.

PPS

Linuxシステムでこれを行っています。

4

0 に答える 0