4

The xterm Terminal Emulator

xterm provides you with a terminal within a window. Anything you can do using a standard terminal, you can do in an xterm window. Once you have an xterm window on your screen, you can use it to run other clients.

You can bring up more than one xterm window at a time. For example, you might want to list the contents of a directory in one window while you edit a file in another window. Although you can display output simultaneously in several windows, you can type into only one window at a time.

Basic operation of xterm should be obvious to anyone familiar with a terminal. You should be able to work productively immediately.

Among the less obvious features of xterm is a dual functionality. By default, xterm emulates a DEC VT102 terminal, a common alphanumeric terminal type. However, xterm can also emulate a Tektronix 4014 terminal, which is used to display graphics. For each xterm process, you can switch between these two types of terminal windows. You can display both a VT102 and a Tektronix window at the same time, but only one of them can be the “active” window, i.e., the window receiving input and output. Hypothetically, you could be editing in the VT102 window while looking at graphics in the Tektronix window.

You switch between the VT102 window and the Tektronix window using items from certain xterm menus. The xterm client has four menus that can be used to manipulate the VT102 and Tek windows, to select many terminal settings, and to run other commands that affect the xterm process. We’ll take a look at some of the more useful items on each menu as well as some alternatives to menu items. For more complete information about menus, see the xterm reference page in Part Three of this guide.

We’ll also discuss two of xterm’s more important features: a scrollbar, which allows you to review text in the window, and a “copy and paste” facility.

Finally, we’ll consider problems involved in resizing an xterm window and how to run a program in a temporary xterm window.

The Release 4 xterm Menus

The Release 4 version of xterm has four different menus:

•   Main Options menu (formerly called xterm menu).

•   VT Options menu (formerly called Modes menu).

•   VT Fonts menu (available as of Release 4).

•   Tek Options menu (formerly called Tektronix menu).

The VT Fonts menu, which allows you to dynamically change the xterm display font, was introduced in Release 4. The other three menus are updated versions of menus available in Release 3. As is indicated above, these three menus have been renamed in Release 4. Most of the items available on these menus have not changed in functionality since Release 3, though many have been renamed and some have been reorganized.

For instance, the R3 xterm menu offered an item called Redraw; the R4 Main Options menu offers the same item, renamed Redraw Window. The Visual Bell item available on the R3 xterm menu in R4 has been renamed Enable Visual Bell and moved to the VT Options menu, a more logical location.

A few menu items are entirely new as of Release 4. This chapter describes the R4 xterm menus. For those who are still running Release 3, we’ve tried to point out the differences: the equivalent R3 menu and item names, what items have been moved within a menu or to another menu, and what items are only available in R4.

The xterm Menus at a Glance

As shown in Figure 4-1, three of the four xterm menus are divided into sections, separated by horizontal lines. The top portion of each divided menu contains various modes that can be toggled. (The one exception is the Redraw Window item (formerly Redraw) on the Main Options menu, which is a command.) A check mark appears next to a mode that is currently active. Selecting one of these modes toggles its state.

The items on the VT Fonts menu change the font in which text is displayed in the xterm window. Only one of these fonts can be active at a time. To toggle one off, you must activate another.

Most mode entries can also be set by command line options when invoking xterm, or by entries in a resource startup file (such as .Xdefaults or .Xresources) as described in Chapter 9, Setting Resources. (See the xterm reference page in Part Three of this guide for a complete list of command options and resource variables.) The various modes on the menus are very helpful if you’ve set (or failed to set) a particular mode on the command line and then decide you want the opposite characteristic.

The sections below the modes portion of each menu contain various commands. Selecting one of these commands performs the indicated function. Many of these functions can only be invoked from the xterm menus. However, some functions can be invoked in other ways: from a twm menu, on the command line, by a sequence of keystrokes (such as Control-C). This chapter includes alternatives to some of the menu items, alternatives which in certain cases may be more convenient. Of course, the xterm menus can be very helpful when other methods to invoke a function fail.

images

Figure 4-1. The Release 4 xterm menus

Menus are displayed by pressing a combination of keyboard keys and pointer buttons. (The exact combination of keys and buttons is described below with each menu.) When you display an xterm menu, the pointer becomes the arrow pointer and initially appears in the menu’s title. Once the menu appears, you can release any keyboard key. The menu will remain visible so long as you continue to hold down the appropriate pointer button.

If you decide not to select a menu item after the menu has appeared, move the pointer off the menu and release the button. The menu disappears and no action is taken.

In the following discussions of the four xterm menus, we’ll consider some of the more useful items as well as some alternatives to menu items. For more complete information about each menu, see the xterm reference page in Part Three of this guide.

The Main Options Menu

The Main Options menu, shown in Figure 4-2, (formerly called the xterm menu) allows you to set certain modes and to send signals (such as SIGHUP) that affect the xterm process.

To bring up the Main Options menu, move the pointer to the xterm window you wish to effect changes on, hold down the Control key, and press the first (usually the left) pointer button.* The pointer changes to the menu pointer, and the following menu of three modes and eight commands appears. (You can release the Control key but must continue to press the first pointer button to hold the Main Options menu in the window.)

Note that Main Options menu items apply only to the xterm window the pointer is in when you display the menu. To effect changes in another xterm, you must move the pointer to that window, display the menu, and specify the items you want.

images

Figure 4-2. The Main Options menu

To select a menu item, move the menu pointer to that item and release the first button. After you have selected a mode (Secure Keyboard, Allow SendEvents, or Log to File), a check mark appears before the item to remind you that it is active. The Log to File mode on the Main Options menu can also be set by a command line option when invoking xterm. In addition, both Log to File and Allow SendEvents can be set by entries in a resource startup file like .Xresources (see Chapter 9, Setting Resources). The menu selections enable you to change your mind once xterm is running. (See the xterm reference page in Part Three of this guide for more information on these modes.)

