Elements of a Console UI application

A Console UI application can use several different types of EGL parts to supply data and several different types of EGL variables to create the interface.

Like many types of applications with user interfaces, EGL Console UI applications separate the interface from the logic used to create that interface. An ordinary EGL program provides the logic for the application, while several different types of parts can represent the interface itself.

Console UI forms and fields

A ConsoleForm part is a record of fields to be shown on the user interface. The fields in this type of record do not store data or have a data type such as INT like the fields in other types of records. Instead, the fields in a ConsoleForm define the location and label of the fields that are shown on the screen. As a group, these fields are sometimes referred to as a form. The Console UI program links the fields on the screen with other EGL variables.

A field in a console UI record can be as simple as a name, a length in characters, and a position on the screen. For example, here is a simple Console UI record that defines a form:
Record CustomerConsoleRecord type consoleForm 
                        {formSize = [10,40],name = "Customer Record"}
  *        consoleField {position = [1,4], 
                         value = "Welcome to my console."};
  ID       consoleField {fieldLen = 5, position = [3,4], 
                         name="customer_id"};
  Fname    consoleField {fieldLen = 20, position = [4,4], 
                         name="first_name"};
  Lname    consoleField {fieldLen = 20, position = [5,4], 
                         name="last_name"};
  PhoneNum consoleField {fieldLen = 20, position = [6,4], 
                         name="phone"};
end
Of the five fields in this form, one is a constant string of text; it cannot change at run time. This field is named with an asterisk (*) and serves as header or explanatory text, in this case "Welcome to my console." The other fields are variable; a Console UI program can use them to display data or accept input.

Menu and MenuItem parts

In Console UI, a menu is a set of options from which the user is expected to choose one. When showing a menu on the interface, you define a menu part and then define the options as an array of menuItem parts in the menuItems menu property. For example, the following menu defines three options from which the user can choose:
new Menu {labelText = "Choose an option: ", 
    menuItems = [
    new MenuItem{name = "One", labelText = "Option One"},
    new MenuItem{name = "Two", labelText = "Option Two"},
    new MenuItem{name = "Three", labelText = "Option Three"}
    ]}

See Creating a Console User Interface for an example of how to respond when the user selects one of the options.

ArrayDictionary part

An ArrayDictionary is a type of EGL part that is often used to represent data in Console UI. Unlike an array of records, in which you define one record part that represents a row and then create an array of those rows, in an ArrayDictionary, you define arrays of consoleFields that represent the columns. Defining data by the columns can be useful in Console UI because ArrayDictionaries scroll automatically in the limited space on a Console UI window.

A detailed example of an ArrayDictionary in Console UI is available at Using an array dictionary in Console UI.

A detailed example of an ArrayDictionary in Console UI is available at "Using an array dictionary in Console UI" in the EGL Language Reference.

Console UI program

The Console UI program is an ordinary EGL program that creates and controls the interface. In general, it creates a Window variable, uses functions in the EGL library ConsoleLib to display that window, and then populates that window with parts that represent the interface, such as ConsoleForm parts. Here is a simple example of a Console UI program that uses the sample ConsoleForm part described above:
program CreateAConsole type BasicProgram

  function main()

    // Step 1: Create a variable for the form.
    myConsoleUIRecord CustomerConsoleRecord;
    // Step 2: Create a window, but don't open it yet.
    myWindow window {name="My Window", position=[1,1]};
    // Step 3: Create variables for the form fields.
    customer_id int;
    first_name, last_name, phone char(30);

    // Step 4: Open the window and open the form inside the window.
    consoleLib.openWindowWithForm(myWindow,myConsoleUIRecord);
    // Step 5: Link the variables to the fields in the form.
    openUI myConsoleUIRecord
      bind customer_id, first_name, last_name, phone
    end

  end

end

For more information on using Console UI programs, see Creating a Console User Interface.

The EGL Plug-in project

With EGL, you can run your Console UI projects in a variety of modes. If you want to run your Console UI application in rich client application (RCP) mode, you need to convert your project to an EGL plug-in project.

For more information about the modes you can run your Console UI application in, see Console UI modes. For more information on EGL plug-in projects, see Creating an EGL plug-in project.


Feedback