lib/vedeu/cursor/cursor.rb in vedeu-0.4.13 vs lib/vedeu/cursor/cursor.rb in vedeu-0.4.14

- old
+ new

@@ -1,21 +1,16 @@ require 'vedeu/cursor/all' require 'vedeu/geometry/position' -require 'vedeu/support/visible' module Vedeu # Each interface has its own Cursor which maintains the position and # visibility of the cursor within that interface. # class Cursor extend Forwardable - - def_delegators :state, :visible?, - :invisible? - include Vedeu::Model # @!attribute [r] attributes # @return [Hash] attr_reader :attributes @@ -34,10 +29,15 @@ # @!attribute [r] state # @return [Boolean|Symbol] attr_reader :state + # @!attribute [r] visible + # @return [Boolean|Symbol] + attr_reader :visible + alias_method :visible?, :visible + # @!attribute [r] x # @return [Fixnum] attr_reader :x # @!attribute [r] y @@ -50,39 +50,41 @@ # @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 state [Boolean|Symbol] The visibility of the cursor, - # either +true+ or +false+, +:hide+ or +:show+. + # @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 the cursor. # # @return [Cursor] def initialize(attributes = {}) # Hack because Repository#by_name creates Cursor objects with just a # name. - if attributes.is_a?(String) - attributes = { name: attributes } - end + attributes = { name: attributes } if attributes.is_a?(String) @attributes = defaults.merge!(attributes) @name = @attributes.fetch(:name) @ox = @attributes.fetch(:ox) @oy = @attributes.fetch(:oy) @repository = @attributes.fetch(:repository) - @state = Vedeu::Visible.coerce(@attributes.fetch(:state)) + @visible = @attributes.fetch(:visible) @x = @attributes.fetch(:x) @y = @attributes.fetch(:y) @position = Vedeu::Position.new(@y, @x) end # @return [String] def inspect - "<Vedeu::Cursor (#{name}, #{state}, x:#{x}, y:#{y}, ox:#{ox}, oy:#{oy})>" + "<Vedeu::Cursor (#{name}, " \ + "#{visible}, " \ + "x:#{x}, " \ + "y:#{y}, " \ + "ox:#{ox}, " \ + "oy:#{oy})>" end # 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. @@ -112,11 +114,11 @@ { name: '', ox: 0, oy: 0, repository: Vedeu.cursors, - state: false, + visible: false, x: 1, y: 1, } end @@ -129,10 +131,16 @@ # Returns the escape sequence for setting the visibility of the cursor. # # @return [String] def visibility - state.cursor + if visible? + Vedeu::Esc.string('show_cursor') + + else + Vedeu::Esc.string('hide_cursor') + + end end end # Cursor end # Vedeu