Sha256: c4d271c5721977d3b575cf503cf0332840f80955fb1d1408704ef334b705d2c9

Contents?: true

Size: 1.58 KB

Versions: 6810

Compression:

Stored size: 1.58 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 { without_readline_completion { 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

    #
    # Disable any Readline completion procs.
    #
    # Other gems, for example, IRB could've installed completion procs that are
    # dependent on them being loaded. Disable those while byebug is the REPL
    # making use of Readline.
    #
    def without_readline_completion
      orig_completion = Readline.completion_proc
      return yield unless orig_completion

      begin
        Readline.completion_proc = ->(_) { nil }
        yield
      ensure
        Readline.completion_proc = orig_completion
      end
    end
  end
end

Version data entries

6,810 entries across 6,807 versions & 29 rubygems

Version Path
ory-client-1.16.4 vendor/bundle/ruby/3.1.0/gems/byebug-11.1.3/lib/byebug/interfaces/local_interface.rb
cybrid_api_id_ruby-0.123.179 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/interfaces/local_interface.rb
cybrid_api_organization_ruby-0.123.179 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/interfaces/local_interface.rb
cybrid_api_organization_ruby-0.123.177 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/interfaces/local_interface.rb
cybrid_api_id_ruby-0.123.177 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/interfaces/local_interface.rb
cybrid_api_organization_ruby-0.123.176 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/interfaces/local_interface.rb
cybrid_api_id_ruby-0.123.176 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/interfaces/local_interface.rb
cybrid_api_organization_ruby-0.123.175 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/interfaces/local_interface.rb
cybrid_api_id_ruby-0.123.175 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/interfaces/local_interface.rb
cybrid_api_id_ruby-0.123.174 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/interfaces/local_interface.rb
cybrid_api_organization_ruby-0.123.174 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/interfaces/local_interface.rb
cybrid_api_id_ruby-0.123.173 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/interfaces/local_interface.rb
cybrid_api_organization_ruby-0.123.173 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/interfaces/local_interface.rb
ory-client-1.16.3 vendor/bundle/ruby/3.1.0/gems/byebug-11.1.3/lib/byebug/interfaces/local_interface.rb
cybrid_api_organization_ruby-0.123.172 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/interfaces/local_interface.rb
cybrid_api_id_ruby-0.123.172 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/interfaces/local_interface.rb
cybrid_api_id_ruby-0.123.171 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/interfaces/local_interface.rb
cybrid_api_organization_ruby-0.123.171 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/interfaces/local_interface.rb
cybrid_api_id_ruby-0.123.170 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/interfaces/local_interface.rb
cybrid_api_organization_ruby-0.123.170 vendor/bundle/ruby/3.3.0/gems/byebug-11.1.3/lib/byebug/interfaces/local_interface.rb