class Byebug::Command

def command_exists?(command)

def command_exists?(command)
  ENV['PATH'].split(File::PATH_SEPARATOR).any? {
    |d| File.exists? File.join(d, command) }
end

def commands

def commands
  @commands ||= []
end

def confirm(msg)

def confirm(msg)
  @state.confirm(msg) == 'y'
end

def debug_eval(str, b = get_binding)

def debug_eval(str, b = get_binding)
  begin
    eval(str, b)
  rescue StandardError, ScriptError => e
    if Command.settings[:stack_trace_on_error]
      at = eval("Thread.current.backtrace_locations(1)", b)
      print "#{at.shift}: #{e.class} Exception(#{e.message})\n"
      for i in at
        print "\tfrom #{i}\n"
      end
    else
      print "#{e.class} Exception: #{e.message}\n"
    end
    nil
  end
end

def debug_silent_eval(str, b = get_binding)

def debug_silent_eval(str, b = get_binding)
  begin
    eval(str, b)
  rescue StandardError, ScriptError
    nil
  end
end

def debug_warning_eval(str, b = get_binding)

def debug_warning_eval(str, b = get_binding)
  begin
    eval(str, b)
  rescue StandardError, ScriptError => e
    print "#{e.class} Exception: #{e.message}\n"
  end
end

def find(subcmds, param)

def find(subcmds, param)
  param.downcase!
  for try_subcmd in subcmds do
    if (param.size >= try_subcmd.min) and
        (try_subcmd.name[0..param.size-1] == param)
      return try_subcmd
    end
  end
  return nil
end

def format_subcmd(subcmd_name)

def format_subcmd(subcmd_name)
  subcmd = find(self::Subcommands, subcmd_name)
  return "Invalid \"#{names.join("|")}\" " \
         "subcommand \"#{args[1]}\"." unless subcmd
  return "#{subcmd.short_help}.\n" \
         "#{subcmd.long_help || '' }"
end

def format_subcmds

def format_subcmds
  cmd_name = names.join("|")
  s = "\n"                                     \
      "--\n"                                   \
      "List of \"#{cmd_name}\" subcommands:\n" \
      "--\n"
  width = self::Subcommands.map(&:name).max_by(&:size).size
  for subcmd in self::Subcommands do
    s += sprintf \
      "%s %-#{width}s -- %s\n", cmd_name, subcmd.name, subcmd.short_help
  end
  return s
end

def get_binding pos = @state.frame_pos

def get_binding pos = @state.frame_pos
  @state.context ? @state.context.frame_binding(pos) : TOPLEVEL_BINDING
end

def get_context(thnum)

def get_context(thnum)
  Byebug.contexts.find {|c| c.thnum == thnum}
end

def help(args)

def help(args)
  output = description.gsub(/^ +/, '')
  if defined? self::Subcommands
    return output += format_subcmds unless args and args[1]
    output += format_subcmd(args[1])
  end
  return output
end

def inherited(klass)

def inherited(klass)
  DEF_OPTIONS.each do |o, v|
    klass.options[o] = v if klass.options[o].nil?
  end
  commands << klass
end

def initialize(state)

def initialize(state)
  @state = state
end

def load_commands

def load_commands
  Dir[File.join(File.dirname(__FILE__), 'commands', '*')].each {
    |file| require file }
  Byebug.constants.grep(/Functions$/).map {
    |name| Byebug.const_get(name) }.each { |mod| include mod }
end

def match(input)

def match(input)
  @match = regexp.match(input)
end

def method_missing(meth, *args, &block)

def method_missing(meth, *args, &block)
  if meth.to_s =~ /^(.+?)=$/
    @options[$1.intern] = args.first
  else
    if @options.has_key?(meth)
      @options[meth]
    else
      super
    end
  end
end

def options

def options
  @options ||= {}
end

def register_setting_get(name, &block)

def register_setting_get(name, &block)
  settings_map[name] ||= {}
  settings_map[name][:getter] = block
end

def register_setting_set(name, &block)

def register_setting_set(name, &block)
  settings_map[name] ||= {}
  settings_map[name][:setter] = block
end

def register_setting_var(name, default)

def register_setting_var(name, default)
  var_name = "@@#{name}"
  class_variable_set(var_name, default)
  register_setting_get(name) { class_variable_get(var_name) }
  register_setting_set(name) { |value| class_variable_set(var_name, value) }
end

def settings

def settings
  unless defined? @settings and @settings
    @settings = Object.new
    map = settings_map
    c = class << @settings; self end
    c.send(:define_method, :[]) do |name|
      raise "No such setting #{name}" unless map.has_key?(name)
      map[name][:getter].call
    end
    c.send(:define_method, :[]=) do |name, value|
      raise "No such setting #{name}" unless map.has_key?(name)
      map[name][:setter].call(value)
    end
  end
  @settings
end

def settings_map

def settings_map
  @@settings_map ||= {}
end

def terminal_width

def terminal_width
  if ENV['COLUMNS'] =~ /^\d+$/
    ENV['COLUMNS'].to_i
  elsif STDIN.tty? && command_exists?('stty')
    `stty size`.scan(/\d+/)[1].to_i
  else
    nil
  end
end