Sha256: 740d3ec6eb043f1b5cc898a1254aa385aceee090055acbdd9a1169bb72f28493

Contents?: true

Size: 876 Bytes

Versions: 13

Compression:

Stored size: 876 Bytes

Contents

# frozen_string_literal: true

require 'io/console'

# Awskeyring Module,
module Awskeyring
  # Input methods for Awskeyring
  module Input
    # Read a secret in without echoing the characters
    #
    # @param [String] prompt text to prompt user with.
    def self.read_secret(prompt)
      $stdout.print(prompt)
      hide_input
    end

    private_class_method def self.hide_input # rubocop:disable Metrics/MethodLength
      password = +''
      loop do
        character = $stdin.getch
        break unless character

        if ["\n", "\r"].include? character
          puts ''
          break
        elsif ["\b", "\u007f"].include? character
          password.chop!
          print "\b\e[P"
        elsif character == "\u0003"
          exit 1
        else
          print '*'
          password << character
        end
      end
      password
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
awskeyring-1.6.0 lib/awskeyring/input.rb
awskeyring-1.5.0 lib/awskeyring/input.rb
awskeyring-1.4.0 lib/awskeyring/input.rb
awskeyring-1.3.3 lib/awskeyring/input.rb
awskeyring-1.3.2 lib/awskeyring/input.rb
awskeyring-1.3.1 lib/awskeyring/input.rb
awskeyring-1.3.0 lib/awskeyring/input.rb
awskeyring-1.2.0 lib/awskeyring/input.rb
awskeyring-1.1.2 lib/awskeyring/input.rb
awskeyring-1.1.1 lib/awskeyring/input.rb
awskeyring-1.1.0 lib/awskeyring/input.rb
awskeyring-1.0.2 lib/awskeyring/input.rb
awskeyring-1.0.1 lib/awskeyring/input.rb