This is a ruby interface to the cdialog
program, supporting all the
features and widget types offered by that program.
Thomas Dickey's dialog program (commonly called cdialog
) has many
more options than the standard dialog
program, and supports all the
extra widget types introduced by Xdialog
. It also supports color, as
well as other features.
Options are divided into two types: common options and widget options. Common options affect the operation of the program as a while, while widget options only affect the immediately preceding widget on the command line.
A class called CDialog::Common
contains the common options, and
provides functions for setting their values.
For each widget type, there is a class (e.g., CDialog::Msgbox
) which
holds the paramaters and options specified for that options. Each widget
class new
function takes a CDialog::Common
instance as its first
parameter; for a chain of widgets to be executed in one cdialog run, only
the first widget would have common options, and the rest would be passed
nil
. An array of widgets can be chained together like this using the
class function CDialog::chain(arr)
.
The cdialog program is executed with the specified options and its standard
error output is available to be read (the CDialog::Gauge
widget is an
exception - it is the only widget that is written to, not read from). This
is done by the CDialog::Base#run
method.
When the cdialog program exits, the run
method returns an array of two
elements (a pair): the first is the exit status of the program (which can be
influenced by environment variables, see the man page for cdialog(1)
for complete details), and the second is the output of the block passed to
the method; this will most often be the program's standard error output (its
standard output is busy drawing the screen).
The code to create a message box saying "Hello, Sailor!" would look like this:
require "cdialog" c = CDialog::Common.new c.title("Hello from Ruby").backtitle("Hello from CDialog") mb = CDialog::Msgbox.new(c, "Hello Sailor!") resultarray = mb.run { |dialog| dialog.stderr.readlines } p resultarray exit(resultarray.first)
This program prints the output
[0, []]
when the "OK" button is pressed.
The ruby-cdialog package is conveniently available from