Class: RubyJard::Screens::SourceScreen

Inherits:
RubyJard::Screen show all
Defined in:
lib/ruby_jard/screens/source_screen.rb

Overview

Display source code of current stopping line and surrounding lines

Instance Attribute Summary

Attributes inherited from RubyJard::Screen

#cursor, #layout, #rows, #selected, #window

Instance Method Summary collapse

Methods inherited from RubyJard::Screen

#click, #move_down, #move_up, #page_down, #page_up

Constructor Details

#initialize(*args) ⇒ SourceScreen

Returns a new instance of SourceScreen.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ruby_jard/screens/source_screen.rb', line 8

def initialize(*args)
  super
  @frame_file = @session.current_frame&.frame_file
  @frame_line = @session.current_frame&.frame_line

  if !@frame_file.nil? && !@frame_line.nil?
    @path_decorator = RubyJard::Decorators::PathDecorator.new
    @loc_decorator = RubyJard::Decorators::LocDecorator.new
    @source_decorator = RubyJard::Decorators::SourceDecorator.new(@frame_file, @frame_line, @layout.height)
  end

  @selected = 0
end

Instance Method Details

#buildObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ruby_jard/screens/source_screen.rb', line 29

def build
  return 'Source' if @frame_file.nil? || @frame_line.nil?

  # TODO: screen now supports window.
  codes = @source_decorator.codes
  @rows = codes.map.with_index do |loc, index|
    lineno = @source_decorator.window_start + index
    RubyJard::Row.new(
      line_limit: 3,
      columns: [
        RubyJard::Column.new(
          spans: [
            span_mark(lineno),
            span_lineno(lineno)
          ]
        ),
        RubyJard::Column.new(
          word_wrap: RubyJard::Column::WORD_WRAP_BREAK_WORD,
          spans: loc_spans(loc)
        )
      ]
    )
  end
end

#titleObject



22
23
24
25
26
27
# File 'lib/ruby_jard/screens/source_screen.rb', line 22

def title
  return 'Source' if @frame_file.nil? || @frame_line.nil?

  _, path_label = @path_decorator.decorate(@frame_file, @frame_line)
  ['Source', path_label]
end