Module: Byebug::Helpers::ToggleHelper

Overview

Utilities to assist breakpoint/display enabling/disabling.

Instance Method Summary collapse

Methods included from ParseHelper

#get_int, #parse_steps, #syntax_valid?

Instance Method Details

#enable_disable_breakpoints(is_enable, args) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/byebug/helpers/toggle.rb', line 11

def enable_disable_breakpoints(is_enable, args)
  return errmsg(pr('toggle.errors.no_breakpoints')) if Breakpoint.none?

  all_breakpoints = Byebug.breakpoints.sort_by(&:id)
  if args.nil?
    selected_breakpoints = all_breakpoints
  else
    selected_ids = []
    args.split(/ +/).each do |pos|
      last_id = all_breakpoints.last.id
      pos, err = get_int(pos, "#{is_enable} breakpoints", 1, last_id)
      return errmsg(err) unless pos

      selected_ids << pos
    end
    selected_breakpoints = all_breakpoints.select do |b|
      selected_ids.include?(b.id)
    end
  end

  selected_breakpoints.each do |b|
    enabled = ('enable' == is_enable)
    if enabled && !syntax_valid?(b.expr)
      return errmsg(pr('toggle.errors.expression', expr: b.expr))
    end

    b.enabled = enabled
  end
end

#enable_disable_display(is_enable, args) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/byebug/helpers/toggle.rb', line 41

def enable_disable_display(is_enable, args)
  return errmsg(pr('toggle.errors.no_display')) if 0 == n_displays

  selected_displays = args ? args.split(/ +/) : [1..n_displays + 1]

  selected_displays.each do |pos|
    pos, err = get_int(pos, "#{is_enable} display", 1, n_displays)
    return errmsg(err) unless err.nil?

    Byebug.displays[pos - 1][0] = ('enable' == is_enable)
  end
end