class DEBUGGER__::Console

Constants

FH
SIGWINCH_SUPPORTED

Public Class Methods

new() click to toggle source
# File debug-1.4.0/lib/debug/console.rb, line 170
def initialize
  @init_history_lines = nil
end

Public Instance Methods

deactivate() click to toggle source
# File debug-1.4.0/lib/debug/console.rb, line 180
def deactivate
  if history && @init_history_lines
    added_records = history.to_a[@init_history_lines .. -1]
    path = history_file
    max = CONFIG[:save_history] || 10_000

    if !added_records.empty? && !path.empty?
      orig_records = read_history_file
      open(history_file, 'w'){|f|
        (orig_records + added_records).last(max).each{|line|
          if !line.start_with?(FH) && !line.strip.empty?
            f.puts line.strip
          end
        }
      }
    end
  end
end
get_command(line) click to toggle source
# File debug-1.4.0/lib/debug/console.rb, line 90
        def get_command line
  case line.chomp
  when /\A(\s*[a-z]+)(\s.*)?\z$/
    return $1, $2
  else
    line.chomp
  end
end
history() click to toggle source
# File debug-1.4.0/lib/debug/console.rb, line 105
def history
  Reline::HISTORY
end
history_file() click to toggle source
# File debug-1.4.0/lib/debug/console.rb, line 155
def history_file
  CONFIG[:history_file] || File.expand_path("~/.rdbg_history")
end
load_history() click to toggle source
# File debug-1.4.0/lib/debug/console.rb, line 199
def load_history
  read_history_file.count{|line|
    line.strip!
    history << line unless line.empty?
  }
end
load_history_if_not_loaded() click to toggle source
# File debug-1.4.0/lib/debug/console.rb, line 174
def load_history_if_not_loaded
  return if @init_history_lines

  @init_history_lines = load_history
end
read_history_file() click to toggle source
# File debug-1.4.0/lib/debug/console.rb, line 161
def read_history_file
  if history && File.exist?(path = history_file)
    f = (['', 'DAI-', 'CHU-', 'SHO-'].map{|e| e+'KICHI'}+['KYO']).sample
    ["#{FH}#{f}".dup] + File.readlines(path)
  else
    []
  end
end
readline(prompt) click to toggle source
# File debug-1.4.0/lib/debug/console.rb, line 99
def readline prompt
  readline_setup prompt do
    Reline.readmultiline(prompt, true){ true }
  end
end
readline_setup(prompt) { || ... } click to toggle source
# File debug-1.4.0/lib/debug/console.rb, line 33
def readline_setup prompt
  load_history_if_not_loaded
  commands = DEBUGGER__.commands

  prev_completion_proc = Reline.completion_proc
  prev_output_modifier_proc = Reline.output_modifier_proc
  prev_prompt_proc = Reline.prompt_proc

  Reline.prompt_proc = nil

  Reline.completion_proc = -> given do
    buff = Reline.line_buffer
    Reline.completion_append_character= ' '

    if /\s/ =~ buff # second parameters
      given = File.expand_path(given + 'a').sub(/a\z/, '')
      files = Dir.glob(given + '*')
      if files.size == 1 && File.directory?(files.first)
        Reline.completion_append_character= '/'
      end
      files
    else
      commands.keys.grep(/\A#{given}/)
    end
  end

  Reline.output_modifier_proc = -> buff, **kw do
    c, rest = get_command buff

    case
    when commands.keys.include?(c = c.strip)
      # [:DIM, :CYAN, :BLUE, :CLEAR, :UNDERLINE, :REVERSE, :RED, :GREEN, :MAGENTA, :BOLD, :YELLOW]
      cmd = colorize(c.strip, [:CYAN, :UNDERLINE])

      if commands[c] == c
        rprompt = colorize("    # command", [:DIM])
      else
        rprompt = colorize("    # #{commands[c]} command", [:DIM])
      end

      rest = (rest ? colorize_code(rest) : '') + rprompt
      cmd + rest
    when !rest && /\A\s*[a-z]*\z/ =~ c
      buff
    else
      colorize_code(buff.chomp) + colorize("    # ruby", [:DIM])
    end
  end

  yield

ensure
  Reline.completion_proc = prev_completion_proc
  Reline.output_modifier_proc = prev_output_modifier_proc
  Reline.prompt_proc = prev_prompt_proc
end