Class: Vedeu::Cursors::Cursor

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Repositories::Model, Toggleable
Defined in:
lib/vedeu/cursors/cursor.rb,
lib/vedeu/cursors/repository.rb

Overview

Repository

Instance Attribute Summary collapse

Attributes included from Toggleable

#visible

Attributes included from Repositories::Model

#repository

Instance Method Summary collapse

Methods included from Toggleable

included, #toggle

Methods included from Repositories::Model

included, #store

Constructor Details

#initialize(attributes = {}) ⇒ Vedeu::Cursors::Cursor

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 new instance of Vedeu::Cursors::Cursor.

Parameters:

Options Hash (attributes):

  • name (String|Symbol)

    The name of the interface this cursor belongs to.

  • ox (Fixnum)

    The offset x coordinate.

  • oy (Fixnum)

    The offset y coordinate.

  • repository (Object)
    Vedeu::Repositories::Repository
  • visible (Boolean)

    The visibility of the cursor.

  • x (Fixnum)

    The terminal x coordinate for the cursor.

  • y (Fixnum)

    The terminal y coordinate for the cursor.



61
62
63
64
65
# File 'lib/vedeu/cursors/cursor.rb', line 61

def initialize(attributes = {})
  defaults.merge!(attributes).each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Instance Attribute Details

#nameNilClass|Symbol|String (readonly)

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 name of the model, the target model or the name of the associated model.

Returns:

  • (NilClass|Symbol|String)

    The name of the model, the target model or the name of the associated model.



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

def name
  @name
end

#oxFixnum

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)


179
180
181
# File 'lib/vedeu/cursors/cursor.rb', line 179

def ox
  @ox = @ox < 1 ? 1 : @ox
end

#oyFixnum

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)


184
185
186
# File 'lib/vedeu/cursors/cursor.rb', line 184

def oy
  @oy = @oy < 1 ? 1 : @oy
end

#xFixnum

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 column/character coordinate.

Returns:

  • (Fixnum)

    The column/character coordinate.



206
207
208
# File 'lib/vedeu/cursors/cursor.rb', line 206

def x
  @x = Vedeu::Point.coerce(value: @x, min: bx, max: bxn).value
end

#yFixnum

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 row/line coordinate.

Returns:

  • (Fixnum)

    The row/line coordinate.



211
212
213
# File 'lib/vedeu/cursors/cursor.rb', line 211

def y
  @y = Vedeu::Point.coerce(value: @y, min: by, max: byn).value
end

Instance Method Details

#attributesHash<Symbol => Boolean|Fixnum|String| Vedeu::Cursors::Repository>

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
# File 'lib/vedeu/cursors/cursor.rb', line 69

def attributes
  {
    name:       @name,
    ox:         ox,
    oy:         oy,
    repository: @repository,
    visible:    @visible,
    x:          x,
    y:          y,
  }
end

#coordinate(offset, type) ⇒ Vedeu::Cursors::Coordinate (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.

Determine correct x and y related coordinates.



225
226
227
228
229
# File 'lib/vedeu/cursors/cursor.rb', line 225

def coordinate(offset, type)
  Vedeu::Cursors::Coordinate.new(geometry: geometry,
                                 offset:   offset,
                                 type:     type)
end

#defaultsHash<Symbol => void> (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.

The default options/attributes for a new instance of this class.

Returns:

  • (Hash<Symbol => void>)


232
233
234
235
236
237
238
239
240
241
242
# File 'lib/vedeu/cursors/cursor.rb', line 232

def defaults
  {
    name:       nil,
    ox:         1,
    oy:         1,
    repository: Vedeu.cursors,
    visible:    false,
    x:          1,
    y:          1,
  }
end

#eql?(other) ⇒ Boolean Also known as: ==

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.

An object is equal when its values are the same.

Parameters:

Returns:



85
86
87
# File 'lib/vedeu/cursors/cursor.rb', line 85

def eql?(other)
  self.class.equal?(other.class) && name == other.name
end

#escape_sequenceVedeu::Cells::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.



