Class: Vedeu::Cursors::Refresh

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Vedeu::Common
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) ⇒ Vedeu::Cursors::Refresh

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

Parameters:

  • name (String|Symbol)

    The name of the interface/view cursor to be refreshed. Defaults to ‘Vedeu.focus`.



34
35
36
# File 'lib/vedeu/cursors/refresh.rb', line 34

def initialize(name)
  @name = present?(name) ? name : Vedeu.focus
end

Instance Attribute Details

#nameString|Symbol (readonly, protected)

Returns:

  • (String|Symbol)


54
55
56
# File 'lib/vedeu/cursors/refresh.rb', line 54

def name
  @name
end

Class Method Details

.by_name(name = Vedeu.focus) ⇒ Array

Examples:

Vedeu.trigger(:_refresh_cursor_, name)

Parameters:

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

    The name of the interface/view cursor to be refreshed. Defaults to ‘Vedeu.focus`.

Returns:

  • (Array)


23
24
25
26
27
# File 'lib/vedeu/cursors/refresh.rb', line 23

def self.by_name(name = Vedeu.focus)
  name || Vedeu.focus

  new(name).by_name
end

Instance Method Details

#absent?(variable) ⇒ Boolean Originally defined in module Vedeu::Common

Returns a boolean indicating whether a variable is nil or empty.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

#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.



86
87
88
# File 'lib/vedeu/cursors/refresh.rb', line 86

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)


44
45
46
47
48
# File 'lib/vedeu/cursors/refresh.rb', line 44

def by_name
  Vedeu.trigger(:_refresh_view_content_, name) if refresh_view?

  cursor.render
end

#cursorVedeu::Cursors::Cursor (private)

Returns:

See Also:

  • Vedeu::Cursors::Repository#by_name


69
70
71
# File 'lib/vedeu/cursors/refresh.rb', line 69

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

#demodulize(klass) ⇒ String Originally defined in module Vedeu::Common

Removes the module part from the expression in the string.

Examples:

demodulize('Vedeu::SomeModule::SomeClass') # => "SomeClass"

Parameters:

  • klass (Class|String)

Returns:

  • (String)

#present?(variable) ⇒ Boolean Originally defined in module Vedeu::Common

Returns a boolean indicating whether a variable has a useful value.

Parameters:

  • variable (String|Symbol|Array|Fixnum)

    The variable to check.

Returns:

  • (Boolean)

#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)


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

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

#snake_case(name) ⇒ String Originally defined in module Vedeu::Common

Converts a class name to a lowercase snake case string.

Examples:

snake_case(MyClassName) # => "my_class_name"
snake_case(NameSpaced::ClassName)
# => "name_spaced/class_name"

Parameters:

  • name (String)

Returns:

  • (String)