【问题标题】:STDIN.getpass does not always show the key icon in the terminalSTDIN.getpass 并不总是在终端中显示钥匙图标
【发布时间】:2021-12-19 18:17:01
【问题描述】:

我如何确保每次拨打STDIN.getpass 时始终显示钥匙图标(示例请参见img)?问题是间歇性的,有时我得到图标,有时我没有。我找不到可靠的重现步骤。

我的代码目前的样子:

  $stdout.flush
  # to hide the password while being typed in the terminal
  STDIN.getpass
  • 我认为$stdout.flush 可以解决我的问题,但它没有。
  • STDIN.getpass 正在返回,因此它没有分配给任何变量。

【问题讨论】:

  • 通过提示时只看到钥匙图标:STDIN.getpass "Enter password:"

标签: ruby terminal io passwords credentials


【解决方案1】:

他们的钥匙图标本身与 STDIN.getpass 功能没有太大关系,这很简单,你可以在这里看到:

https://github.com/ruby/io-console/blob/master/lib/io/console/ffi/common.rb#L9-L21

noecho 块只是将tty_mode 设置为noecho(参见https://github.com/ruby/ruby/blob/d92f09a5eea009fa28cd046e9d0eb698e3d94c5c/ext/io/console/console.c#L602)

所以,我认为这个问题实际上更好:“当 tty_mode 设置为 noecho 时,my operating system 上的 Terminal program 怎么不总是显示一个钥匙图标。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-12
    • 2018-03-17
    • 2020-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多