Class: Vedeu::Application
- Inherits:
-
Object
- Object
- Vedeu::Application
- Defined in:
- lib/vedeu/application.rb
Overview
Orchestrates the running of the main application loop.
Instance Attribute Summary collapse
- #configuration ⇒ Configuration readonly protected
Class Method Summary collapse
- .restart(configuration) ⇒ Object
- .start(configuration) ⇒ Object
-
.stop ⇒ void
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) ⇒ Application
constructor
:nocov: Returns a new instance of Vedeu::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! - A new terminal screen is opened (or rather the current terminal is requested into either :raw or :cooked mode).
Constructor Details
#initialize(configuration) ⇒ Application
:nocov: Returns a new instance of Vedeu::Application.
35 36 37 |
# File 'lib/vedeu/application.rb', line 35 def initialize(configuration) @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Configuration (readonly, protected)
70 71 72 |
# File 'lib/vedeu/application.rb', line 70 def configuration @configuration end |
Class Method Details
.restart(configuration) ⇒ Object
12 13 14 |
# File 'lib/vedeu/application.rb', line 12 def self.restart(configuration) new(configuration).start end |
.start(configuration) ⇒ Object
7 8 9 |
# File 'lib/vedeu/application.rb', line 7 def self.start(configuration) new(configuration).start end |
.stop ⇒ void
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.
24 25 26 27 28 |
# File 'lib/vedeu/application.rb', line 24 def self.stop Vedeu.trigger(:_cleanup_) Vedeu::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.
96 97 98 99 100 101 102 103 104 |
# File 'lib/vedeu/application.rb', line 96 def main_sequence if configuration.interactive? Vedeu::Input.capture(Terminal) else Vedeu.trigger(:_standalone_) 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.
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/vedeu/application.rb', line 111 def run_many Vedeu::MainLoop.start! { yield } rescue ModeSwitch Vedeu::Terminal.switch_mode! Vedeu.trigger(:_drb_restart_) Vedeu::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).
78 79 80 81 82 83 84 85 86 |
# File 'lib/vedeu/application.rb', line 78 def runner if configuration.once? yield else run_many { yield } end 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.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/vedeu/application.rb', line 50 def start Vedeu.trigger(:_drb_start_) output = Vedeu::Terminal.open do Vedeu::Terminal.set_cursor_mode Vedeu.trigger(:_initialize_) runner { main_sequence } end Vedeu.trigger(:_drb_stop_) output end |