lib/vedeu/cursors/cursor.rb in vedeu-0.6.10 vs lib/vedeu/cursors/cursor.rb in vedeu-0.6.11

- old
+ new

@@ -5,11 +5,11 @@ # Each interface has its own Cursor which maintains the position # and visibility of the cursor within that interface. # class Cursor - include Vedeu::Model + include Vedeu::Repositories::Model include Vedeu::Toggleable extend Forwardable def_delegators :border, :bx, @@ -50,11 +50,12 @@ # @param attributes [Hash] # @option attributes name [String] The name of the interface # this cursor belongs to. # @option attributes ox [Fixnum] The offset x coordinate. # @option attributes oy [Fixnum] The offset y coordinate. - # @option attributes repository [Vedeu::Repository] + # @option attributes repository + # [Vedeu::Repositories::Repository] # @option attributes visible [Boolean] The visibility of the # cursor. # @option attributes x [Fixnum] The terminal x coordinate for # the cursor. # @option attributes y [Fixnum] The terminal y coordinate for @@ -73,28 +74,22 @@ # # @return [Vedeu::Cursors::Cursor] def move_down @oy += 1 - @attributes = attributes.merge!(x: x, - y: coordinate.y_position, - ox: ox, - oy: oy) + @attributes = new_attributes(coordinate.y_position, x, oy, ox) Vedeu::Cursors::Cursor.new(@attributes).store end # Moves the cursor left by one column. # # @return [Vedeu::Cursors::Cursor] def move_left @ox -= 1 - @attributes = attributes.merge!(x: coordinate.x_position, - y: y, - ox: ox, - oy: oy) + @attributes = new_attributes(y, coordinate.x_position, oy, ox) Vedeu::Cursors::Cursor.new(@attributes).store end # Moves the cursor to the top left of the named interface. @@ -110,28 +105,22 @@ # # @return [Vedeu::Cursors::Cursor] def move_right @ox += 1 - @attributes = attributes.merge!(x: coordinate.x_position, - y: y, - ox: ox, - oy: oy) + @attributes = new_attributes(y, coordinate.x_position, oy, ox) Vedeu::Cursors::Cursor.new(@attributes).store end # Moves the cursor up by one row. # # @return [Vedeu::Cursors::Cursor] def move_up @oy -= 1 - @attributes = attributes.merge!(x: x, - y: coordinate.y_position, - ox: ox, - oy: oy) + @attributes = new_attributes(coordinate.y_position, x, oy, ox) Vedeu::Cursors::Cursor.new(@attributes).store end # Renders the cursor. @@ -141,18 +130,18 @@ Vedeu::Output::Output.render(visibility) end # Arbitrarily move the cursor to a given position. # - # @param new_y [Fixnum] The row/line position. - # @param new_x [Fixnum] The column/character position. + # @param new_oy [Fixnum] The row/line position. + # @param new_ox [Fixnum] The column/character position. # @return [Vedeu::Cursors::Cursor] - def reposition(new_y, new_x) - @attributes = attributes.merge!(x: coordinate.x_position, - y: coordinate.y_position, - ox: new_x, - oy: new_y) + def reposition(new_oy, new_ox) + @attributes = new_attributes(coordinate.y_position, + coordinate.x_position, + new_oy, + new_ox) Vedeu::Cursors::Cursor.new(@attributes).store end # Returns an escape sequence to position the cursor and set its @@ -278,15 +267,26 @@ x: 1, y: 1, } end + # @return [Hash] + def new_attributes(new_y = y, new_x = x, new_oy = oy, new_ox = ox) + attributes.merge!(x: new_x, y: new_y, ox: new_ox, oy: new_oy) + end + # Returns the escape sequence for setting the visibility of the # cursor. # # @return [String] def visibility - value = visible? ? Vedeu::Esc.show_cursor : Vedeu::Esc.hide_cursor + value = if visible? + Vedeu::EscapeSequences::Esc.show_cursor + + else + Vedeu::EscapeSequences::Esc.hide_cursor + + end Vedeu::Models::Escape.new(position: position, value: value) end end # Cursor