Advanced Editing

The Command Editor

While most users are happy just entering a single line of text into the Command Line at a time, there are many situations that call for editing and sending large blocks of text to the MUD. Some examples that require multi-line editing are:

All of these functions require some type of text editor for manipulating large amounts of text offline. While you can use editors such as Notepad to create files, and then Cut and Paste text to the MUD, zMUD offers a more integrated editing feature called the Command Editor

The command editor, shown in Figure 1, is activated by choosing the Editor command in the Window menu, or by pressing ctrl-enter. This editor is similar to many simple text editors, but contains some specialized MUD features that will be described in this chapter.

Figure 1: zMUD Command Editor

Beneath the menu bar is a toolbar containing buttons for various commands. At the bottom of the window is a status bar containing the location of the cursor, the current mode (Insert or Overwrite), and the horizontal scroll bar. The Command Editor can edit files up to 16,000 lines long. The line limit for the editor is set in the zMUD General Preferences dialog in the Memory section.

Entering text manually

Since the Command Editor functions as a normal text editor, you can just start entering text by hand by typing on the keyboard. The cursor keys are used to move the cursor up, down, left and right. The function of various keys is shown in the table below

Table 1: Keyboard commands in the editor

Key

Function

up-arrow

move the cursor up one line

down-arrow

move the cursor down one line

right-arrow

move the cursor right one character. If at the end of the line, move the cursor to the beginning of the next line

left-arrow

move the cursor left one character. If at the beginning of the line, move the cursor to the end of the previous line

home

move the cursor to the beginning of the current line

end

move the cursor to the end of the current line

page-up

move the cursor up one screen of text

page-down

move the cursor down one screen of text

ctrl-left-arrow

move the cursor to the previous word on the line. If at the beginning of the line, then move the cursor to the end of the previous line

ctrl-right-arrow

move the cursor to the beginning of the next word in the line. If at the end of the line, then move the cursor to the beginning of the first word on the next line

ctrl-home

move the cursor to the beginning of the file

ctrl-end

move the cursor to the end of the file

insert

toggle the insert/overwrite mode. In insert mode, characters entered are inserted in front of the cursor. In overwrite mode, the characters entered overwrite the existing text in the file

delete

delete the character just to the right of the cursor. If at the end of the line, the next line is joined with the current line.

backspace

delete the character just to the left of the cursor. If at the beginning of the line, the current line is joined to the end of the previous line

ctrl-c

copy the selected text to the clipboard

ctrl-x

cut the selected text into the clipboard

ctrl-v

paste the text in the clipboard, inserting it just before the cursor

Text can be selected by clicking and dragging with the mouse. If you double-click the left mouse button, the word under the mouse will be selected. If you left-click the mouse in the margin to the left of the text, the entire line will be selected. You can also select text using the cursor keys: hold down the shift key while moving the cursor and the text will be selected.

Entering text from a file

You can read text from a file using the Open command in the File menu, or by clicking the Open button in the toolbar. You should only read normal ASCII text files into the Command Editor. However, the Command Editor does recognize ANSI color codes, so log files saved with color can be read with the color information intact. If you attempt to read a file with other binary codes, such as vt100 cursor movement codes, the editor may act unpredictably.

If you try to load a file that is too large for the editor, you will be prompted for several options: a) you can attempt to increase the size of the editor’s buffer to accommodate the file; b) you can stop reading the file; c) you can continue reading the file and truncate the text at the beginning of the file that doesn’t fit. The third option is useful for reading the end of a large log file. On 16-bit systems, the editor is limited to 16,000 lines of text (and each line is limited to 64,000 characters). On 32-bit systems, the only limit to the size of the editor is the amount of physical memory on your computer. The default size of the editor is 1,000 lines.

Using the Open command erases any other text in the editor. If you want to insert a file into the editor without erasing the other text, use the Import command in the File menu. The specified file will be inserted just before the current cursor position.

