Class: Vedeu::Runtime::Application
- Inherits:
-
Object
- Object
- Vedeu::Runtime::Application
- Defined in:
- lib/vedeu/runtime/application.rb
Overview
Orchestrates the running of the main application loop.
Instance Attribute Summary collapse
- #configuration ⇒ Vedeu::Configuration readonly protected
Class Method Summary collapse
- .restart(configuration) ⇒ Object
- .start(configuration) ⇒ Object
-
.stop ⇒ void
(also: exit)
Stops the application! - The ‘:cleanup` event is triggered, which in turn triggers the client event `:cleanup`; the client application may treat this event as Vedeu signalling that it is about to terminate.
Instance Method Summary collapse
-
#initialize(configuration) ⇒ Vedeu::Runtime::Application
constructor
Returns a new instance of Vedeu::Runtime::Application.
-
#main_sequence ⇒ void
private
For an interactive application we capture input, (usually from the user), and continue the main loop.
-
#run_many ⇒ void
private
Runs the application in a continuous loop.
-
#runner ⇒ void
private
Runs the application loop either once, or forever (exceptions and signals permitting).
-
#start ⇒ Array
Starts the application!.
Constructor Details
#initialize(configuration) ⇒ Vedeu::Runtime::Application
Returns a new instance of Vedeu::Runtime::Application.
47 48 49 |
# File 'lib/vedeu/runtime/application.rb', line 47 def initialize(configuration) @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Vedeu::Configuration (readonly, protected)
80 81 82 |
# File 'lib/vedeu/runtime/application.rb', line 80 def configuration @configuration end |
Class Method Details
.restart(configuration) ⇒ Object
17 18 19 |
# File 'lib/vedeu/runtime/application.rb', line 17 def restart(configuration) new(configuration).start end |
.start(configuration) ⇒ Object
12 13 14 |
# File 'lib/vedeu/runtime/application.rb', line 12 def start(configuration) new(configuration).start end |
.stop ⇒ void Also known as: exit
This method returns an undefined value.
Stops the application! - The ‘:cleanup` event is triggered, which in turn triggers the client event `:cleanup`; the client application may treat this event as Vedeu signalling that it is about to terminate. Client applications are encouraged to use this event to close any open buffers, save files, empty trash, etc.
32 33 34 35 36 |
# File 'lib/vedeu/runtime/application.rb', line 32 def stop Vedeu.trigger(:_cleanup_) Vedeu::Runtime::MainLoop.stop! end |
Instance Method Details
#main_sequence ⇒ void (private)
This method returns an undefined value.
For an interactive application we capture input, (usually from the user), and continue the main loop. If the client application does not require user input then Vedeu triggers the ‘:standalone` event for each run of the main loop. The client application is expected to respond to this event and ’do something useful’. When the client application has finished, it should trigger the ‘:exit` event.
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/vedeu/runtime/application.rb', line 103 def main_sequence if configuration.interactive? Vedeu::Input::Capture.read(Terminal) else Vedeu.trigger(:_standalone_) Vedeu.refresh end end |
#run_many ⇒ void (private)
This method returns an undefined value.
Runs the application in a continuous loop. This loop is stopped when an uncaught exception occurs or when either the ‘:mode_switch` or `:exit` event is triggered.
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/vedeu/runtime/application.rb', line 119 def run_many Vedeu::Runtime::MainLoop.start! { yield } rescue Vedeu::Error::ModeSwitch Vedeu::Terminal.switch_mode! Vedeu.trigger(:_drb_restart_) Vedeu::Runtime::Application.restart(configuration) end |
#runner ⇒ void (private)
This method returns an undefined value.
Runs the application loop either once, or forever (exceptions and signals permitting).
88 89 90 91 92 |
# File 'lib/vedeu/runtime/application.rb', line 88 def runner return yield if configuration.once? run_many { yield } end |
#start ⇒ Array
Starts the application!
-
A new terminal screen is opened (or rather the current terminal is requested into either :raw or :cooked mode).
-
The cursor visibility is then set dependent on this mode. In :raw mode, the cursor is hidden.
-
The ‘:initialize` event is triggered. The client application is may treat this event as Vedeu signalling that it is now ready.
-
We enter into the main sequence where the application will either run once or continuous, interactively or standalone.
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/vedeu/runtime/application.rb', line 64 def start Vedeu.trigger(:_drb_start_) Vedeu::Terminal.open do Vedeu::Terminal.set_cursor_mode Vedeu.trigger(:_initialize_) runner { main_sequence } end end |