The Secure Keyboard mode toggle has been added to the menu (in a Release 3 patch) to help counteract one of the security weaknesses of X. This mode is intended to be activated when you want to type a password or other important text in an xterm window. Generally, when you press a keyboard key or move the pointer, the X server generates a packet of information that is available for other clients to interpret. These packets of information are known as events. Moving the pointer or pressing a keyboard key causes input events to occur.

There is an inherent security problem in the client-server model. Because events such as the keys you type in an xterm window are made available via the server to other clients, hypothetically an adept system hacker could access this information. (Naturally, this is not an issue in every environment.) A fairly serious breach of security could easily occur, for instance, if someone were able to find out a user’s password or the root password. Enabling Secure Keyboard mode causes all user input to be directed only to the xterm window itself.

Of course, in many environments, this is probably not necessary: if the nature of the work is in no way sensitive, if the system administrator has taken pains to secure the system in other ways, etc. If your environment might be vulnerable, you can enable Secure Keyboard mode before typing passwords and other important information and then disable it again using the menu.

When you enable Secure Keyboard mode, the foreground and background colors of the xterm window wm be exchanged (as if you had enabled the Reverse Video mode from the VT Options menu), as shown in Figure 4-3. When you disable Secure Keyboard mode, the colors will be switched back.

Be aware that only one X client at a time can secure the keyboard. Thus, if you have enabled Secure Keyboard mode in one xterm, you will not be allowed to enable it in another xterm until you disable it in the first. If Secure Keyboard mode is not available when you request it, the colors will not be switched and a bell will sound.

If you request Secure Keyboard mode and are not refused, but the colors are not exchanged, be careful: you are not in Secure Keyboard mode. If this happens, there’s a good chance that someone has tampered with the system. If the application you’re running displays a prompt before asking for a password, it’s a good idea to enable Secure Keyboard mode before the prompt is displayed and then verify that the prompt is displayed in the proper colors. Before entering the password, you can also display the Main Options menu again and verify that a check mark appears next to Secure Keyboard mode.

Be aware that Secure Keyboard will be disabled automatically if you iconify the xterm window, or start twm or another window manager that provides a titlebar or other window decoration. This limitation is due to the X protocol. When the mode is disabled, the colors will be switched back and the bell will sound to warn you.

In addition to modes that can be toggled, the Main Options menu includes several commands. All of the commands (except for Redraw Window) send a signal that is intended to affect the xterm process: suspend it (Send STOP Signal), terminate it (Send TERM Signal), etc. Given that your operating system may recognize only certain signals, every menu item may not produce the intended function.

Note that most of these commands are equivalent to common keystroke commands, which are generally simpler to invoke. For example, in most terminal setups, Control-C can be used to interrupt a process. This is generally simpler than using the Send INT Signal menu command (Interrupt program in prior releases), which performs the same function.

images

Figure 4-3. Reverse video is enabled when the keyboard is secure

Similarly, if your system supports job control, you can probably suspend a process by typing Control-Z and start the process again by typing Control-Y, rather than using the Send STOP Signal and Send CONT Signal menu commands. (These commands were called Suspend program and Continue program in Release 3.) If your system does not support job control, neither the menu commands nor the keystrokes will work.

Four of the commands (Send HUP Signal, Send TERM Signal, Send KILL Signal, and Quit*) send signals that are intended to terminate the xterm window. Depending on the signals your system recognizes, these commands may or may not work as intended. Be aware that in most cases, you can probably end an xterm process simply by typing some sequence (such as Control-D or exit) in the window. Of course, the menu items may be very helpful if the more conventional ways of killing the window fail. Also be aware that, in addition to being recognized only by certain systems, some signals are more gentle to systems than others. See the xterm reference page in Part Three of this guide for information on the signal sent by each of the menu commands and the signal(3C) reference page in the UNIX Programmer’s Manual for more information on what each signal does.

The Quit command sends the SIGHUP signal to the process group of the process running under xterm, usually the shell. (The Send HUP Signal command sends the same signal.) This ends up killing the xterm process, and the window disappears from the screen.

Quit is separated from the earlier commands by a horizontal line, so it’s easier to point at. Sending a SIGHUP signal with Quit is also slightly more gentle to the system than sending a SIGKILL signal with Send KILL Signal.

The Redraw Window command redraws the contents of the window. As an alternative, you can redraw the entire screen using the xrefresh client. See the xrefresh reference page in Part Three of this guide for more information about this client.

If you are still using the uwm window manager, the Redraw and Refresh Screen selections of the WindowOps menu redraw a selected window and the entire screen, respectively. See Appendix B, The uwm Window Manager, for more about these uwm menu items.

VT Options Menu

The VT Options menu (formerly the Modes menu) provides many VT102 setup functions. Some of these mode settings are analogous to those available in a real VT102’s setup mode; others, such as scrollbar, are xterm-only modes.

The VT Options menu items allow you to reset several modes at once, to select the Tektronix window to accept input, and to hide the VT window.

The Release 4 version of this menu is very similar to the Release 3 version. A majority of the mode toggles have been renamed by adding the first word “Enable.” For example, Jump Scroll has been renamed Enable Jump Scroll, making it more apparent when a check mark precedes it that the mode is active. The names of a few of the other items have been changed slightly: Enable Visual Bell has been added from the Main Options menu, and Show Tek Window has been moved from the mode toggles section of the menu below to the commands section.

