[Home] [Downloads] [Search] [Help/forum]

MUSHclient scripting

Description of MUSHclient world function: world.ANSI

Type Method
Summary Generates an ANSI colour sequence
Prototype BSTR ANSI(short Code);

View list of data type meanings


This generates an ANSI colour sequence, like this:

ESC [ code m

The code number is supplied as an argument.

This is intended to be used with the ANSINote function - which lets you write to the output window with ANSI formatting, or to send to other clients via the chat system.

Useful numbers to use would be:


0: reset
1: bold
3: blink (is rendered as italic)
4: underline
7: inverse

22: cancel bold
23: cancel blink
24: cancel underline
27: cancel inverse

Foreground (text) colour

30: Black
31: Red
32: Green
33: Yellow
34: Blue
35: Magenta
36: Cyan
37: White

Background colour

40: Black
41: Red
42: Green
43: Yellow
44: Blue
45: Magenta
46: Cyan
47: White

// 256 colour ANSI foreground
38;5;n where n is 0 to 255

// 256 colour ANSI background
48;5;n where n is 0 to 255

Suggestion - you could conceivably replace colours in incoming chat messages by doing a world.Replace using ANSI, providing the incoming ANSI codes conform exactly to the rendering used here.

For example:

mymessage = world.Replace (incoming_message, ANSI (36), ANSI (37))

This would hopefully replace the code for Cyan with the code for White.

Note: Available in version 3.37 onwards.

VBscript example
ANSINote "This is normal" & ANSI (33) & " and this is yellow"
Jscript example
ANSINote ("This is normal" + ANSI (33) + " and this is yellow");
PerlScript example
ANSINote ("This is normal" . ANSI (33) . " and this is yellow");
Python example
world.ANSINote ("This is normal", 
world.ANSI (33, 47), " and this is yellow")
Lua example
AnsiNote ("This is normal ",
          ANSI (33, 47),
          "and this is yellow on white")
Lua notes
You can supply multiple arguments, as in the above example. 
Each one will generate its own ANSI code, so you can easily do multiple changes 

(eg. foreground, background, bold) in a single call to ANSI.

If you supply multiple arguments they will be placed into the same ANSI sequence, like this:

ANSI (33, 47) --> ESC[33;47m
Returns A string consisting of: ESC "[" Code "m"
Introduced in version 3.37

See also ...

Function Description
AnsiNote Make a note in the output window from text with ANSI colour codes imbedded
ChatMessage Sends a message to a chat user (raw format)
ChatNote Does a note using ANSI codes for the chat system
StripANSI Strips ANSI colour sequences from a string

Search for script function

Enter a word or phrase in the box below to narrow the list down to those that match.

The function name, prototype, summary, and description are searched.

Search for:   

Leave blank to show all functions.

Return codes

Many functions return a "code" which indicates the success or otherwise of the function.

You can view a list of the return codes

Function prototypes

The "prototype" part of each function description lists exactly how the function is called (what arguments, if any, to pass to it).

You can view a list of the data types used in function prototypes

View all functions


Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]