## 10.6. GUI Interfaces

The screen shots and explanation for this section were supplied by Steve Kirkendall. We thank him.

elvis's X11 interface provides a scrollbar and mouse support, and allows you to select which fonts to use. There is no way to change fonts after elvis has created the first window. The fonts must all be monospace fonts, typically some variation of a Courier or "fixed" font.

elvis 2.0's X11 interface supports multiple fonts and colors, a blinking cursor that changes shape to indicate your editing mode (insert vs. command), a scrollbar, and mouse actions. The mouse can be used for selecting text, cutting and pasting between applications, and performing tag searches.

elvis 2.1 adds a configurable toolbar, dialogue windows, a status bar, and the `-client` flag. It also works better on monochrome X terminals.

Because elvis 2.1 has a significantly improved X11 interface over 2.0, and because it should be released by the time this book is published, details in the rest of this section apply to it. A number of features, several command-line options, and the ability to configure elvis via X resources are all missing from Version 2.0.

### 10.6.1. The Basic Window

The basic elvis window is shown in Figure 10.1.

#### Figure 10.1. The elvis GUI window

elvis provides a separate text search pop-up dialogue box, which is shown in Figure 10.2.

#### Figure 10.2. The elvis search dialogue

The look and feel are intended to resemble Motif, but elvis doesn't actually use the Motif libraries.

Command-line options let you choose the four different fonts that elvis uses, normal, italic, bold, and "control," which is the font for the toolbar text and button labels. You may also specify foreground and background colors, the initial window geometry, and whether elvis should start out iconified.

The new `-client` option causes elvis to look for an already running elvis process, and send it a message requesting it to start editing the files named on the command line. Doing it this way allows you to share yanked text and other information between the files elvis is currently editing and the new files.

Besides the toolbar, there is also a status bar that displays status messages and any available information about toolbar buttons.

### 10.6.2. Mouse Behavior

The mouse behavior tries to strike a balance between xterm(1) and what makes sense for an editor. To do this correctly, elvis distinguishes between clicking and dragging.

Dragging the mouse always selects text. Dragging with button 1 pressed (usually the left button) selects characters, dragging with button 2 (the middle button) selects a rectangular area, and dragging with button 3 (usually the right button) selects whole lines. These operations correspond to elvis' `v`, `^V`, and `V` commands, respectively. (These commands are described later in this chapter.) When you release the button at the end of the drag, the selected text is immediately copied into an X11 cut buffer, so you can paste it into another application such as xterm. The text remains selected, so you can apply an operator command to it.

Clicking button 1 cancels any pending selection, and moves the cursor to the clicked-on character. Clicking button 3 moves the cursor without canceling the pending selection; you use this to extend a pending selection.

Clicking button 2 "pastes" text from the X11 cut buffer (like xterm). If you're entering an ex command line, the text will be pasted into the command line as though you had typed it. If you're in visual command mode or input mode, the text will be pasted into your edit buffer. When pasting, it doesn't matter where you click in the window; elvis always inserts the text at the position of the text cursor.

Double-clicking button 1 simulates a `^]` keystroke, causing elvis to perform tag lookup on the clicked-on word. If elvis happens to be displaying an HTML document, then tag lookup pursues hypertext links, so you can double-click on any underlined text to view the topic that describes that text. Double-clicking button 3 simulates a `^T` keystroke, taking you back to where you did the last tag lookup.

### 10.6.3. The Toolbar

The X11 interface supports a user-configurable toolbar. By default, the toolbar is enabled unless your ~/.exrc file has a `set notoolbar` command.

The default toolbar already has some buttons defined. You use the `:gui` command to reconfigure the toolbar.

There are a number of commands. In particular, you can reconfigure the toolbar to suit your tastes, deleting one or all of the existing buttons, adding new ones, and controlling the spacing between buttons or groups of buttons. Here is a simple example:

>     :gui Make:make
>     :gui Make " Rebuild the program
>     :gui Quit:q
>     :gui Quit?!modified

These commands add two new buttons. The first line adds a button named "Make," which will execute the `:make` command when pressed. (The `:make` command is described later in this chapter.) The second line adds descriptive text for the "Make" button that shows up in the status line when the button is pressed. In this case, the `"` does not start a comment; rather it is an operator for the `:gui` command.

