Sha256: fde4894b5ca26f8d5d6774daa2514b5181d90e4611d340d89f14b8c9934d12c4
Contents?: true
Size: 1.05 KB
Versions: 6
Compression:
Stored size: 1.05 KB
Contents
# frozen_string_literal: true module Byebug # # Interface class for standard byebug use. # class LocalInterface < Interface EOF_ALIAS = 'continue'.freeze def initialize super() @input = STDIN @output = STDOUT @error = STDERR end # # Reads a single line of input using Readline. If Ctrl-D is pressed, it # returns "continue", meaning that program's execution will go on. # # @param prompt Prompt to be displayed. # def readline(prompt) with_repl_like_sigint do Readline.readline(prompt, false) || EOF_ALIAS end end # # Yields the block handling Ctrl-C the following way: if pressed while # waiting for input, the line is reset to only the prompt and we ask for # input again. # # @note Any external 'INT' traps are overriden during this method. # def with_repl_like_sigint orig_handler = trap('INT') { raise Interrupt } yield rescue Interrupt puts('^C') retry ensure trap('INT', orig_handler) end end end
Version data entries
6 entries across 6 versions & 1 rubygems