lib/vedeu/cursors/cursor.rb in vedeu-0.6.44 vs lib/vedeu/cursors/cursor.rb in vedeu-0.6.45

- old
+ new

@@ -95,11 +95,11 @@ # @return [Vedeu::Cursors::Cursor] def move_down @oy += 1 @y = coordinate(oy, :y).y - store + store_and_refresh end # Moves the cursor left by one column. # # Vedeu.trigger(:_cursor_left_, name) @@ -108,11 +108,11 @@ # @return [Vedeu::Cursors::Cursor] def move_left @ox -= 1 @x = coordinate(ox, :x).x - store + store_and_refresh end # Moves the cursor to the top left of the named interface. # # Vedeu.trigger(:_cursor_origin_, name) @@ -136,11 +136,11 @@ # @return [Vedeu::Cursors::Cursor] def move_right @ox += 1 @x = coordinate(ox, :x).x - store + store_and_refresh end # Moves the cursor up by one row. # # Vedeu.trigger(:_cursor_up_, name) @@ -149,11 +149,11 @@ # @return [Vedeu::Cursors::Cursor] def move_up @oy -= 1 @y = coordinate(oy, :y).y - store + store_and_refresh end # Renders the cursor. # # @return [Array<Vedeu::Models::Escape>] @@ -298,10 +298,21 @@ # @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 + # Store the cursor and refresh the cursor. + # + # @return [void] + def store_and_refresh + store + + Vedeu.trigger(:_refresh_cursor_, name) + + self + end + # Returns the escape sequence for setting the visibility of the # cursor. # # @return [String] def visibility @@ -338,48 +349,32 @@ # See {file:docs/events/visibility.md#\_toggle_cursor_} Vedeu.bind(:_toggle_cursor_) { |name| Vedeu.toggle_cursor(name) } # See {file:docs/cursors.md} Vedeu.bind(:_cursor_left_) do |name| - cursor = Vedeu.cursors.by_name(name) - - if cursor.visible? - cursor.move_left - - Vedeu.trigger(:_refresh_cursor_, name) + Vedeu.cursors.by_name(name).tap do |cursor| + cursor.move_left if cursor.visible? end end # See {file:docs/cursors.md} Vedeu.bind(:_cursor_down_) do |name| - cursor = Vedeu.cursors.by_name(name) - - if cursor.visible? - cursor.move_down - - Vedeu.trigger(:_refresh_cursor_, name) + Vedeu.cursors.by_name(name).tap do |cursor| + cursor.move_down if cursor.visible? end end # See {file:docs/cursors.md} Vedeu.bind(:_cursor_up_) do |name| - cursor = Vedeu.cursors.by_name(name) - - if cursor.visible? - cursor.move_up - - Vedeu.trigger(:_refresh_cursor_, name) + Vedeu.cursors.by_name(name).tap do |cursor| + cursor.move_up if cursor.visible? end end # See {file:docs/cursors.md} Vedeu.bind(:_cursor_right_) do |name| - cursor = Vedeu.cursors.by_name(name) - - if cursor.visible? - cursor.move_right - - Vedeu.trigger(:_refresh_cursor_, name) + Vedeu.cursors.by_name(name).tap do |cursor| + cursor.move_right if cursor.visible? end end # See {file:docs/cursors.md} Vedeu.bind(:_cursor_origin_) do |name|