Class: Byebug::ListCommand

Inherits:
Command
  • Object
show all
Includes:
Helpers::FileHelper, Helpers::ParseHelper
Defined in:
lib/byebug/commands/list.rb

Overview

List parts of the source code.

Instance Method Summary collapse

Methods included from Helpers::ParseHelper

#get_int, #parse_steps, #syntax_valid?, #without_stderr

Methods included from Helpers::FileHelper

#get_line, #get_lines, #n_lines, #normalize

Methods inherited from Command

#help, #initialize, #match, subcommands, to_name

Methods included from Helpers::StringHelper

#camelize, #prettify

Constructor Details

This class inherits a constructor from Byebug::Command

Instance Method Details

#descriptionObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/byebug/commands/list.rb', line 31

def description
  <<-EOD
    l[ist][[-=]][ nn-mm]

    Lists lines of code forward from current line or from the place where
    code was last listed. If "list-" is specified, lists backwards instead.
    If "list=" is specified, lists from current line regardless of where
    code was last listed. A line range can also be specified to list
    specific sections of code.
  EOD
end

#executeObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/byebug/commands/list.rb', line 17

def execute
  exist = File.exist?(@state.file)
  return errmsg "No sourcefile available for #{@state.file}\n" unless exist

  @match ||= match('list')
  max_lines = n_lines(@state.file)
  b, e = range(@match[2], max_lines)
  return errmsg('Invalid line range') unless valid_range?(b, e, max_lines)

  display_lines(b, e)

  @state.prev_line = b
end

#regexpObject



13
14
15
# File 'lib/byebug/commands/list.rb', line 13

def regexp
  /^\s* l(?:ist)? (?:\s*([-=])|\s+(\S+))? \s*$/x
end