Class: Clack::Prompts::Password

Inherits:
Core::Prompt show all
Defined in:
lib/clack/prompts/password.rb

Overview

Password input prompt with masked display.

Displays a mask character for each input character, hiding the actual password. Supports backspace but not cursor movement (for security).

Examples:

Basic usage

secret = Clack.password(message: "Enter your API key")

With custom mask

secret = Clack.password(message: "Password", mask: "*")

Constant Summary

Constants inherited from Core::Prompt

Core::Prompt::MIN_TERMINAL_WIDTH

Instance Attribute Summary

Attributes inherited from Core::Prompt

#error_message, #state, #value, #warning_message

Instance Method Summary collapse

Methods inherited from Core::Prompt

flush_resize, register, #request_redraw, #run, setup_signal_handler, unregister

Constructor Details

#initialize(message:, mask: nil, **opts) ⇒ Password

Returns a new instance of Password.

Parameters:

  • message (String)

    the prompt message

  • mask (String, nil) (defaults to: nil)

    character to display (default: “▪”)

  • opts (Hash)

    a customizable set of options

Options Hash (**opts):

  • :validate (Proc, nil)

    validation proc returning error string or nil

  • additional (Hash)

    options passed to Core::Prompt



21
22
23
24
25
# File 'lib/clack/prompts/password.rb', line 21

def initialize(message:, mask: nil, **opts)
  super(message:, **opts)
  @mask = mask || Symbols::S_PASSWORD_MASK
  @value = ""
end