To bring up the VT Options menu, move the pointer to the xterm window, hold down the Control key, and then press and hold down the middle pointer button. (You can release the Control key but must continue to press the middle button to keep the VT Options menu in the window.) The menu shown in Figure 4-4 appears.

Check marks indicate the active modes. For example, Jump Scroll, Auto Wraparound, and Scroll to Bottom on Tty Output are active in the VT Options menu displayed in Figure 4-4. (These are the only modes active by default. In Release 3, Scroll to Bottom on Tty Output was not active by default.*) To turn off one of these modes, move the menu pointer to that mode and release the middle button.

images

Figure 4-4. The VT Options menu

Most of these modes can also be set by command line options when invoking xterm. or by entries in a resource startup file like .Xresources (see Chapter 9, Setting Resources). The menu selections enable you to change your mind once xterm is running.

The toggle Allow 80/132 Column Switching warrants a little more explanation. This mode allows xterm to recognize the DECCOLM escape sequence, which switches the terminal between 80- and 132-column mode. The DECCOLM escape sequence can be included in a program (such as a spreadsheet) to allow the program to display in 132-column format. See Appendix F, xterm Control Sequences, for more information. This mode is off by default.

The VT Options menu commands (in the second and third partitions of the menu) perform two sets of functions, neither of which can be performed from the command line or a resource definition file. The commands Soft Reset and Full Reset reset some of the modes on the menu to their initial states. See the xterm reference page in Part Three of this guide for more information.

The Show Tek Window, Switch to Tek Mode, and Hide VT Window menu items allow you to manipulate the Tektronix and VT102 windows.

The Show Tek Window command displays the Tek window and its contents, without making it the active window (you can’t input to it). Use the Switch to Tek Mode command to display a Tektronix window and make it the active window. When you select Switch to Tek Mode, the Show Tek Window command is enabled automatically, since the Tek window is displayed. (Note that a Tektronix window is not commonly used for general purpose terminal emulation, but for displaying the output of graphics or typesetting programs.)

Both of these commands are toggles. If Show Tek Window is active and you toggle it off, the Tek window becomes hidden. (As we’ll see, you can also do this with the Hide Tek Window item on the Tek Options menu.) If both Switch to Tek Mode and Show Tek Window are active (remember, enabling the former automatically enables the latter), toggling either one of them off switches the xterm back to VT mode. (This can also be done from the Tek Options menu with the Switch to VT Mode item.)

The Hide VT Window command hides the VT102 window, but does not destroy it or its contents. It can be restored (and made the active window) by choosing Select VT Mode from the Tek Options menu.

VT Fonts Menu

The VT Fonts menu is a welcome Release 4 innovation. It allows you to change the display font of an xterm window while the window is running. To bring up the VT Fonts menu, move the pointer inside the xterm window. Press the Control key on the keyboard; while holding down the Control key, press the third (right) pointer button. The VT Fonts menu is shown in Figure 4-5.

images

Figure 4-5. VT Fonts menu

If you have not toggled any items on this menu, a check mark will appear before the Default mode setting. The Default is the font that was specified when the xterm window was run. This font could have been specified on the xterm command line or in a resource file like X resources. Whatever the case, this font remains the Default for the duration of the current xterm process.

The items Default, Tiny, Small, Medium, and Large can be toggled to set the font displayed in the xterm window. The font can be changed any number of times, to accommodate a variety of uses. You might choose to use a large font for editing a file (chances are you’ve chosen a large enough default font, though). You could then change to a smaller font while a process is running and you don’t need to be reading or typing in that xterm. Changing the font also changes the size of the window.

There are also default settings for the Tiny, Small, Medium, and Large fonts. They are all constant width fonts from the directory /usr/lib/X11/fonts/misc and are listed in Table 4-1.

Table 4-1. VT Fonts Menu Defaults

Menu Item Default Font
Tiny nil2
Small 6×10
Medium 8×13
Large 9×15

Bring up the VT Fonts menu, and toggle some of these fonts to see what they look like. The default Tiny font, nil2, is actually too small to be legible. It is not intended to be read. If you select this font, your xterm window becomes tiny, almost the size of some application icons. Though you cannot read the actual text in a window this size, the window is still active and you can observe if additional output, albeit minuscule, is displayed. An xterm window displaying text in such a small font can serve, in effect, as an active icon.

Be aware that you can specify your own Tiny, Small, Medium, and Large fonts using entries in a resource startup file like .Xresources. The corresponding resource names are font 1, font2, font3, and font4. See Chapter 5, Font Specification, for more information about available fonts. See Chapter 9, Setting Resources, for instructions on how to set resource variables.

In addition to the menu selections we’ve discussed, the VT Fonts menu offers two other possible selections: Escape Sequence and Selection. When you first run an xterm window, these selections appear on the VT Fonts menu, but they are not functional. (They will appear in a lighter typeface than the other selections, indicating that they are not available.) In order to enable these selections for use, you must perform certain actions, which are outlined in Chapter 5, Font Specification, after we discuss font specification in greater detail.

Tek Options Menu

The Tek Options menu (formerly Tektronix) controls certain modes and functions of the Tektronix window. The menu can only be displayed from within the Tektronix window. As previously described, you can display the Tek window and make it the active window by using the Switch to Tek Mode command on the VT Options menu.

To display the Tek Options menu, move the pointer inside the Tektronix window. Press the Control key on the keyboard; while holding down the Control key, press the middle pointer button. The Tek Options menu appears. With this menu, you set the size of the text in the Tektronix window and select some commands.

images

Figure 4-6. The Tek Options menu

Note that these modes (above the first line) can only be set from the Tek Options menu. All of these modes set the point size of the text displaying in the Tektronix window. (Only one of these four modes can be enabled at any time.)

