Class: Pikuri::Tool::Confirmer::Terminal

Inherits:
Pikuri::Tool::Confirmer show all
Defined in:
lib/pikuri/tool/confirmer.rb

Overview

Stdin/stdout implementation: prints prompt on its own line (a leading puts guarantees separation from any streamed output the Terminal listener may have produced just above), reads one line from $stdin, parses it strictly:

  • “y” / “yes” (case-insensitive, stripped) → true

  • “n” / “no”false

  • EOF / Ctrl+D (gets returns nil) → false, deliberate abort

  • anything else (blank, typo, “maybe”) → re-prompt with a short “Please answer y or n: ” line and loop

No retry cap; EOF eventually breaks adversarial input.

Constant Summary

Constants inherited from Pikuri::Tool::Confirmer

AUTO_APPROVE, TERMINAL

Instance Method Summary collapse

Instance Method Details

#confirm?(prompt:) ⇒ Boolean

Parameters:

  • prompt (String)

Returns:

  • (Boolean)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/pikuri/tool/confirmer.rb', line 58

def confirm?(prompt:)
  puts
  puts prompt
  $stdout.flush
  loop do
    line = $stdin.gets
    return false if line.nil?

    answer = line.strip.downcase
    return true  if answer == 'y' || answer == 'yes'
    return false if answer == 'n' || answer == 'no'

    print 'Please answer y or n: '
    $stdout.flush
  end
end