Ad hoc escape sequences used for formatting purposes.
Megistos includes a reasonably sophisticated formatting system, inspired by the really basic one included in the Major BBS. Major offered a pretty useful line wrapping feature, which came in handy for the built-in (line) editor, among other things. It was only applied to the user's input, though. Megistos applies it to the output, where it's most useful. It supports setting left and right margins, paragraph indentations, left and right alignment, centering, and full justification (my favourite).This takes full advantage of any user's terminal. I'm pretty sensitive to this type of need, because I've always had larger than normal text resolutions (things like 132 by 30, even on my poor little 286). Major couldn't take advantage of them, and it always annoyed me. I suppose it annoyed me enough to make this beast!
Right, then. Formatting directives are escape sequences, just like most terminal directives (also known as `ANSI' in the BBS world, to refer to a minute subset of the ANSI X3.64 Standard for Control Sequences for Video Terminals and Peripherals).
All formatting directives start with the sequence `ESC !', or ASCII codes 27 33 (in decimal). A character identifying the directive follows. Many directives take an optional argument, a base ten integer.
In default of any formatting directives, characters are printed in the normal way, left-aligned, without any word wrapping, justification or any margin or indentation adjustments. If your prompts are 80 columns wide and a user has a 64 column screen, they'll get ugly wrap-around effects.
Here are the specific commands. Spaces have been inserted between command elements. This was done for clarity. No spaces are actually used within the directives.
- ESC ! L
- Start formatting text. The current and subsequent lines will be rendered left-aligned. This is the default.
- ESC ! R
- Start formatting text. Current and subsequent lines will be rendered right-aligned.
- ESC ! C
- Start formatting text. Current and subsequent lines will be centred.
- ESC ! W
- Start formatting text. Current and subsequent lines will be rendered in wrap-around mode. This mode allows you to format ragged-edge text so that words are not split in two lines. There is, of course, no hyphenation!
- ESC ! J
- Start formatting text. Current and subsequent lines will be justified. This mode one produces professional-looking straight-edge text from left to right border.
- ESC ! l
- (lower case `L') Place left margin. If preceded by an argument, this sets the left margin to as many characters as the argument (zero denotes the physical left margin of the screen):
|<--------- physical line length -------->| |<-- arg -->|Left Margin |If the argument is not specified, this directive sets the left margin to the current cursor position.
- ESC ! i
- Works just like 'l', but sets the left margin on subsequent lines, whereas `l' affects the current line too. This is useful for paragraphs where the first line is indented, or for lists, where subsequent lines are indented.
- ESC ! r
- Place right margin. If the optional argument is specified immediately before the `r', this sets the right margin to the specified number of characters (zero denotes the physical right margin of the screen):
|<------- physical line length -------->| | Right Margin|<-- arg -->|If not preceded by a number, this command sets the right margin to the current cursor position.
- ESC ! F
- With the optional integer argument, this directive repeats the char following it as many times as specified by the argument. That is, ESC!10F- will render as `----------'. If not preceded by a number, the character following the `F' is repeated all the way the right margin.
- ESC ! (
- (open parenthesis) Begin formatting using the last formatting mode specified. This begins formatting, starts taking into account margins, etc. When wrapping/justifying, use this to begin a new paragraph. To end a paragraph, you need the following command:
- ESC ! )
- (closed parenthesis) Stop formatting. All subsequent output will be dumped to the output stream as-is, until another format command is encountered. Stops using set margins, etc. When wrapping/justifying, use this to end a paragraph so that newline characters are not transformed into horizontal spacing.
- ESC ! Z
- Zero the horizontal position counter. Start formatting from this position.
- ESC ! v
- Controls the expansion of substitution variables ( @VAR@-style embedded vars). This directive requires an argument. A value of 0 inhibits variable expansion, allowing normal use of the at-sign `@' symbol. Use this in places where the user is likely to use this symbol, e.g. pages, reading mail, etc. Non-zero values enable variable expansion, giving the at-sign its special meaning. You'll have to use ` @@' to get `@', et cetera. The default is full variable expansion.
- ESC ! P
- Causes a forced pause at the current point. Waits for the user to press any key, then continues printing. Use this sparingly, because it tends to annoy users.