The most important command on the Tek Options menu, shown in Figure 4-6, is Switch to VT Mode (formerly Select VT Mode). If the Tek window has been made the active window (using the Switch to Tek Mode command from the VT Options menu), you can choose Switch to VT Mode to make the VT window the active window again. (If both windows are showing, you can also toggle Switch to Tek Mode on the VT Options menu to deactivate it; that is, switch from Tek mode and back to VT mode.) Switch to VT Mode is also a toggle; if you deactivate it, xterm will switch back to Tek mode.

Selecting Show VT Window (formerly VT Window Showing), displays the VT window if it has been hidden (using the Hide VT Window command from the VT Options menu), or hides it if it is being displayed. (Again, the command is a toggle.) Remember that you cannot input to the VT window until you make it the active window, using Switch to VT Mode.

Using the Scroll bar

When using xterm, you are not limited to viewing the 24 lines displayed in the window. By default, xterm actually remembers the last 64 lines that have appeared in the window. If the window has a scrollbar, you can scroll up and down through the saved text. If the window was not created with a scrollbar, you can add one using the Enable Scrollbar item on the VT Options menu.

To create a single xterm window with a scrollbar, use the -sb command line option:

% .xterm -sb &

To display all xterm windows with a scrollbar by default, set scrollBar in your X resources file, as described in Chapter 9, Setting Resources. This is illustrated below:

XTerm*scrollBar: true

Figure 4-7 shows an xterm window with a scrollbar.

images

Figure 4-7. An xterm window with a scrollbar

The thumb (the highlighted area within the scrollbar) moves within the scroll region. The thumb displays the position and amount of text currently showing in the window relative to the amount saved. When an xterm window with a scrollbar is first created, the thumb fills the entire scroll bar. As more text is saved, the size of the thumb decreases. The number of lines saved is 64 by default, but an alternative can be specified with either the -sl command line option or the saveLines value in an .Xresources file.

When the pointer is positioned in the scrollbar, the cursor changes to a two-headed arrow. Clicking the first (usually the left) pointer button in the scrollbar causes the window to scroll toward the end of information in the window.

Clicking the third (usually the right) pointer button in the scrollbar causes the window to scroll toward the beginning of information in the window.

Clicking the second (usually the middle) pointer button moves the display to a position in the saved text that corresponds to the pointer’s position in the scroll region. For example, if you move the pointer to the very top of the scroll region and click the second (middle) button, the display is positioned very near the beginning of the saved area.

If you hold down the second button, you can drag the thumb up and down. Text moves as you move the thumb. If you drag up, the window scrolls back, toward the beginning of information in the window. If you drag down, the window scrolls forward, toward the end of information in the window. When you release the button, the window displays the text at that location. This makes it easy to get to the top of the data by pressing the second button, dragging it off the top of the scrollbar, and releasing it.

Copying and Pasting Text Selections

Once your xterm window is created, you can select text to copy and paste within the same or other xterm windows using the pointer. You don’t need to be in a text editor to use copy and paste. You can also copy or paste text to and from the command line.

Text copied into memory using the pointer is saved in a global cut buffer and also becomes what is known as the PRIMARY text “selection.” Both the contents of the cut buffer and the contents of the PRIMARY text selection are globally available to all clients. When you paste text into an xterm window, by default the contents of the PRIMARY selection are pasted. If there is no text in the PRIMARY selection, the contents of the cut buffer (called CUT_BUFFER0), are pasted. (Thus, in most cases, these will be the same.)

Copying and pasting is one way in which clients exchange information, in this case, text. Prior to Release 3, many clients exchanged information solely by means of cut buffers. Cut buffers are only useful for transferring information between clients that interpret data in the same format. Thus, cut buffers could be used to transfer ASCII text between xterm windows. In accordance with the newer interclient communication conventions developed since Release 2, most Release 3 and 4 clients, notably xterm, primarily exchange information via selections. The advantage of the selection mechanism is that it allows data from one client to be converted to a different format to be used by another client. Cut buffers do not perform this type of translation.

As we’ve said, if you are copying text between xterm windows, the contents of CUT_BUFFER0 and the PRIMARY selection should be the same. However, as we’ll see later, while some applications (notably the current version of xterm) copy to both the cut buffer and the selection, other applications (generally prior to Release 3) only copy to the cut buffer. If you are using both types of applications together and trying to transfer text between them, differences between the contents of the cut buffer and the PRIMARY selection may make copying and pasting problematic. If you are only copying text between xterm windows (Release 3 or later), problems of this type will never arise.

For our purposes, we are mainly concerned with ASCII text selections from xterm windows. First, we’ll show you how to copy and paste text between xterm windows. Then we’ll discuss some of the implications of using selections versus cut buffers, and describe two clients, xcutsel and xclipboard, which allow you to manipulate text saved in memory. The xcutsel client addresses problems that arise when you’re copying text between an application that uses selections and one that uses cut buffers. The xclipboard allows you to store multiple text selections.

Selecting Text to Copy

To select text, move the pointer to the beginning of the text you want to select. Hold down the first button while moving the pointer to the end of the desired text, then release the button. The text is highlighted, copied into the global cut buffer (called CUT_BUFFER0) and also made the PRIMARY selection.

Note that with the current implementation of the copy and paste feature, tabs are saved as spaces.

You can select a single word or line simply by clicking. To select a single word, place the pointer on the word and double-click the first button.* To select a single line, place the pointer on the line and triple-click the first button.

If you hold the button down after double- or triple-clicking (rather than releasing it) and move the pointer, you will select additional text by words or lines at a time.

The following table describes the button combinations and the resulting selection. Begin by placing the pointer on your desired selection.

Table 4-2. Button Combinations to Select Text for Copying

