Class: Vedeu::Runtime::Application Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Orchestrates the running of the main application loop.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVedeu::Runtime::Application

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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



50
# File 'lib/vedeu/runtime/application.rb', line 50

def initialize; end

Class Method Details

.restartvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.



21
22
23
# File 'lib/vedeu/runtime/application.rb', line 21

def restart
  new.start
end

.startvoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.



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

def start
  new.start
end

.stopvoid Also known as: exit

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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


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

def stop
  Vedeu.trigger(:_cleanup_)

  Vedeu::Runtime::MainLoop.stop!
end

Instance Method Details

#main_sequencevoid (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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 Vedeu.config.interactive?
    Vedeu::Input::Capture.read

  else
    Vedeu.trigger(:_standalone_)
    Vedeu.refresh

  end
end

#run_many(&block) ⇒ void (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.

Parameters:

  • block (Proc)


120
121
122
123
124
125
# File 'lib/vedeu/runtime/application.rb', line 120

def run_many(&block)
  Vedeu::Runtime::MainLoop.start! { yield }

rescue Vedeu::Error::ModeSwitch
  Vedeu::Runtime::Application.restart
end

#run_once(&block) ⇒ void (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

  • block (Proc)


129
130
131
132
133
# File 'lib/vedeu/runtime/application.rb', line 129

def run_once(&block)
  # Vedeu.debug(binding)

  yield
end

#runner(&block) ⇒ void (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Runs the application loop either once, or forever (exceptions and signals permitting).

Parameters:

  • block (Proc)


84
85
86
87
88
89
90
91
92
# File 'lib/vedeu/runtime/application.rb', line 84

def runner(&block)
  if Vedeu.config.once?
    run_once { yield }

  else
    run_many { yield }

  end
end

#startArray

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/vedeu/runtime/application.rb', line 65

def start
  Vedeu.trigger(:_drb_start_)

  Vedeu::Terminal.open do
    Vedeu::Terminal.set_cursor_mode

    Vedeu.trigger(:_initialize_)

    runner { main_sequence }
  end
end