Module: ExAequo::Ui::Prompts

Extended by:
Colorize, Prompts
Included in:
Prompts
Defined in:
lib/ex_aequo/ui/prompts.rb

Instance Method Summary collapse

Instance Method Details

#prompt_ch(text: nil, chars:) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ex_aequo/ui/prompts.rb', line 10

def prompt_ch(text: nil, chars:)
  loop do
    $stdout.print(text || _mk_text(chars))
    $stdout.flush
    case _member($stdin.getch, chars)
    in {ok: true, ch:}
      return ch
    in {ok: false, ch:}
      $stdout.puts(colorize("<red>ERROR$: Illegal char entered -> #{ch.inspect}"))
    end
  end
end