Sha256: 7fea33b99b8456d075c470732ffe24bd39d1ad374efb3820b65e0cc34dadf528

Contents?: true

Size: 875 Bytes

Versions: 1

Compression:

Stored size: 875 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

1 entries across 1 versions & 1 rubygems

Version Path
awskeyring-1.0.0 lib/awskeyring/input.rb