Class: Vedeu::Output::Viewport Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/vedeu/output/viewport.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A Viewport is the visible part of the content within an interface.

When a buffer has more lines than the defined height, or more columns than the defined width of the interface, this class provides ‘scrolling’ via the cursor’s position.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view) ⇒ Vedeu::Output::Viewport

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns an instance of Vedeu::Output::Viewport.

Parameters:



41
42
43
# File 'lib/vedeu/output/viewport.rb', line 41

def initialize(view)
  @view = view
end

Instance Attribute Details

#viewVedeu::Views::View (readonly, protected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



64
65
66
# File 'lib/vedeu/output/viewport.rb', line 64

def view
  @view
end

Class Method Details

.render(view) ⇒ Array<Array<String>>|NilClass

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

Returns:

  • (Array<Array<String>>|NilClass)


33
34
35
# File 'lib/vedeu/output/viewport.rb', line 33

def self.render(view)
  new(view).render
end

Instance Method Details

#bxFixnum (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Fixnum)


158
159
160
# File 'lib/vedeu/output/viewport.rb', line 158

def bx
  @bx ||= geometry.bx
end

#byFixnum (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Fixnum)


163
164
165
# File 'lib/vedeu/output/viewport.rb', line 163

def by
  @by ||= geometry.by
end

#columnsRange (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

The width is reduced by one as #columns is a range of Array elements.

Using the current cursor’s x position, return a range of visible columns.

Scrolls the content horizontally when the stored cursor’s x position for the interface is outside of the visible area.

Returns:

  • (Range)


123
124
125
# File 'lib/vedeu/output/viewport.rb', line 123

def columns
  left...(left + bordered_width)
end

#content_offset(offset, dimension) ⇒ Fixnum (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the offset for the content (the number of rows or columns to change the viewport by on either the y or x axis) determined by the offset (the cursor’s y or x offset position.

Parameters:

  • offset (Fixnum)

    The cursor’s oy or ox values.

  • dimension (Fixnum)

    Either the height or width.

Returns:

  • (Fixnum)


144
145
146
147
148
# File 'lib/vedeu/output/viewport.rb', line 144

def content_offset(offset, dimension)
  return 0 unless offset >= dimension

  offset - dimension
end

#cursorVedeu::Cursors::Cursor (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

See Also:

  • Cursors::Repository#by_name


169
170
171
# File 'lib/vedeu/output/viewport.rb', line 169

def cursor
  @cursor ||= Vedeu.cursors.by_name(name)
end

#geometryObject (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the geometry for the interface.



153
154
155
# File 'lib/vedeu/output/viewport.rb', line 153

def geometry
  @geometry ||= Vedeu.geometries.by_name(name)
end

#leftFixnum (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Fixnum)


128
129
130
# File 'lib/vedeu/output/viewport.rb', line 128

def left
  @left ||= content_offset(ox, bordered_width)
end

#outputArray<Array<Vedeu::Views::Char>> (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/vedeu/output/viewport.rb', line 69

def output
  Vedeu.timer("Rendering content: '#{name}'".freeze) do
    out = []

    show.each_with_index do |line, iy|
      line.each_with_index do |column, ix|
        column.position = [by + iy, bx + ix]
        out << column
      end
    end

    out
  end
end

#renderArray<Array<String>>|NilClass

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the content for the view.

Returns:

  • (Array<Array<String>>|NilClass)


48
49
50
# File 'lib/vedeu/output/viewport.rb', line 48

def render
  Vedeu.render_output(output) if visible?
end

#rowsRange (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

The height is reduced by one as #rows is a range of Array elements.

Using the current cursor’s y position, return a range of visible lines.

Scrolls the content vertically when the stored cursor’s y position for the interface is outside of the visible area.

Returns:

  • (Range)


108
109
110
# File 'lib/vedeu/output/viewport.rb', line 108

def rows
  top...(top + bordered_height)
end

#showArray (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

If there are no lines of content, we return an empty array. If there are no more columns of content we return a space enclosed in an array; this prevents a weird line hopping bug which occurs when the current line has no more content, but subsequent lines do.

Returns the visible content for the view.

Returns:

  • (Array)


93
94
95
# File 'lib/vedeu/output/viewport.rb', line 93

def show
  (lines[rows] || []).map { |line| (line.chars[columns] || []) }
end

#to_sString Also known as: to_str

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a string representation of the viewport.

Returns:

  • (String)


55
56
57
# File 'lib/vedeu/output/viewport.rb', line 55

def to_s
  Array(render).map(&:to_s).join("\n".freeze)
end

#topFixnum (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Fixnum)


133
134
135
# File 'lib/vedeu/output/viewport.rb', line 133

def top
  @top ||= content_offset(oy, bordered_height)
end