立即从控制台获取单个字符 [英] Get single char from console immediately

查看:34
本文介绍了立即从控制台获取单个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在提供后从 STDIN 获取每个字符(无需等待返回键)?

Is it possible to get each char from STDIN once it is provided (without waiting for return key)?

推荐答案

是的,有很多方法可以做到这一点,除了 gems 之外,您还可以通过 gems 直接操作 terminfo,用于 termios、ncurses 或 stty 程序.

Yes, there are numerous ways to do this, and besides gems you can directly manipulate with terminfo through gems for termios, ncurses or stty program.

tty_param = `stty -g`
system 'stty raw'

a = IO.read '/dev/stdin', 1

system "stty #{tty_param}"

print a

这篇关于立即从控制台获取单个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