Sha256: aebedff0a6ea00eb3f7ae36d6261c2d328bd32eb6195d41ba8336a351a226657
Contents?: true
Size: 1.9 KB
Versions: 1
Compression:
Stored size: 1.9 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 attribute :delay, Float, default: 0.0 def initialize(attributes = {}) Vedeu.events.on(:refresh, attributes[:delay]) { refresh } super end def clear @_clear ||= ClearInterface.call(self) 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 = clear 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
vedeu-0.1.2 | lib/vedeu/models/interface.rb |