Sha256: 1a432b159b1329ac7734f3b4b7d7cdba48569c0aa6d5d98ab6bfd2147d679346

Contents?: true

Size: 480 Bytes

Versions: 9

Compression:

Stored size: 480 Bytes

Contents

class IO
  def get_password(out: $stderr)
    result = ''
    noecho do
      while char = getch
        case char
        when /[\r\n]/
          break
        when /[\e\b\x7f]/
          result.replace result.chop
          out.write "\b \b"
        when /[\x3\x1A]/ # interrupt, background
          out.write "\nOk, aborting\n"
          abort
        else
          result << char
          out.write '*'
        end
      end
    end
    out.write "\n"
    result
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
donjon-2.0.1 lib/core_ext/io_get_password.rb
donjon-2.0.0 lib/core_ext/io_get_password.rb
donjon-1.0.1 lib/core_ext/io_get_password.rb
donjon-1.0.0 lib/core_ext/io_get_password.rb
donjon-0.0.5 lib/core_ext/io_get_password.rb
donjon-0.0.4 lib/core_ext/io_get_password.rb
donjon-0.0.3 lib/core_ext/io_get_password.rb
donjon-0.0.2 lib/core_ext/io_get_password.rb
donjon-0.0.1 lib/core_ext/io_get_password.rb