To save the current text to a file, use the Save or Save As commands in the File menu, or click the Save button in the toolbar. If any of the text has been colored, the proper ANSI color codes will be saved along with the text. To save the text without the color information, turn off the Color option in the Options menu.

Capturing text from the MUD

There are several ways to send text received from the MUD into the editor. The simplest method is to copy the text from the MUD window and paste it into the editor. Because the Command Editor recognizes ANSI color codes, color information copied from the MUD information will be retained. The ability to handle ANSI color properly is a key feature in the zMUD Command Editor that is missing in many other editors.

Text from the MUD can be captured under script control using the #CAPTURE command. Simply specify the number of lines to capture, and those lines are copied from the MUD window into the editor. If you specify a count of zero lines, all lines until the next blank line is received from the MUD will be captured to the editor; this is called Block Capture mode. You can also toggle the capturing of text using #C+ to turn on capturing, and #C- to turn off capturing. When capturing is on, all text received from the MUD is copied to the editor. If the Capture Commands option in the zMUD General Preferences is also on, then any commands entered from the Command Line will also be captured to the editor when capturing is on.

In the editor, you can also control text capturing using the Capture command in the Option menu, or with the Toggle Caption button in the toolbar. If you turn the Capture option off in the editor, then text is not captured from the MUD no matter what other commands are used. The Capture option in the editor must be enabled in order for the #CAPTURE, #C+, and #C- commands to function normally. You can also manually capture lines from the MUD from within the editor using the Capture command in the File menu. You will be prompted for the number of lines to capture from the current MUD window.

All of the capture commands also take an optional parameter specifying the name of the window to send the captured text to. When this parameter is missing, the text is sent to the Command Editor. However, you can use this parameter to send text to any window you want. If the specified window does not exist, it is created automatically. Some examples of how the #CAPTURE command can be used to filter text from your main MUD window are shown later in this chapter.

Editing Text

Once the Command Editor contains some text, you can edit it using the keyboard commands described above. You can also manipulate the color of text. Since the Command Editor understands ANSI color codes, you can specify any ANSI color for the text, as well as highlight text. To change the color or text, select the text, then select Color from the Option menu, or click the Color button in the toolbar. A palette of foreground and background colors will be displayed. Simply click the combination of colors desired, then click OK. If you select the Color command when no text is selected, the default color of text that you enter from the keyboard will be changed.

You can highlight text by selecting it, then using the Bold command in the Option menu, or using the Bold button in the toolbar. Highlighted text either appears as a bold font, or as bright colors, depending upon the setting of the Highlight options in the zMUD Color settings dialog. If you use the Bold command when no text is selected, the highlight setting of the text entered from the keyboard will be changed.

Sending text to the MUD

In addition to editing the text, the Command Editor also allows you to send the text back to the MUD in several different ways. Using a regular editor, you would have to copy and paste the text to the MUD. However, the Command Line only allows you to paste a single line of text to send to the MUD. By pasting text into the Command Editor, you can then send the entire contents of the editor to the MUD using the Send command in the File menu, or using the Send button in the toolbar.

Text that is sent to the MUD can be optionally prefixed with a text string. This text string is entered into the Prefix String pull-down box on the right side of the toolbar, with the Prefix Toggle button just to the left of this pull-down box enabled. The Prefix String is not added to the beginning of blank lines. Instead, blank lines are replaced with whatever is specified in the Blank Line replacement string area of the Preferences in the Option menu.

What if you want to send the contents of a text file to another player on the MUD. The MUD has a tell command that is used to talk with another player. However, the tell command only accepts one line at a time. The solution to this problem is to use the Command Editor. Open the editor by pressing ctrl-enter and click the Open button on the editor’s toolbar to open a text file. In the Prefix box to the right of the toolbar, enter the text tell Zugg and make sure the Prefix Toggle to the left of the pull-down box is enabled. Then, click the Send button. Each line in the editor will be sent to the MUD with the text tell Zugg added to the beginning of each line. Thus, Zugg will receive the contents of the file, one line at a time.

