Method: Dialog::Base#wait

Defined in:
lib/base.rb

#waitObject

Waits for the user to close/cancel the dialog.

That is, waits for the dialog program to return. Returns self. Use the ok?, cancel?, etc. predicates to determine exit status, like this:

if dlg.wait.ok?
  ...
else
  ...
end

If forking or waiting for the process fails, a SystemCallError is raised. If dialog exits with an error message, a DialogError is raised.



268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# File 'lib/base.rb', line 268

def wait
  raise DialogError, "No dialog to wait for" unless @pid

  pid, status = Process.wait2(@pid)
  @exitstatus = status.exitstatus
  @output = @stderr.read

  if @exitstatus == 255
    # Raise an exception if dialog printed an error message
    # If not, the user just exited the dialog using ESC
    raise DialogError.new(commandline_arguments), @output unless @output.empty?
  end

  case @exitstatus
    when Ok then
      handlers[:ok].call(self, @output) if handlers[:ok]
      handlers[:yes].call(self, @output) if handlers[:yes]
    when Cancel then
      handlers[:cancel].call(self, @output) if handlers[:cancel]
      handlers[:no].call(self, @output) if handlers[:no]
    when Extra then
      handlers[:extra].call(self, @output) if handlers[:extra]
    when Help then
      handlers[:help].call(self, @output) if handlers[:help]
  end
  self
ensure
  @pid = @stdin = @stderr = nil
end