Color Output in the Command-line Interface - Maple Programming Help

Home : Support : Online Help : System : Command-Line Maple : interface/ansicolor

Color Output in the Command-line Interface

 Calling Sequence interface(ansicolor) interface(ansicolor=colorSpec) interface(getansi) interface(getansi=colorNum) interface(showcolors) interface(showtermcolors)

Parameters

 colorSpec - an integer or list of integers

Description

 • The ansicolor option of the interface command is used to query or set the colors used by the command-line interface when displaying different categories of output (syntax highlighting).
 • When invoked as interface(ansicolor), the current color scheme is returned.
 • The color scheme is set using interface(ansicolor='colorSpec'), where colorSpec is either an integer specifying one of the predefined color schemes, or a list of individual color specifications for different categories of output.
 • The colors specified are only in effect in the command-line interface to Maple, and only if the terminal being used supports color. To test your terminal, use the command interface(showtermcolors).
 • The following built-in color schemes are supported:

 Scheme Description 0 16-color scheme for dark backgrounds, consisting of 8 normal and 8 bold colors. This scheme should work with any ANSI X3.64 compatible 16-color terminal. This scheme usually also displays acceptably on light backgrounds, and is therefore the default when the terminal is not known to support 256-color mode. 1 16-color scheme for light backgrounds. Same as above, but with black, two shades of gray, and white reversed. This scheme should work with any ANSI compatible color terminal. 2 256-color scheme for dark backgrounds. The colors in this scheme are qualitatively similar to those in the 16-color scheme (i.e., red is still red), except that they were chosen to have uniform perceptual brightness within each group (normal and bold). The bold colors are brighter than the normal colors. 3 256-color scheme for light backgrounds. As above, but the bold colors are darker than the normal colors. 4 256-color scheme for dark backgrounds, based on Ethan Schoonover's popular Solarized set of colors. Some of the bold colors are identical to the normal ones, as Solarized has only 8 distinct colors. The mapping from system colors (i.e., red, green, etc.) to Solarized colors differs slightly from those suggested by Schoonover. 5 Solarized scheme for light backgrounds. 6 Vintage terminal inspired scheme, using only shades of gray, green, and amber (although any given real vintage terminal only ever used one of these three colors). This scheme works best on a background that is almost black. 7 Background-agnostic scheme for 256-color terminals. This scheme is the default when the terminal is known to support 256-color mode.

 • If you do not like any of the above schemes, you can define your own by providing a colorSpec that is a list of colors for different output categories. The individual entries in the list must be integers in the range -1 to 65535.
 An entry of -1 indicates that no color is to be used for the corresponding category of output. Instead, Maple will use default attributes, such as bold for keywords and italics for variable names (if the terminal supports these).
 An entry in the range 0..65535 specifies a foreground (fg) and background (bg) color, where the entry is calculated as bg * 256 + fg. Each component must be in the range 0..255, and refers to the extended ANSI color table entry number (not standardized, but widely supported). The color numbers can be viewed using interface(showtermcolors).
 A background color of 0 is treated specially. Instead of specifying that the background is to be black, the terminal's default background color is used instead. A black background can still be achieved by specifying a background color of 16, since that entry in the terminal's color table is also black.
 • The following table lists the categories of output whose color can be specified individually:

 List Index Output Type 1 Normal output. This color is used when no other output category applies, or when no color is defined for that output category. The default is -1, yielding the terminal's default text color. 2 Italic output. This is used when the pretty printer calls for italic text, generally for variable names. The default is -1, yielding italic text in the same color as normal text. Note that not all terminals support italics, in which case normal text is displayed. 3 Symbol output. Currently unused*. The default is -1, yielding normal text. 4 Bold output. The default is -1, yielding boldface text in the same color as normal text. This is not used for any specific output category, but is used as a fallback if no color is specified for general keywords or error messages. 5 Underlined output. The default is -1, yielding underlined text in the same color as normal text. This is not used for any specific output category, but is used as a fallback if no color is specified for flow control interruption or error keywords. 6 Reverse video output*. Currently unused. The default is -1, yielding reversed video text in the terminal's default color or the color specified for normal text, but with the foreground and background colors exchanged. 7 Maple prompts. This is the color used for Maple's normal input, and also debugger, prompts. The default is green (2). 8 User input. This is the color of input typed by the user. The default is -1, specifying the terminal's default color. If interface(ansiedit) is true, then this color is only used for parts of the input that are not included in one of the other categories. 9 Output from userinfo calls. The default is green (2), indicating the special yet not-alarming nature of this output. 10 Output when tracing execution, either via the trace command, or as a result of a high printlevel setting. The default is (dark) yellow (3). 11 Warnings. The default is bold yellow (11), to bring this to the user's attention. 12 Errors. The default is bold red (9), indicating the importance of this output. 13 Output from the debugger. This includes only output generated by the debugger itself, not output produced for other reasons while a program is being debugged. The default is red (1). 14 Maple keywords when printing procedures and expressions. The default is bold blue (12). 15 Maple declaration keywords, such as local and option. The default is bold green (10). 16 Maple keywords that interrupt control flow, such as break and return. The default is bold magenta (13). If this color is set to -1, these keywords are printed bold and underlined. 17 Maple keywords related to exceptions and exception handling, such as error and try. The default is bold red (9). If this color is set to -1, these keywords are printed bold and underlined. 18 Labels in large expressions, such as %1. The default is bold cyan (14), so they can be easily seen in the midst of large output. 19 Special names (e.g. procname, false, infinity) and any back-quoted names. The default is cyan (6). 20 Strings enclosed in double quotes. The default is (dark) magenta (5). 21 The Maple logo at startup. The default is green (2). 22 Output generated by printf. The default is -1, giving output in the terminal's default color. 23 Maple status messages ("bytes used..."). The default is blue (4), making them darker than most output, but still visible. 24 Output generated during execution of a system command. The default is -1, giving output in the terminal's default color. 25 Maple comments when input is being echoed.

 *The entries marked as "currently unused" above may be used in future versions of Maple for purposes not covered by the later entries in the list. They appear early in the list for historical reasons.
 • Any output that does not fall specifically into one of the categories above is rendered using the terminal's default color, which in many terminal applications, can be specified separately from all the specifically numbered colors.
 • If the given list has less than 25 entries, the missing entries are assumed to be -1. Unless mentioned otherwise in the table above, this will result in normal text in the terminal's default color.
 Specifying an empty list is equivalent to specifying a list containing 25 instances of -1, and will result in using the terminal's default color for all categories of output. Syntax highlighting will only make use of boldface, underline, and italic attributes.
 • Passing an empty list sets all entries to -1, and causes Maple to revert to monochrome output, using only the normal, bold, underline, and italic attributes.
 • A list with only one element specifies the text color for all categories of output.
 • When a colorSpec is specified, interface(ansicolor='colorSpec') returns the list specifying the old color scheme. Also, if interface(ansi) is not already true, it will be set to true.
 • By default, color is also applied to line-printed (lprint) output, as well as command-line user input. These can be disabled using interface(ansilprint=false) and interface(ansiedit=false) respectively.
 • When output is to a file or pipe instead of to the terminal, color is not applied.

