绝对必须有更好的方法来做到这一点。
temp_file ||= Tempfile.new()
system("stty -echo; tput u7; read -d R x; stty echo; echo ${x#??} > #{temp_file.path}")
temp_file.gets.chomp.split(';').map(&:to_i)
基本上,我在子进程中运行这个问题的 bash 脚本,然后从重定向文件中读取输出。
不使用 C 或任何 gem(stdlib 可以)有什么更好的方法来做到这一点?交叉兼容性不是很重要。