Sha256: 776851fa8efaf9dc5644fdf0f0d4c43101fcc15903ab2c1ba1a08ed4b9387c5c

Contents?: true

Size: 1.03 KB

Versions: 11

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Byebug
  #
  # Interface class for standard byebug use.
  #
  class LocalInterface < Interface
    EOF_ALIAS = "continue"

    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 { Readline.readline(prompt) || EOF_ALIAS }
    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

11 entries across 10 versions & 6 rubygems

Version Path
talon_one-2.0.0 vendor/bundle/ruby/2.7.0/gems/byebug-11.1.1/lib/byebug/interfaces/local_interface.rb
talon_one-2.0.0 vendor/bundle/ruby/2.3.0/gems/byebug-11.0.1/lib/byebug/interfaces/local_interface.rb
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/byebug-11.1.1/lib/byebug/interfaces/local_interface.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/byebug-11.1.1/lib/byebug/interfaces/local_interface.rb
byebug-11.1.1 lib/byebug/interfaces/local_interface.rb
byebug-11.1.0 lib/byebug/interfaces/local_interface.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/byebug-11.0.1/lib/byebug/interfaces/local_interface.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/byebug-11.0.1/lib/byebug/interfaces/local_interface.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/byebug-11.0.1/lib/byebug/interfaces/local_interface.rb
byebug-11.0.1 lib/byebug/interfaces/local_interface.rb
byebug-11.0.0 lib/byebug/interfaces/local_interface.rb