Module: PiotrbCliUtils::CmdLoop
- Defined in:
- lib/piotrb_cli_utils/cmd_loop.rb
Instance Method Summary collapse
Instance Method Details
#run_cmd_loop(prompt = '=> ') ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/piotrb_cli_utils/cmd_loop.rb', line 5 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 line = reader.read_line(prompt) line.strip! yield(line) end end || :stopped end |