The editor also has a Send Line command and button that will just send the current line containing the cursor to the MUD, and a Send Selected command and button that will send the selected text to the MUD. In each case, the Prefix String is added to the beginning of each line if the Prefix Toggle is enabled.

When sending text to the MUD, the ANSI color codes are also sent unless the Color option in the Option menu is turned off. Many MUDs support color, but do not allow you to send ANSI color codes directly. This restriction exists because many MUD servers cannot accept the Escape (ASCII character 27) character, which is needed to specify an ANSI color code. Also, it is difficult to remember all of the ANSI color codes (they are listed in the Appendix for your reference). Instead of accepting ANSI color codes, many MUDs use their own color commands or syntax. The Customizing zMUD chapter explains how to enter this syntax into zMUD. If you have the Color Syntax option in the Option menu enabled, the Command Editor will translate the ANSI color codes to the specific color syntax you have defined for your MUD.

Finally, you can also control whether the text is sent directly to the MUD, or whether zMUD parses it as commands first. Normally you will just send the text straight to the MUD, but when programming scripts you will likely want to turn on the Parse option in the Option menu or enable the Toggle Parse button on the toolbar to ensure that zMUD executes any commands in the line first.

Other features of the editor

The Command Editor also supports word wrapping. In the Preferences option in the Option menu, you can specify Auto-Wrap which causes the lines to word-wrap at the end of the window, or you can enter a specific column to wrap the text at. Lines that are wrapped are indented by several spaces so that you can distinguish them from lines that do no wrap. Even though a long string of text may be wrapped and displayed on several lines in the window, it is still considered as a single line of text from the MUD. Wrapped lines do count towards the editor line limit, but when you use the Send Line command, the entire string of unwrapped text is sent to the MUD. Also, if you select a line by clicking the mouse in the left margin, the entire string of text will be selected, even if it wraps to multiple lines.

You can search for text in the editor using the Find option of the Edit menu. Enter the text you which to find, and select either up or down for a backwards or forwards search. The text that is found is automatically selected and can be copied to the clipboard, or sent to the MUD using the Send Selected command. You can also jump to a specific line in the editor using the Goto command in the Edit menu.

Unique uses for the editor

Even though the Command Editor is similar to many simple editors, its integration with zMUD allows for some very creative uses, especially for MUD coders, builders, and wizards.

On some MUDs, a wizard can serve as master of ceremonies for MUD weddings. The Command Editor can be used by the wizard to make this a very simple and fun duty. In preparation for the ceremony, the wizard creates a wedding template file that looks something like this:

1: #prompt husband;#prompt wife

2: We are gathered here to witness the marriage of @husband and @wife.

3: Do you, @husband, take @wife to be your MUDfully wedded wife,

4: in sickness and in health, till deleted do you part?

5: Do you, @wife, take @husband to be your MUDfully wedded husband,

6: With the power vested in my by this MUD, I pronounce you husband and wife.

7: You may kiss the bride.

Obviously, a real MUD wizard would invent a more elaborate ceremony, but the text above is enough to illustrate our example. Load this text (without the line numbers) into the Command Editor, and ensure that the Parse Toggle is enabled so that zMUD will execute the commands before text is sent to the MUD. In the Prefix String box, enter say and ensure that the Prefix Toggle is enabled.

When you are ready to conduct the wedding, click on the 1st line to move the cursor, then click the Send Line command. Since command parsing is enabled, this command is executed by zMUD, which prompts you to enter values for the @husband and @wife variables. When you have entered these two values, click on line 2 and click Send Line. Because parsing is enabled, the values of @husband and @wife will be replaced with the text you just entered, and the line will be sent to the MUD with the string say added to the beginning. The say command instructs the MUD to echo this text to everyone in the current room.