Retrieving Color Escape Sequences

 • The call interface(getansi='colorNum'), where colorNum is an integer from 1 to 25, returns a string containing the escape sequence used to generate the color and/or attributes for the corresponding output category. This can be used, for example, to generate output with printf that matches the current color scheme.
 • Calling interface(getansi) with no specified integer will return an expression sequence of strings of all the escape sequences for the current color scheme.

Viewing the Current Color Scheme

 • To see sample output using the color scheme currently in effect, use the command interface(showcolors). This command will include the color information even when writing to a file, allowing the ANSI escape sequences to be inspected in an editor if desired.

Viewing All Available Colors

 • To see all the colors supported by your terminal, use the command interface(showtermcolors).
 • The output consists of five sections, the first of which displays text in the terminal's default color using each of the attributes normal, bold, italic, underline, and reverse. Except for the italic attribute, this should display correctly on any ANSI X3.64 compatible terminal, ranging from the original 1978 DEC VT100 to a modern X11 terminal emulator such as Gnome Terminal.
 The second section uses the ANSI standard escape sequences to write text in 8 normal and 8 bold colors, and should display correctly on any ANSI X3.64 compatible color terminal. The bold colors may appear either brighter, with a heavier weight, or both, depending on terminal settings. The shades and hues of the colors in this section may vary depending on the terminal used and its settings. Depending on the terminal background color, one of the 16 colors may not be visible. On a monochrome terminal, the bold colors should appear in boldface.
 The third section displays the same 16 colors using the non-standard but widely supported extended 256-color escape sequences. Like the previous section, the shades and hues may vary depending on terminal settings.
 Section four consists of 216 colors representing a 6x6x6 color cube. This section is printed as 6 subsections, each with 6 rows and 6 columns. These colors consist of all combinations of red, green, and blue, each taking on values from the set {0.000, 0.373, 0.529, 0.686, 0.843, 1.000}. These colors should look identical on all compatible terminals.
 The last section consists of 24 shades of gray, ranging in intensity from 0.0314 to 0.933. These too should look identical on all 256-color compatible terminals.
 • If any of the above do not appear as described, then the terminal does not support the corresponding feature. If the output contains any unusual sequences of characters, then the terminal is likely not ANSI-compatible at all. Note that 256-color mode must be explicitly enabled via a setting on some terminals, such as PuTTY.

