Class: Vedeu::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/application.rb

Overview

Orchestrates the running of the main application loop.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Application

:nocov:

Parameters:



36
37
38
# File 'lib/vedeu/application.rb', line 36

def initialize(configuration)
  @configuration = configuration
end

Instance Attribute Details

#configurationConfiguration (readonly, private)

Returns:



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.

Parameters:



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.

Parameters:



9
10
11
# File 'lib/vedeu/application.rb', line 9

def self.start(configuration)
  new(configuration).start
end

.stopvoid

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_sequencevoid (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_manyvoid (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

#runnervoid (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

#startArray

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.

Returns:

  • (Array)

    The last output sent to the terminal.



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