To select Do this
Word Double-click the first button.
Line Triple-click the first button.
Passage Hold down the first button, move the pointer, release the button.

Each selection replaces the previous contents of CUT_BUFFER0 and the previous PRIMARY text selection. You can make only one selection at a time.

Once you have made a selection with the first button, you can extend that selection with the third button. The following example shows how this works:

1.   Bring up vi (or any other text editor with which you are familiar) in an xterm window, and type in this sample sentence:

The X Window System is a network-based graphics window system that was developed at MIT in 1984.

2.   Place the pointer on the word graphics in the sample sentence and select it with two clicks of the first button.

3.   Then press and hold the third pointer button. Move the pointer away from the word graphics, to the left or right. A new selection now extends from the last selection (graphics) to the pointer’s location and looks something like the following:

The X Window System is a network-based graphics window system that was developed at MIT in 1984.

or:

The X window System is a network-based graphics window system that was developed at MIT in 1984.

Remember that your extension always begins from your last selection. By moving the pointer up or down, right or left of the last selection, you can use this technique to select part of one line or add or subtract several lines of text.

images

Figure 4-8. Highlighted text saved as the PRIMARY selection

To clear the highlighting, move the pointer off the selection and click anywhere else in the window with the first button. Note, however, that the text still remains in memory until you make another selection.

Pasting Text Selections

The second (middle) button inserts the text from the PRIMARY selection (or CUT_BUFFER0, if the selection is empty) as if it were keyboard input. You can move data from one xterm window to another by selecting the data in one window with the first button, moving the pointer to another window, and clicking the second button.

You can paste text either into an open file or at a command line prompt. To paste text into an open file, as illustrated in Figure 4-9, click the second button within the window containing the file. The text from the memory area will be inserted where the text editor cursor is. (Of course, the file must be in a mode where it is expecting text input, such as the insert mode of an editor.) You can paste the same text as often as you like. The contents of the PRIMARY selection remain until you make another selection.

images

Figure 4-9. Pasting text into an open file

To paste text at a command line prompt, you must first close any open file within the window. Then click the second button anywhere within the window to place the text on the command line at the end of text in the window (note that the window will scroll to the bottom on input).

You can make multiple insertions by repeatedly clicking the second button.

The latest text selected replaces the previous text selected.

You can also paste over existing text with the vi change text commands (such as cw, for change word). For example, you can paste over five words by specifying the vi command Sew, and then pasting text by clicking the second pointer button. Note that you can paste over existing text in any editor that has an overwrite mode.

Manipulating Text Selections

Prior to Release 3, text copied into memory using the pointer was saved in the global cut buffer, in effect, “owned” by the server, and available to all clients. Cut buffers are only useful for copying and pasting information that does not need to be translated to another format, such as ASCII text between two xterm windows.

Since Release 3, text copied into memory from an xterm window is saved in the cut buffer and as the PRIMARY selection. The PRIMARY selection takes precedence over the contents of the cut buffer. When pasting text between xterm windows, if the selection contains text, it is pasted. If not, the contents of the cut buffer are pasted. Selections can be used to transfer data that must be translated to a form the receiving client can interpret.

A selection is globally available, but it is not owned by the server. A selection is owned by a client—initially by the client from which you copy it. Then when the text selection is pasted to another window, that window becomes the owner of the selection.

Because of the rules of precedence governing cut buffers and selections, and the nature of selections (particularly the issue of ownership), certain problems can arise in transferring data:

1.   If one client communicates with cut buffers and one with selections, copying and pasting between them is inherently problematic. By default, the selection takes precedence. How do you paste the contents of the cut buffer instead?

2.   By default, you can save only one selection at a time.

3.   For a selection to be transferred to a client, the selection must be owned by a client. If the client that owns the selection no longer exists, the transfer cannot be made.

The xcutsel and xclipboard clients address the first two of these problems, respectively.

Most users will probably not encounter the third problem. You are probably doing all your copying and pasting between xterm windows. If you’ve made a selection from an xterm window and the window is killed, the selection contents are lost. However, the cut buffer contents remain intact and are pasted instead. (Since all xterm windows interpret ASCII text, the translation capabilities of the selection mechanism are not needed.)

Problems involving the loss of selections are more likely to happen if you are transferring information between clients that require information to be in different formats. If you are having such problems, you can customize the clients involved to copy information to what is known as the CLIPBOARD selection.

The CLIPBOARD selection is intended to avert problems of selection ownership by providing centralized ownership. Once the CLIPBOARD owns a selection, the selection can be transferred (and translated), even if the client that previously owned the selection goes away.

You can customize a client to send data to the CLIPBOARD selection by using event translations, which are discussed in Chapter 9, Setting Resources. See the client reference pages for information on the appropriate translations. For more information on selections and translations, see Volume One, Xlib Programming Manual.

Copying and Pasting between Release 2 and 3 Clients: xcutsel

The xcutsel client is intended to bridge a gap that exists between the ways older and newer clients allow you to copy text. If all the clients you are using are from Release 3 or later, you will probably have no use for xcutsel and should skip ahead to the next section.*

Since Release 3, when you select text from an xterm window with the pointer, the text is copied into the global cut buffer and made the PRIMARY selection. (Thus, generally, the contents of the cut buffer and the PRIMARY selection are the same.) By default, the PRIMARY selection is what gets pasted into a window. If there is no PRIMARY selection, the contents of the cut buffer arc pasted.

Prior to Release 3, clients did not use selections. Text was copied into the cut buffer only (and was not equated with a PRIMARY selection). Problems can arise if you are running clients that use cut buffers only (many Release 2 clients and uwm, any release) with clients that primarily use selections (Release 3 and later) and arc trying to paste text between them.