Examples

 > $\mathrm{old}≔\mathrm{interface}\left(\mathrm{ansicolor}\right)$
 ${\mathrm{old}}{≔}\left[{-1}{,}{-1}{,}{-1}{,}{-1}{,}{-1}{,}{-1}{,}{2}{,}{-1}{,}{2}{,}{3}{,}{11}{,}{9}{,}{1}{,}{12}{,}{10}{,}{13}{,}{9}{,}{14}{,}{6}{,}{5}{,}{2}{,}{-1}{,}{4}{,}{-1}{,}{3}\right]$ (1)
 > $\mathrm{new}≔\mathrm{subsop}\left(16=231,\mathrm{old}\right)$
 ${\mathrm{new}}{≔}\left[{-1}{,}{-1}{,}{-1}{,}{-1}{,}{-1}{,}{-1}{,}{2}{,}{-1}{,}{2}{,}{3}{,}{11}{,}{9}{,}{1}{,}{12}{,}{10}{,}{231}{,}{9}{,}{14}{,}{6}{,}{5}{,}{2}{,}{-1}{,}{4}{,}{-1}{,}{3}\right]$ (2)
 > $\mathrm{interface}\left(\mathrm{ansicolor}=\mathrm{new}\right)$
 $\left[{-1}{,}{-1}{,}{-1}{,}{-1}{,}{-1}{,}{-1}{,}{2}{,}{-1}{,}{2}{,}{3}{,}{11}{,}{9}{,}{1}{,}{12}{,}{10}{,}{13}{,}{9}{,}{14}{,}{6}{,}{5}{,}{2}{,}{-1}{,}{4}{,}{-1}{,}{3}\right]$ (3)
 > $\mathrm{interface}\left(\mathrm{ansicolor}\right)$
 $\left[{-1}{,}{-1}{,}{-1}{,}{-1}{,}{-1}{,}{-1}{,}{2}{,}{-1}{,}{2}{,}{3}{,}{11}{,}{9}{,}{1}{,}{12}{,}{10}{,}{231}{,}{9}{,}{14}{,}{6}{,}{5}{,}{2}{,}{-1}{,}{4}{,}{-1}{,}{3}\right]$ (4)