Class: Vedeu::RefreshCursor

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

Overview

Handle the refreshing (redrawing) of a cursor, without redrawing the whole interface; unless the cursor’s offset has caused the view to change.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Vedeu::RefreshCursor

Returns a new instance of Vedeu::RefreshCursor.

Parameters:

  • name (String)

    The name of the cursor.



22
23
24
# File 'lib/vedeu/cursor/refresh_cursor.rb', line 22

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameString (readonly, protected)

Returns:

  • (String)


43
44
45
# File 'lib/vedeu/cursor/refresh_cursor.rb', line 43

def name
  @name
end

Class Method Details

.render(name = Vedeu.focus) ⇒ Object

Parameters:

  • name (String) (defaults to: Vedeu.focus)

    The name of the cursor.



14
15
16
# File 'lib/vedeu/cursor/refresh_cursor.rb', line 14

def self.render(name = Vedeu.focus)
  new(name).render
end

Instance Method Details

#borderObject (private)

Note:

Vedeu::Border is used in this way because if there is not a border defined, it will fallback to a Vedeu::Null::Border which uses Vedeu::Geometry to determine it’s dimensions based on the name also. When a Vedeu::Geometry cannot be found, this falls back to a Vedeu::Null::Geometry which uses the current terminal’s dimensions.

Fetch the border by name.



89
90
91
# File 'lib/vedeu/cursor/refresh_cursor.rb', line 89

def border
  @border ||= Vedeu.borders.by_name(name)
end

#cursorVedeu::Cursor (private)

Returns:



75
76
77
# File 'lib/vedeu/cursor/refresh_cursor.rb', line 75

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

#new_cursorVedeu::Cursor (private)

Returns:



57
58
59
# File 'lib/vedeu/cursor/refresh_cursor.rb', line 57

def new_cursor
  @new_cursor ||= Vedeu::Cursor.new(cursor.attributes.merge(position))
end

#positionHash<Symbol => Fixnum> (private)

Returns:

  • (Hash<Symbol => Fixnum>)


62
63
64
65
66
67
# File 'lib/vedeu/cursor/refresh_cursor.rb', line 62

def position
  {
    x: validated_position.x,
    y: validated_position.y,
  }
end

#refresh_view?Boolean (private)

Returns true when the view should be refreshed. This is determined by checking that the offsets for x and y are outside the width and height of the named interface.

Returns:

  • (Boolean)


52
53
54
# File 'lib/vedeu/cursor/refresh_cursor.rb', line 52

def refresh_view?
  new_cursor.ox >= width || new_cursor.oy >= height
end

#renderArray

Renders the cursor in the terminal. If the cursor’s x or y offsets are greater or equal to the interface’s width or height respectively, then the view is also refreshed, causing the content to be offset also.

Returns:

  • (Array)


31
32
33
34
35
36
37
# File 'lib/vedeu/cursor/refresh_cursor.rb', line 31

def render
  Vedeu.log(type: :info, message: "Refreshing cursor: '#{name}'")

  Vedeu::Refresh.by_name(name) if refresh_view?

  Vedeu::Terminal.output(new_cursor.to_s)
end

#validated_positionVedeu::PositionValidator (private)



70
71
72
# File 'lib/vedeu/cursor/refresh_cursor.rb', line 70

def validated_position
  @position ||= Vedeu::PositionValidator.validate(name, cursor.x, cursor.y)
end