Class: Vedeu::Cursors::Refresh

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/vedeu/cursors/refresh.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 = nil) ⇒ Vedeu::Cursors::Refresh

Returns a new instance of Vedeu::Cursors::Refresh.

Parameters:

  • name (String) (defaults to: nil)

    The name of the cursor.



26
27
28
# File 'lib/vedeu/cursors/refresh.rb', line 26

def initialize(name = nil)
  @name = name || Vedeu.focus
end

Instance Attribute Details

#nameString (readonly, protected)

Returns:

  • (String)


48
49
50
# File 'lib/vedeu/cursors/refresh.rb', line 48

def name
  @name
end

Class Method Details

.by_name(name = nil) ⇒ Object

Parameters:

  • name (String) (defaults to: nil)

    The name of the cursor.



18
19
20
# File 'lib/vedeu/cursors/refresh.rb', line 18

def self.by_name(name = nil)
  new(name).by_name
end

Instance Method Details

#borderObject (private)

Note:

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

Fetch the border by name.



80
81
82
# File 'lib/vedeu/cursors/refresh.rb', line 80

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

#by_nameArray

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)


36
37
38
39
40
41
42
# File 'lib/vedeu/cursors/refresh.rb', line 36

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

  Vedeu.trigger(:_refresh_, name) if refresh_view?

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

#cursorVedeu::Cursors::Cursor (private)

Returns:

See Also:

  • Vedeu::Cursors::Repository#by_name


63
64
65
# File 'lib/vedeu/cursors/refresh.rb', line 63

def cursor
  @cursor ||= Vedeu.cursors.by_name(name)
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)


57
58
59
# File 'lib/vedeu/cursors/refresh.rb', line 57

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