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 private
Class Method Summary collapse
- .restart(configuration) ⇒ void
- .start(configuration) ⇒ void
-
.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:.
-
#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:
36 37 38 |
# File 'lib/vedeu/application.rb', line 36 def initialize(configuration) @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Configuration (readonly, private)
70 71 72 |
# File 'lib/vedeu/application.rb', line 70 def configuration @configuration end |
Class Method Details
.restart(configuration) ⇒ void
This method returns an undefined value.
15 16 17 |
# File 'lib/vedeu/application.rb', line 15 def self.restart(configuration) new(configuration).start end |
.start(configuration) ⇒ void
This method returns an undefined value.
9 10 11 |
# File 'lib/vedeu/application.rb', line 9 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.
27 28 29 30 31 |
# File 'lib/vedeu/application.rb', line 27 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.
94 95 96 97 98 99 100 101 102 |
# File 'lib/vedeu/application.rb', line 94 def main_sequence if configuration.interactive? 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.
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/vedeu/application.rb', line 109 def run_many MainLoop.start! { yield } rescue ModeSwitch Terminal.switch_mode! Vedeu.trigger(:_drb_restart_) 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).
76 77 78 79 80 81 82 83 84 |
# File 'lib/vedeu/application.rb', line 76 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.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/vedeu/application.rb', line 51 def start Vedeu.trigger(:_drb_start_) output = Terminal.open do Terminal.set_cursor_mode Vedeu.trigger(:_initialize_) runner { main_sequence } end Vedeu.trigger(:_drb_stop_) output end |