Module: PiotrbCliUtils::CmdLoop
- Defined in:
- lib/piotrb_cli_utils/cmd_loop.rb
Instance Method Summary collapse
Instance Method Details
#run_cmd_loop(prompt = '=> ') ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/piotrb_cli_utils/cmd_loop.rb', line 8 def run_cmd_loop(prompt = '=> ') reader = TTY::Reader.new(interrupt: :noop) reader.on(:keyctrl_c, :keyescape) do return :abort end reader.on(:keyctrl_d) do return :eof end catch(:stop) do loop do actual_prompt = prompt.respond_to?(:call) ? prompt.call : prompt line = reader.read_line(actual_prompt) line.strip! yield(line) end end || :stopped end |