For instance, say you copy text in a Release 3 xterm window using the pointer. The text is copied into the cut buffer and also becomes the PRIMARY selection. If you paste in any window, the PRIMARY selection is what you get. Then, say you copy text in a R2 xterm window. The text is stored in the cut buffer, replacing the text in the cut buffer from the R3 window, but it does not replace the PRIMARY selection. You can paste the text from the R2 window in another R2 window because the window only understands cut buffers, but you can’t paste it in an R3 window. If you try to, by default you get the PRIMARY selection (from the other R3 window).

xcutsel enables you to switch the text in the cut buffer and the PRIMARY selection so that you can cut and paste between clients that use cut buffers and clients that use selections.

To open an xcutsel window, type:

% xcutsel &

and then place the window on your screen. Figure 4-10 shows an xcutsel window.

The window contains three command buttons whose functions are described below:

quit Exits the xcutsel program.
copy PRIMARY to 0 Copies the contents of the PRIMARY selection to CUT_BUFFER0.
copy 0 to PRIMARY Copies the contents ofCUT_BUFFER0 to the PRIMARY selection.

images

Figure 4-10. An xcutsel window

Now let’s go back to the problem we set up earlier in this section. If you copy text from an R2 window and want to paste in an R3 window, you merely click on the copy 0 to PRIMARY button. The contents of the cut buffer (from the R2 client) replace the previous PRIMARY selection (from the R3 client). When you paste, you get the text you want (from the R2 window).

Now say you have the same situation, but the opposite problem. You made a selection from an R3 window, which filled the cut buffer and the PRIMARY selection. Then you copied text from an R2 window, which merely filled the buffer. (The contents of the buffer and the PRIMARY selection are different.) But now say you want to paste the text from the PRIMARY selection (from the R3 window) in an R2 window. If you paste text in an R2 window, you get the contents of the cut buffer (the text from the other R2 window).

To solve this problem, just click on the copy PRIMARY to 0 button in the xcutsel window. The contents of the PRIMARY selection (from the R3 window) replace the contents of the cut buffer (from the R2 window). When you paste in an R2 window, you get still get the contents of the cut buffer, but it is now the text you want.

This business of selections versus cut buffers can be pretty confusing. If you have problems pasting the text you want, experiment a little with xcutsel.

Saving Multiple Selections: xclipboard (Release 4 Version)

The xclipboard client provides a window in which you can paste multiple text selections and from which you can copy text selections to other windows. Similar to the clipboard feature of the Macintosh operating system, the xclipboard is basically a storehouse for text you may want to paste into other windows, perhaps multiple times. The xclipboard window is shown in Figure 4-11.

This section and the next two sections describe various features of the Release 4 version of xclipboard. If you are using the Release 3 version, which has more limited functionality, also read the section “Release 3 xclipboard” later in this chapter.

images

Figure 4-11. The xclipboard window

To open an xclipboard, type:

% xclipboard &

and then place the window interactively with the pointer.

You can paste text into the xclipboard window using the pointer in the manner described above and then copy and paste it elsewhere, but this is not its intended usage. To use the xclipboard most effectively, you must do some customization involving a resource file, such as .Xresources. The necessary steps are described in detail in Chapter 9, Setting Resources. For now, suffice it to say that you want to set up the xclipboard so that you can select text to be made the CLIPBOARD selection and have that text automatically pasted in the xclipboard window. This is illustrated in Figure 4-12.

Since the xclipboard client is intended to be coordinated with the CLIPBOARD selection, the X server allows you to run only one xclipboard at a time.

In order to illustrate how the clipboard works, let’s presume it has been set up according to the guidelines in Chapter 9. According to those guidelines, you make text the CLIPBOARD selection by selecting it with the first pointer button (as usual) and then, while continuing to hold the first button, clicking the third button. (You could specify another button combination or a button and key combination, but we’ve found this one works pretty well. For more information about these specifications, see Chapter 9, Setting Resources.) The first pointer action makes the text the PRIMARY selection (and it is available to be pasted in another window using the pointer); the second pointer action additionally makes the text the CLIPBOARD selection (and it is automatically sent to the xclipboard window).

These guidelines still allow you to select text with the first pointer button alone, and that text will be made the PRIMARY selection; however, the text will not automatically be sent to the xclipboard. This enables you to make many selections, but to direct to the xclipboard only those you consider important (perhaps those you might want to paste several times).

images

Figure 4-12. Selected text appears automatically in the xclipboard window

In order to allow you to store multiple text selections, the seemingly tiny xclipboard actually provides multiple screens, each of which can be thought of as a separate buffer. (However, as we’ll see, a single text selection can span more than one screen.) Each time you use the pointer to make text the CLIPBOARD selection, the xclipboard advances to a new screen in which it displays and stores the text.

Once you have saved multiple selections, the client’s Next and Previous command buttons allow you to move forward and backward among these screens of text. The functionality of the client’s command buttons is summarized in Table 4-3. They are all selected by clicking with the first pointer button.

Table 4-3. Command Buttons and Functions

Button Function
Quit Causes the application to exit.
Delete Deletes the current xclipboard buffer; the current screenful of text is cleared from the window, and the next scrcenful (or previous, if there is no next) is displayed.
New Opens a new buffer into which you can insert text; the window is cleared.
Next and Previous Once you have sent multiple selections to the xclipboard, Next and Previous allow you to move from one to another (display them sequentially). Before two or more CLIPBOARD selections are made, these buttons are not available for use (their labels will appear in a lighter typeface to indicate this).

The command buttons you will probably use most frequently are Delete, Next, and Previous.

