Class: Vedeu::Runtime::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/vedeu/runtime/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) ⇒ Vedeu::Runtime::Application

Returns a new instance of Vedeu::Runtime::Application.

Parameters:



47
48
49
# File 'lib/vedeu/runtime/application.rb', line 47

def initialize(configuration)
  @configuration = configuration
end

Instance Attribute Details

#configurationVedeu::Configuration (readonly, protected)



80
81
82
# File 'lib/vedeu/runtime/application.rb', line 80

def configuration
  @configuration
end

Class Method Details

.restart(configuration) ⇒ Object

Parameters:



17
18
19
# File 'lib/vedeu/runtime/application.rb', line 17

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

.start(configuration) ⇒ Object

Parameters:



12
13
14
# File 'lib/vedeu/runtime/application.rb', line 12

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

.stopvoid 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.

Examples:

Vedeu.exit


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_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.



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_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.



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

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

#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.



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