lib/vedeu/interface/interface.rb in vedeu-0.0.4 vs lib/vedeu/interface/interface.rb in vedeu-0.0.5

- old
+ new

@@ -1,37 +1,62 @@ module Vedeu + class NotImplementedError < StandardError; end + class Interface def initialize(options = {}) @options = options end - def initial; end + def initial_state + raise NotImplementedError, 'Subclasses implement this method.' + end - def main - output + def event_loop + while true do + command = input - input - end + break if command == :stop - def output - Terminal.hide_cursor + output(command) + end end def input - Terminal.show_cursor + evaluate end + def output(command) + Compositor.write(command) + end + + private + + attr_reader :options + + def evaluate + Commands.execute(read) + end + + def read + Terminal.input + end + def width - options[:width] || Terminal.width + options[:width] end def height - options[:height] || Terminal.height + options[:height] end - private + def options + defaults.merge!(@options) + end - attr_reader :options + def defaults + { + width: Terminal.width, + height: Terminal.height + } + end end - - class Dummy < Interface; end end