When you select text using the first and third pointer buttons, the text will automatically be displayed in the xclipboard window and will in effect be the first screenful of text (or first buffer) saved in the xclipboard. Subsequent CLIPBOARD selections will be displayed and saved in subsequent screens.

You select text from the xclipboard and paste it where you want it just as you would any text. Just display the text you want in the xclipboard window, using Next or Previous as necessary. Then select the text using the first pointer button and paste it using the second pointer button.

You can remove a screenful of text from the xclipboard by displaying that screenful and then clicking on the Delete command button. When you delete a screenful of text using this command button, the next screenful (if any) will be displayed in the window. If there is no next screenful, the previous screenful will be displayed.

Certain features (and limitations) of the xclipboard become apparent only when you make a very large CLIPBOARD selection. Say you select a full xterm window of text with the first and third pointer buttons, as described above. The text extends both horizontally and vertically beyond the bounds of a single xclipboard screen. (As we suggested earlier, a CLIPBOARD selection can actually span more than one xclipboard screen. Pressing Delete will remove all screenfuls comprising the selection.) When you make a selection that extends beyond the bounds of the xclipboard screen (either horizontally, vertically, or both), scrollbars will be activated in the window to allow you to view the entire selection.

If the text extends both horizontally and vertically beyond the bounds of the xclipboard screen, as it does in Figure 4-13, the window will display both horizontal and vertical scrollbars. If the text extends beyond the screen in only one of these two ways, the window will display either a horizontal or vertical scrollbar, as needed.* These scrollbars are selection-specific: they are only displayed so long as the current selection cannot be viewed in its entirety without them. If you move to a previous or subsequent selection that can be viewed without scrollbars, the scrollbars will be deactivated.

images

Figure 4-13. xclipboard with scrollbars to view large text selection

Problems with Large Selections

If you experiment making large selections with xclipboard, you may discover what seems to be a bug in the program. Though in most circumstances, making a new selection causes the screen to advance and display the new text, this does not happen reliably after a selection vertically spanning more than one screenful. In these cases, the new selection is saved in the xclipboard; however, the xclipboard window does not automatically advance to show you the new current selection. Instead, the previous long selection is still displayed. This is a bit of xclipboard sleight-of-hand. The new selection has been successfully made, but the appearance of the window belies this fact. (The Next button will probably add to your confusion; it will not be available for selection, suggesting that the text in the window is the last selection saved. This is not the case.)

In order to get around this and display the actual current selection, press the Previous button. The same long selection (which is, in actuality, the Previous selection) will again be displayed. Then the Next button will be enabled, and you can click on it to display the actual current selection.

Editing Text Saved In the xclipboard

You can edit text you send to the xclipboard using the same commands recognized by xedit. These commands are described in the section “Text Editing Widget” of Chapter 7, Other Clients. A small caret cursor will be visible in each screenful of text. You can move this cursor by clicking the pointer where you’d like it to appear. Then you can backspace to delete letters or type to insert them, or use any of the text editing commands described in Chapter 7. When you edit a screenful of text, the xclipboard continues to store the edited version, until you delete it or exit the program.

Be aware that, without performing customization, you can still use xclipboard on a very simple level. You can paste text into and copy text from the xclipboard window just as you would any other, using the pointer movements described earlier in this chapter. You can also type in the xclipboard window, and then copy and paste what you’ve typed. Just move the pointer into the window and try typing. However, keep in mind that this is not the intended use of the xclipboard.

If you do choose to use the clipboard in a limited way, it can still be a helpful editing tool. For example, say you wanted to create a paragraph composed of a few lines of text from each of two files. You could copy the text from each file using the pointer and paste it into the xclipboard window. (Each time you paste text into the xclipboard window, the text is appended to whatever text has already been pasted there.) Again using the pointer, you could copy the newly formed paragraph from the xclipboard window and paste it into a file in another window.

Release 3 xclipboard

xclipboard was first shipped as a part of the standard version of X in Release 3. If you are using the Release 3 xclipboard, shown in Figure 4-14, you’ll find that it’s functionality is considerably more limited than the Release 4 version.

images

Figure 4-14. The Release 3 xclipboard window

The Release 3 xclipboard can also be customized to receive the CLIPBOARD selection automatically. However, this version of the xclipboard merely inserts each selection on the line(s) following the previous one. The screen of the xclipboard will scroll forward as you add more text, but at line intervals, not at full screen intervals as the Release 4 client does. Thus, while the Release 4 xclipboard allows you to save multiple selections that are recognized as such by commands like Delete, the Release 3 xclipboard only allows you to save what is, in effect, a single, running selection. This limitation alone makes the Release 3 xclipboard far less useful than the Release 4 xclipboard.

But the Release 3 xclipboard has other serious limitations. It features only one functioning command button, quit. The erase button in the window is not functional, and unfortunately, no other key or combination of keys seems to clear the text from the xclipboard.

Unlike the Release 4 version, the Release 3 xclipboard docs not recognize all of the text editing commands recognized by xedit. You can use all of the commands that move the cursor, but none of the commands that delete text. Your only option to remove text is to select the quit button, which closes the window without saving its contents, and open a new xclipboard window.

You also cannot change or add to any text once it is placed in the window. You can type text in the window, but not within any pre-existing selection. If you type text, the cursor will automatically advance to the line below the last selection, and the new text will be displayed there. If the last text in the window is text you typed in, the cursor will advance to the end of that line and append the new typed text. (Note that since the cursor advances automatically and you cannot edit any text, the xedit commands to move the cursor are virtually useless.)

Once you type text in, it is treated just like any other selection-it cannot be deleted or edited in any way. Likewise, if you physically paste text in the window using the pointer (rather than sending it automatically as the CLIPBOARD selection), it will appear after existing text and cannot be edited or deleted.