245
246
247
# File 'lib/vedeu/cursors/cursor.rb', line 245

def escape_sequence
  Vedeu::Cells::Cursor.new(position: position, value: visibility)
end

#geometryVedeu::Geometries::Geometry (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 named geometry from the geometries repository.



218
219
220
# File 'lib/vedeu/cursors/cursor.rb', line 218

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

#hideVedeu::Cells::Cursor

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.



170
171
172
173
174
175
176
# File 'lib/vedeu/cursors/cursor.rb', line 170

def hide
  super

  Vedeu.log(type: :cursor, message: "Hiding cursor: '#{name}'")

  render
end

#inspectString

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:

  • (String)


91
92
93
94
# File 'lib/vedeu/cursors/cursor.rb', line 91

def inspect
  "name: #{name.inspect} x: #{x} y: #{y} ox: #{ox} oy: #{oy} " \
  "visible: #{visible}"
end

#move_down(offset = 1) ⇒ Vedeu::Cursors::Cursor

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.



98
99
100
101
102
103
# File 'lib/vedeu/cursors/cursor.rb', line 98

def move_down(offset = 1)
  @oy += offset || 1
  @y = coordinate(oy, :y).y

  self
end

#move_left(offset = 1) ⇒ Vedeu::Cursors::Cursor

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.



107
108
109
110
111
112
# File 'lib/vedeu/cursors/cursor.rb', line 107

def move_left(offset = 1)
  @ox -= offset || 1
  @x = coordinate(ox, :x).x

  self
end

#move_originVedeu::Cursors::Cursor

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.



116
117
118
119
120
121
122
123
# File 'lib/vedeu/cursors/cursor.rb', line 116

def move_origin
  @x = bx
  @y = by
  @ox = 0
  @oy = 0

  store
end

#move_right(offset = 1) ⇒ Vedeu::Cursors::Cursor

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.



127
128
129
130
131
132
# File 'lib/vedeu/cursors/cursor.rb', line 127

def move_right(offset = 1)
  @ox += offset || 1
  @x = coordinate(ox, :x).x

  self
end

#move_up(offset = 1) ⇒ Vedeu::Cursors::Cursor

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.



136
137
138
139
140
141
# File 'lib/vedeu/cursors/cursor.rb', line 136

def move_up(offset = 1)
  @oy -= offset || 1
  @y = coordinate(oy, :y).y

  self
end

#positionVedeu::Geometries::Position

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.

Return the position of this cursor.



191
192
193
# File 'lib/vedeu/cursors/cursor.rb', line 191

def position
  @position = Vedeu::Geometries::Position.new(y, x)
end

#renderArray<Vedeu::Cells::Cursor>

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.

Renders the cursor.

Returns:



146
147
148
# File 'lib/vedeu/cursors/cursor.rb', line 146

def render
  Vedeu.render_output(escape_sequence)
end

#showVedeu::Cells::Cursor

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.



197
198
199
200
201
202
203
# File 'lib/vedeu/cursors/cursor.rb', line 197

def show
  super

  Vedeu.log(type: :cursor, message: "Showing cursor: '#{name}'")

  render
end

#to_aArray<Fixnum>

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:

  • (Array<Fixnum>)


151
152
153
# File 'lib/vedeu/cursors/cursor.rb', line 151

def to_a
  position.to_a
end

#to_s(&block) ⇒ String 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 an escape sequence to position the cursor and set its visibility. When passed a block, will position the cursor, yield and return the original position.

Parameters:

  • block (Proc)

Returns:

  • (String)


161
162
163
164
165
# File 'lib/vedeu/cursors/cursor.rb', line 161

def to_s(&block)
  return escape_sequence.to_s unless block_given?

  "#{position}#{yield}#{escape_sequence}"
end

#visibilityString (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 escape sequence for setting the visibility of the cursor.

Returns:

  • (String)


253
254
255
256
257
# File 'lib/vedeu/cursors/cursor.rb', line 253

def visibility
  return Vedeu.esc.show_cursor if visible?

  Vedeu.esc.hide_cursor
end