Sha256: 709a97b6d4fa3f59c8033df7a98fc41184cb96abdb995430b63e0df1b7ecabb0

Contents?: true

Size: 1.01 KB

Versions: 21

Compression:

Stored size: 1.01 KB

Contents

require 'tempfile'

class Thor
  module Shell
    module Password
      if RUBY_PLATFORM =~ /mswin32|mingw32/

        def ask_passwordly(statement, color = nil)
          say("#{statement} ", color)

          require "Win32API"
          char = nil
          password = ''

          while char = Win32API.new("crtdll", "_getch", [ ], "L").Call do
            break if char == 10 || char == 13 # received carriage return or newline
            if char == 127 || char == 8 # backspace and delete
              password.slice!(-1, 1)
            else
              # windows might throw a -1 at us so make sure to handle RangeError
              (password << char.chr) rescue RangeError
            end
          end
          puts
          return password
        end

      else

        def ask_passwordly(statement, color = nil)
          system "stty -echo"
          password = ask(statement, color)
          puts
          return password
        ensure
          system "stty echo"
        end
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
pullentity-client-0.3.9 lib/pullentity-client/thor/shell/password.rb
pullentity-client-0.3.8 lib/pullentity-client/thor/shell/password.rb
pullentity-client-0.3.7 lib/pullentity-client/thor/shell/password.rb
pullentity-client-0.3.6 lib/pullentity-client/thor/shell/password.rb
pullentity-client-0.3.5 lib/pullentity-client/thor/shell/password.rb
pullentity-client-0.3.4 lib/pullentity-client/thor/shell/password.rb
pullentity-client-0.3.3 lib/pullentity-client/thor/shell/password.rb
pullentity-client-0.3.2 lib/pullentity-client/thor/shell/password.rb
pullentity-client-0.3.1 lib/pullentity-client/thor/shell/password.rb
pullentity-client-0.3.0 lib/pullentity-client/thor/shell/password.rb
pullentity-client-0.1.3 lib/pullentity-client/thor/shell/password.rb
pullentity-client-0.1.2 lib/pullentity-client/thor/shell/password.rb
pullentity-client-0.1.1 lib/pullentity-client/thor/shell/password.rb
pullentity-client-0.1.0 lib/pullentity-client/thor/shell/password.rb
pullentity-client-0.0.9 lib/pullentity-client/thor/shell/password.rb
pullentity-client-0.0.8 lib/pullentity-client/thor/shell/password.rb
pullentity-client-0.0.7 lib/pullentity-client/thor/shell/password.rb
pullentity-client-0.0.6 lib/pullentity-client/thor/shell/password.rb
pullentity-client-0.0.4 lib/pullentity-client/thor/shell/password.rb
pullentity-client-0.0.3 lib/pullentity-client/thor/shell/password.rb