Sha256: 6b1949e0fb6fdbd872dc8f850a8059fee7a889882486252af741408aefffec05
Contents?: true
Size: 1.79 KB
Versions: 4
Compression:
Stored size: 1.79 KB
Contents
require 'json' require 'virtus' require 'vedeu' require 'vedeu/models/attributes/line_collection' require 'vedeu/models/presentation' require 'vedeu/models/style' require 'vedeu/output/clear_interface' require 'vedeu/output/render_interface' require 'vedeu/support/geometry' require 'vedeu/support/queue' require 'vedeu/support/terminal' module Vedeu class Interface include Vedeu::Queue include Virtus.model include Presentation include Style attribute :name, String attribute :lines, LineCollection attribute :y, Integer, default: 1 attribute :x, Integer, default: 1 attribute :width, Integer, default: Terminal.width attribute :height, Integer, default: Terminal.height attribute :current, String, default: '' attribute :cursor, Boolean, default: true attribute :centred, Boolean, default: false def initialize(attributes = {}) Vedeu.events.on(:refresh) { refresh } super end def enqueue super(self.to_s) end def geometry @_geometry ||= Geometry.new(attributes) end def origin(index = 0) geometry.origin(index) end def refresh if enqueued? self.current = dequeue elsif no_content? self.current = ClearInterface.call(self) else self.current end Terminal.output(self.current) self.current end def to_json(*args) { colour: colour, style: style_original, name: name, lines: lines, y: y, x: x, width: width, height: height, cursor: cursor }.to_json end def to_s RenderInterface.call(self) end private def no_content? self.current.nil? || self.current.empty? end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
vedeu-0.1.0 | lib/vedeu/models/interface.rb |
vedeu-0.0.42 | lib/vedeu/models/interface.rb |
vedeu-0.0.41 | lib/vedeu/models/interface.rb |
vedeu-0.0.40 | lib/vedeu/models/interface.rb |