Class: Clack::Prompts::Confirm

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

Overview

Yes/No confirmation prompt.

Displays a toggle between two options. Navigate with arrow keys, j/k, or press y/n to select directly.

Examples:

Basic usage

proceed = Clack.confirm(message: "Continue?")

With custom labels

deploy = Clack.confirm(
  message: "Deploy to production?",
  active: "Yes, ship it!",
  inactive: "No, abort",
  initial_value: false
)

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:, active: "Yes", inactive: "No", initial_value: true, **opts) ⇒ Confirm

Returns a new instance of Confirm.

Parameters:

  • message (String)

    the prompt message

  • active (String) (defaults to: "Yes")

    label for the “yes” option (default: “Yes”)

  • inactive (String) (defaults to: "No")

    label for the “no” option (default: “No”)

  • initial_value (Boolean) (defaults to: true)

    initial selection (default: true)

  • opts (Hash)

    additional options passed to Core::Prompt



27
28
29
30
31
32
# File 'lib/clack/prompts/confirm.rb', line 27

def initialize(message:, active: "Yes", inactive: "No", initial_value: true, **opts)
  super(message:, **opts)
  @active_label = active
  @inactive_label = inactive
  @value = initial_value
end