Sha256: 761b3d618c1997d9395b53977cbdb28ab8f18a12fcd4fd009a5188a599f681c2
Contents?: true
Size: 1.22 KB
Versions: 10
Compression:
Stored size: 1.22 KB
Contents
require 'vedeu/support/input' require 'vedeu/support/terminal' module Vedeu ModeSwitch = Class.new(StandardError) class Application # :nocov: def self.start(options = {}) new(options).start end def initialize(options = {}) @options = options end def start Terminal.open(mode) do Terminal.set_cursor_mode Vedeu.events.trigger(:refresh) runner { main_sequence } end end private attr_reader :options def runner if interactive? interactive { yield } else run_once { yield } end end def main_sequence Input.capture Vedeu.events.trigger(:refresh) end def interactive? options.fetch(:interactive) end def interactive loop { yield } rescue ModeSwitch if Terminal.raw_mode? Application.start({ mode: :cooked }) else Application.start({ mode: :raw }) end end def run_once yield end def mode options.fetch(:mode) end def options defaults.merge!(@options) end def defaults { interactive: true, mode: :raw } end # :nocov: end end
Version data entries
10 entries across 10 versions & 1 rubygems