从 stdin 读取单个字符而不按回车

Read a single char from stdin without pressing enter

如何在不按 enter / return 的情况下从控制台读取单个字符?

在 ruby 中,我会使用:

require 'io/console'
input = STDIN.getch

试试这个:

char = STDIN.raw &.read_char
p char