The second button, named "Quit," is created by the third line. It exits the program. The fourth line changes its behavior. If the condition (`!modified`) is true, the button will behave normally. But if it's false, the button will ignore any mouse clicks, and it will also be displayed as being "flat," instead of having the normal 3-D appearance. Thus, if the current file is modified, you won't be able to use the "Quit" button to exit.

You can create pop-up dialogues that appear when a toolbar button is pressed. The dialogue can set the value(s) of pre-defined variables (options) that can then be tested from the ex command associated with the button. There are 26 pre-defined variables, named `a-z`, that are set aside for user "programs" of this sort to use. This example associates a dialogue with a new button named "Split":

>     :gui Split"Create a new window, showing a given file
>     :gui Split;"File to load:" (file) f = filename
>     :gui Split:split (f)

The first command associates descriptive text with the "Split" button. The second command creates the pop-up dialogue: its prompt is File to load: and it will set the `filename` option. The `(file)` indicates that any string may be entered, but that the TAB key may be used for filename completion. The `f = filename` copies the value of `filename` into `f`. Finally, the third command actually executes the `:split` command on the value of `f`, which will be the new filename supplied by the user.

The facility is quite flexible; see the online help for the full details.

### 10.6.4. Options

A large number of options control the X11 interface. You typically set these in your .exrc file. There are options and abbreviations for setting the various fonts, enabling and configuring the toolbar, status bar, scrollbars, and the cursor. Other options control the cursor's behavior when you switch windows with `^W ^W` and whether the cursor goes back to the original xterm when elvis exits.

The online documentation describes all of the X11-related ex options. Here, we describe some of the more interesting ones:

`autoiconify`

  Normally, when the `^W ^W` command switches focus to an iconified window, that window is de-iconified. When `autoiconify` is true, elvis will iconify the old window, so that the number of open elvis windows remains constant.

`blinktime`

  The value is a number between 1 and 10 that indicates for how many tenths of a second the cursor should be visible and then invisible. A value of 0 disables blinking.

`firstx`, `firsty`, `stagger`

  `firstx` and `firsty` control the position of the first window that elvis creates. If not set, the `-geometry` option or the window manager controls placement. If `stagger` is set to a non-zero value, any new windows are created that many pixels down and to the right of the current window. Setting it to zero lets the window manager to do the placement.

`outlinemono`

  When set, elvis provides a white outline around characters when using a monochrome X display. This makes text easier to read. The value can range from 0 for no outline to 3 for the heaviest; the default is 2. This option has no effect on color displays.

`stopshell`

  Stores a command which runs an interactive shell, for the `:shell` and `:stop` ex commands, and the `^Z` visual command. The default value is `xterm &`, which starts an interactive terminal emulator in another window.

`xscrollbar`

  Values `left` and `right` place the scrollbar on the indicated side of the window, while `none` disables the scrollbar. The default is `right`.

elvis 2.1 adds the ability to be configured via X resources. The resource values can be overridden by command-line flags, or by explicit `:set` or `:color` commands in the initialization scripts. elvis's resources are listed in Table 10.4.

#### Table 10.4. elvis X Resources

Resource Class |  | Default
--- | --- | ---
(Name is lowercase of class) | Type | Value
Elvis.Toolbar | Boolean | true
Elvis.Statusbar | Boolean | true
Elvis.Font | Font | fixed
Elvis.Geometry | Geometry | 80x34
Elvis.Foreground | Color | black
Elvis.Background | Color | gray90
Elvis.MultiClickTimeout | Timeout | 3
Elvis.Control.Font | Font | variable
Elvis.Cursor.Foreground | Color | red
Elvis.Cursor.Selected | Color | red
Elvis.Cursor.BlinkTime | Timeout | 3
Elvis.Tool.Foreground | Color | black
Elvis.Tool.Background | Color | gray75
Elvis.Scrollbar.Foreground | Color | gray75
Elvis.Scrollbar.Background | Color | gray60
Elvis.Scrollbar.Width | Number | 11
Elvis.Scrollbar.Repeat | Timeout | 4
Elvis.Scrollbar.Position | Edge | right

The "Timeout" type gives a time value, in tenths of a second. The "Edge" type gives a scrollbar position, one of `left`, `right`, or `none`.

For example, if your X resource database contains the line `elvis.font: 10x20`, the default text font would be `10x20`. This value would be used if the `normalfont` option was unset.

Copyright © 2003 O'Reilly & Associates. All rights reserved.