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.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVedeu::Runtime::Application

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



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

def initialize; end

Class Method Details

.restartvoid

This method returns an undefined value.



19
20
21
# File 'lib/vedeu/runtime/application.rb', line 19

def restart
  new.start
end

.startvoid

This method returns an undefined value.



14
15
16
# File 'lib/vedeu/runtime/application.rb', line 14

def start
  new.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


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

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.



97
98
99
100
101
102
103
104
105
106
# File 'lib/vedeu/runtime/application.rb', line 97

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 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)


114
115
116
117
118
119
# File 'lib/vedeu/runtime/application.rb', line 114

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

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

#runner(&block) ⇒ void (private)

This method returns an undefined value.

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

Parameters:

  • block (Proc)


82
83
84
85
86
# File 'lib/vedeu/runtime/application.rb', line 82

def runner(&block)
  return yield if Vedeu.config.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.



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

def start
  Vedeu.trigger(:_drb_start_)

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

    Vedeu.trigger(:_initialize_)

    runner { main_sequence }
  end
end