Next, click the 3rd line, then click Send Line, and continue sending the 4th line, then the 5th line, then the 4th line again, ending with the 6th and 7th lines. You have just conducted the wedding ceremony without entering the text in real time. You composed your wedding ceremony template offline, and can now use it over and over again. If you ever want to change it, you just edit the template and save it back to disk. This is certainly easier than typing the text by hand at the time of the ceremony, and eliminates the possibility of embarrassing typing errors.

Advanced Text Capture

As described earlier in this chapter, the #CAPTURE, #C+, and #C- commands take an optional parameter that specifies the name of the window to send the captured text. You can use this feature to filter text from your main MUD window and send it to other windows, organizing the information from the MUD and ensuring that you don’t miss important messages.

If the window specified by the capture commands does not exist, it is created automatically. Or, you can use the #WINDOW command to create a blank window with a specified name. These windows are similar to regular MUD output windows, but are linked to the main MUD window and considered child windows. If you close the main MUD output window, any child windows created with capture commands are also closed. Also, any child windows that were open when you quit a MUD and close its window are saved and reopened the next time you use that character. Since the position and size of child windows are also saved, you can organize your screen once and it will always remember your layout when you play that character again.

Child windows can also have their own settings independent from the main MUD window. A MUD file with the same name as the window is loaded if it exists when the child window is created. For example, if you create a child window with a name of chat, then a settings file named CHAT.MUD will be loaded for that window. This allows you to specify customer triggers, colors, etc. for each of your child windows, and can be a very powerful feature!

As an example, let’s create a series of useful message filters to clean up our main MUD window. On many MUDs, players can globally chat using the chat or gossip commands. While most MUDs allow you to turn off the chat messages, sometimes you’ll miss some useful information that way. Instead of turning them off, it would be better to remove them from the main screen and store them somewhere you can refer back to later. To do this, enter the following command:

#TRIGGER {chats} {#CAPTURE chat;#GAG}

This trigger takes every line from the MUD that contains the word chat and copies it to a window called chat. Then, the #GAG command is used to remove the line from the main window. If your MUD also adds an extra blank line after the chat message, then you might want to use a #GAG 2 command to remove both lines from the window. With this trigger, all chat messages are moved to a new window that you can log separately from the main window, or scroll back through the messages, or use the Find command in the chat window to find a specific message.

The above technique is also useful to filter and highlight important messages sent directly to you or your MUD group. For example, when you are part of a large MUD group fighting a tough battle, a lot of text can scroll through your window very quickly. If someone asks you a question or send you a private message during this battle, you might easily miss it. The following commands take care of this situation:

#TRIGGER {tells you} {#CAPTURE tell}
#TRIGGER {tells the group} {#CAPTURE group}

These command create windows called tell and group that store messages sent privately to you or to your entire group. You can also add a #GAG command if you wish, but normally it isn’t bothersome to see these messages in the main window.

Since each of these child windows can have their own settings, you can customize them even further. In the group window, each line looks something like:

Zugg tells the group ‘heal me’

The important text in this line is the name of the player (Zugg) and the message (heal me). The "tells the group" text isn’t really needed. Select the group window, and enter the command:

#TRIGGER {(*) tells the group} {#SUB %1:}

This trigger matches lines that contain tells the group and captures the name at the beginning of the line (we use * instead of %w in case the name is more than one word). The #SUBSTITUTE command is then used to replace this text with just the name, followed by a colon. Now, lines in this window look like this:

Zugg: ‘heal me’

Select the Save As command from the Settings menu and save the settings to a file called GROUP.MUD so that this trigger is loaded whenever the group window is opened.

Exercises

  1. Use the Command Editor to store the description of your room on a MOO and send it to the MUD.
  2. Write a script to capture the description of your room on a MOO and store it into the editor.
  3. Write a script to display your current stats (or score) in a window, along with your current equipment and inventory in another window.
  4. Write a script that captures all chat messages to one window, but selects chat messages from a specific list of players and sends those messages to a second window.