Despite these limitations, you can still use the Release 3 xclipboard on a very simple level as a text editing tool. Whether you customize it to receive CLIPBOARD selections automatically or not, the xclipboard can still be used as a storehouse for text. You can paste text into and copy text from the xclipboard. You could use it to gather text from several areas, perhaps forming a new paragraph to be pasted into one or more files. If you’re a good typist (since you cannot correct your errors), you could also enter text in the window and then copy and paste what you’ve typed.

Terminal Emulation and the xterm Terminal Type

Anyone who has used a variety of terminals knows that they don’t all work the same way. As a terminal emulator, an xterm window must be assigned a terminal type, which tells the system how the window should operate, that is, what type of terminal it should emulate. When xterm is assigned an invalid terminal type, the window does not display properly at all times, particularly when using a text editor, such as vi. If one of your login files (.login, .profile, .cshrc, etc.) currently specifies a default terminal type, you will need to replace this with a type valid for xterm. (If none of your login files specifies a terminal type, xterm automatically searches the file of TERMCAP entries for the first valid entry.)

xterm can emulate a variety of terminal types, which are listed on the client reference page in Part Three of this guide. An xterm window emulates a terminal most successfully when it has been assigned the terminal type xterm. For the xterm terminal type to be recognized on your system, the system administrator will have had to add it to the file containing valid TERMCAP entries. (The xterm TERMCAP entry is supplied with the standard release of X.) If this has not been done, the system will not recognize the xterm terminal type. In these cases, try the vt100 terminal type, which also generally works well, or use one of the other types listed on the client reference page.

See Appendix A, System Management, and the xterm reference page in Part Three of this guide for information about customizing the termcap file.

Resizing an xterm Window

xterm sets the TERMCAP environment variable for the dimensions of the window you create. Clients (including xterm) use this TERMCAP information to determine the physical dimensions of input and output to the window.

If you resize an xterm window, programs running within the window must be notified so they can adjust the dimensions of input and output to the window. If the underlying operating system supports terminal resizing capabilities (for example, the SIGWINCH signal in systems derived from BSD 4.3), xterm will use these facilities to notify programs running in the window whenever it is resized. However, if your operating system does not support terminal resizing capabilities, you may need to request explicitly that TERMCAP be updated to reflect the resized window.

The resize client sends a special escape sequence to the xterm window and xterm sends back the current size of the window. The results of resize can be redirected to a file that can then be sourced to update TERMCAP. To update TERMCAP to match a window’s changed dimensions, enter:

% resize > filename

and then execute the resulting shell command file:

% source filename          C shell syntax

or:

$ . filename                    Bourne shell syntax

TERMCAP will be updated and the dimensions of the text within the window will be adjusted accordingly.

If your version of UNIX includes the C shell, you can also define the following alias for resize:

alias rs 'set noglob; eval 'resize'; unset noglob;

Then use rs to update the TERMCAP entry to reflect a window’s new dimensions.

Note that even if your operating system supports terminal resizing capabilities, xterm may have trouble notifying programs running in the window that the window has been resized. On some older systems (based on BSD 4.2 or earlier), certain programs, notably the vi editor, cannot interpret this information. If you resize a window during a vi editing session, vi will not know the new size of the window. If you quit out of the editing session and start another one, the editor should know the new window size and operate properly. On newer systems (e.g., BSD 4.3 and later), these problems should not occur.

Running a Program in a Temporary xterm Window

Normally, when you start up an xterm window, it automatically runs another instance of the UNIX Bourne or C shell (depending on which is set in your .Xresources file or the SHELL environment variable). If you want to create an xterm window that runs some other program, and goes away when that program terminates, you can do so with the xterm -e option:

% xterm -e command[arguments]

For example, if you wanted to look at the file temp in a window that would disappear when you quit out of the file, you could use the UNIX more program as follows:

% xterm -e more temp

If you are using other options to xterm on the command line, the -e option must appear last. This is because everything after the -e option is read as a command.

______________
*The right button can be made to function as the “first” button. This is especially useful if you are left-handed. See Chapter 11, Setup Clients, for instructions on how to customize the pointer with xmodmap.

†The Allow SendEvents mode is available as of Release 4. Log to File is available in Release 3 as Logging. The equivalent Release 3 menu (called xterm) also includes a Visual Bell mode toggle. As of Release 4, this item has been renamed Enable Visual Bell and moved to the VT Options menu.

*The first three of these commands were called Hangup, Terminate, and Kill in Release 3. Quit has not been renamed.

*In Release 3, if you enable the scrollbar for a particular window, the mode Scroll to Bottom on Tty Output is turned on automatically. This mode indicates that if you are using the scrollbar and the window receives output (or a key is pressed, if stty echo is enabled), the window scrolls forward so that the cursor is at the current line. (You can use the menu to toggle this mode off, but it is generally desirable to have.)

*To be more precise, double clicking selects all characters of the same class (e.g., alphanumeric characters). By default, punctuation characters and whitespace are in a different class from letters or digits-hence, the observed behavior. However, character classes can be changed. For example, if you wanted to double-click to select e-mail addresses, you’d want to include the punctuation characters 1, %, @, and in the same class as letters and digits. However, redefining the character classes is not something you’d do every day. See the xterm reference page in Part Three for details.

*If you are using uwm, you may have use for xcutsel. Regardless of the release, uwm uses only cut buffers. See Appendix B, The uwm Window Manager, of this guide for details.

* An application created using the X Toolkit, which provides horizontal and vertical scrollbars, is described as a viewport. See Chapter 7, Other Clients, for more information about viewports and other X Toolkit features.

Get X Window System User's Guide for X11 R3 and R4 of the X Window System now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.