github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/docs/user-guide/ansi.md (about)

     1  # ANSI Constants
     2  
     3  > Infixed constants that return ANSI escape sequences
     4  
     5  ## Description
     6  
     7  ANSI Constants is a Murex convention of passing ANSI escape sequences into
     8  strings. It uses the `{}` notation with the constant name placed in between two
     9  curly braces. eg `{GREEN}`. 
    10  
    11  ## Constants
    12  
    13  Rather than duplicate the constants from source, and risk the documentation and
    14  implementation drifting, this document will embed the source directly below.
    15  
    16  ```go
    17  package ansi
    18  
    19  var constants = map[string][]byte{
    20  	// ascii control codes
    21  	"^@": {0},
    22  	"^A": {1},
    23  	"^B": {2},
    24  	"^C": {3},
    25  	"^D": {4},
    26  	"^E": {5},
    27  	"^F": {6},
    28  	"^G": {7},
    29  	"^H": {8},
    30  	"^I": {9},
    31  	"^J": {10},
    32  	"^K": {11},
    33  	"^L": {12},
    34  	"^M": {13},
    35  	"^N": {14},
    36  	"^O": {15},
    37  	"^P": {16},
    38  	"^Q": {17},
    39  	"^R": {18},
    40  	"^S": {19},
    41  	"^T": {20},
    42  	"^U": {21},
    43  	"^V": {22},
    44  	"^W": {23},
    45  	"^X": {24},
    46  	"^Y": {25},
    47  	"^Z": {26},
    48  	"^[": {27},
    49  	`^/`: {28},
    50  	"^]": {29},
    51  	"^^": {30},
    52  	"^_": {31},
    53  
    54  	"^?": {127},
    55  
    56  	// ascii human readable
    57  	"EOF":      {4},
    58  	"EOT":      {4},
    59  	"BELL":     {7},
    60  	"BS-ISO":   {8},
    61  	"LF":       {10},
    62  	"CR":       {13},
    63  	"CRLF":     {13, 10},
    64  	"ESC":      {27},
    65  	"ESCAPE":   {27},
    66  	"BS-ASCII": {127},
    67  
    68  	// ansi escape sequences
    69  	"CURSOR-UP":         {27, 91, 65},
    70  	"CURSOR-DOWN":       {27, 91, 66},
    71  	"CURSOR-FORWARDS":   {27, 91, 67},
    72  	"CURSOR-BACKWARDS":  {27, 91, 68},
    73  	"CURSOR-HOME":       {27, 91, 72},
    74  	"CURSOR-HOME-VT100": {27, 91, 49, 126},
    75  	"CURSOR-END":        {27, 91, 70},
    76  	"CURSOR-END-VT100":  {27, 91, 52, 126},
    77  
    78  	"INS":    {27, 91, 50, 126},
    79  	"INSERT": {27, 91, 50, 126},
    80  	"DEL":    {27, 91, 51, 126},
    81  	"DELETE": {27, 91, 51, 126},
    82  
    83  	// function keys
    84  	"F1-VT100": {27, 79, 80},
    85  	"F2-VT100": {27, 79, 81},
    86  	"F3-VT100": {27, 79, 82},
    87  	"F4-VT100": {27, 79, 83},
    88  	"F1":       {27, 91, 49, 49, 126},
    89  	"F2":       {27, 91, 49, 50, 126},
    90  	"F3":       {27, 91, 49, 51, 126},
    91  	"F4":       {27, 91, 49, 52, 126},
    92  	"F5":       {27, 91, 49, 53, 126},
    93  	"F6":       {27, 91, 49, 55, 126},
    94  	"F7":       {27, 91, 49, 56, 126},
    95  	"F8":       {27, 91, 49, 57, 126},
    96  	"F9":       {27, 91, 50, 48, 126},
    97  	"F10":      {27, 91, 50, 49, 126},
    98  	"F11":      {27, 91, 50, 51, 126},
    99  	"F12":      {27, 91, 50, 52, 126},
   100  
   101  	// alt-num
   102  	"ALT-0": {27, 48},
   103  	"ALT-1": {27, 49},
   104  	"ALT-2": {27, 50},
   105  	"ALT-3": {27, 51},
   106  	"ALT-4": {27, 52},
   107  	"ALT-5": {27, 53},
   108  	"ALT-6": {27, 54},
   109  	"ALT-7": {27, 55},
   110  	"ALT-8": {27, 56},
   111  	"ALT-9": {27, 57},
   112  
   113  	// control seqs
   114  	"CSI": {27, 91},
   115  }
   116  
   117  var sgr = map[string][]byte{
   118  	// text effects
   119  	"RESET":      {27, 91, 48, 109},
   120  	"BOLD":       {27, 91, 49, 109},
   121  	"ITALIC":     {27, 91, 51, 109}, // Not commonly supported in terminals
   122  	"UNDERSCORE": {27, 91, 52, 109},
   123  	"UNDERLINE":  {27, 91, 52, 109},
   124  	"UNDEROFF":   {27, 91, '2', '4', 109},
   125  	"BLINK":      {27, 91, 53, 109},
   126  	"INVERT":     {27, 91, 55, 109},
   127  
   128  	"ALT-FONT-1": {27, 91, 49, 49, 109}, // Not commonly supported in terminals
   129  	"ALT-FONT-2": {27, 91, 49, 50, 109}, // Not commonly supported in terminals
   130  	"ALT-FONT-3": {27, 91, 49, 51, 109}, // Not commonly supported in terminals
   131  	"ALT-FONT-4": {27, 91, 49, 52, 109}, // Not commonly supported in terminals
   132  	"ALT-FONT-5": {27, 91, 49, 53, 109}, // Not commonly supported in terminals
   133  	"ALT-FONT-6": {27, 91, 49, 54, 109}, // Not commonly supported in terminals
   134  	"ALT-FONT-7": {27, 91, 49, 55, 109}, // Not commonly supported in terminals
   135  	"ALT-FONT-8": {27, 91, 49, 56, 109}, // Not commonly supported in terminals
   136  	"ALT-FONT-9": {27, 91, 49, 57, 109}, // Not commonly supported in terminals
   137  	"FRAKTUR":    {27, 91, 50, 48, 109}, // Not commonly supported in terminals
   138  
   139  	// text colours
   140  	"BLACK":   {27, 91, 51, 48, 109},
   141  	"RED":     {27, 91, 51, 49, 109},
   142  	"GREEN":   {27, 91, 51, 50, 109},
   143  	"YELLOW":  {27, 91, 51, 51, 109},
   144  	"BLUE":    {27, 91, 51, 52, 109},
   145  	"MAGENTA": {27, 91, 51, 53, 109},
   146  	"CYAN":    {27, 91, 51, 54, 109},
   147  	"WHITE":   {27, 91, 51, 55, 109},
   148  
   149  	"BLACK-BRIGHT":   {27, 91, 49, 59, 51, 48, 109},
   150  	"RED-BRIGHT":     {27, 91, 49, 59, 51, 48, 109},
   151  	"GREEN-BRIGHT":   {27, 91, 49, 59, 51, 48, 109},
   152  	"YELLOW-BRIGHT":  {27, 91, 49, 59, 51, 48, 109},
   153  	"BLUE-BRIGHT":    {27, 91, 49, 59, 51, 48, 109},
   154  	"MAGENTA-BRIGHT": {27, 91, 49, 59, 51, 48, 109},
   155  	"CYAN-BRIGHT":    {27, 91, 49, 59, 51, 48, 109},
   156  	"WHITE-BRIGHT":   {27, 91, 49, 59, 51, 48, 109},
   157  
   158  	// background colours
   159  	"BG-BLACK":   {27, 91, 52, 48, 109},
   160  	"BG-RED":     {27, 91, 52, 49, 109},
   161  	"BG-GREEN":   {27, 91, 52, 50, 109},
   162  	"BG-YELLOW":  {27, 91, 52, 51, 109},
   163  	"BG-BLUE":    {27, 91, 52, 52, 109},
   164  	"BG-MAGENTA": {27, 91, 52, 53, 109},
   165  	"BG-CYAN":    {27, 91, 52, 54, 109},
   166  	"BG-WHITE":   {27, 91, 52, 55, 109},
   167  
   168  	"BG-BLACK-BRIGHT":   {27, 91, 49, 59, 52, 48, 109},
   169  	"BG-RED-BRIGHT":     {27, 91, 49, 59, 52, 48, 109},
   170  	"BG-GREEN-BRIGHT":   {27, 91, 49, 59, 52, 48, 109},
   171  	"BG-YELLOW-BRIGHT":  {27, 91, 49, 59, 52, 48, 109},
   172  	"BG-BLUE-BRIGHT":    {27, 91, 49, 59, 52, 48, 109},
   173  	"BG-MAGENTA-BRIGHT": {27, 91, 49, 59, 52, 48, 109},
   174  	"BG-CYAN-BRIGHT":    {27, 91, 49, 59, 52, 48, 109},
   175  	"BG-WHITE-BRIGHT":   {27, 91, 49, 59, 52, 48, 109},
   176  }
   177  ```
   178  
   179  ### How To Read The Code Above
   180  
   181  Each line will look something a little like
   182  
   183  ```
   184  "GREEN":   {27, 91, 51, 50, 109},
   185  ```
   186  
   187  The part within quotes is the constant name, and the part that follows is the
   188  sequence of bytes that are infixed.
   189  
   190  So the example above will replace `{GREEN}` from within a string with the
   191  byte values of 27, 91, 51, 50 and 109 (in that order).
   192  
   193  ## Unsupported Constants
   194  
   195  If a constant does not exist in the above code, then the infix string is left
   196  unedited.
   197  
   198  ```
   199  # Green spelt correctly
   200  » out "{GREEN}PASSED{RESET}"
   201  PASSED
   202  
   203  # Green spelt incorrectly (ie so that it doesn't exist as a valid constant)
   204  » out "{GREEEEN}PASSED{RESET}"
   205  {GREEEEN}PASSED
   206  ```
   207  
   208  ## Enabling / Disabling ANSI Escape Sequences
   209  
   210  These sequences are enabled by default. To disable run the following:
   211  
   212  ```
   213  » config set shell color false
   214  ```
   215  
   216  You will need to add this to your Murex profile, `~/.murex_profile` to make
   217  it persistent.
   218  
   219  ## See Also
   220  
   221  * [Profile Files](../user-guide/profile.md):
   222    A breakdown of the different files loaded on start up
   223  * [`%(Brace Quote)`](../parser/brace-quote.md):
   224    Initiates or terminates a string (variables expanded)
   225  * [`(brace quote)`](../parser/brace-quote-func.md):
   226    Write a string to the STDOUT without new line (deprecated)
   227  * [`err`](../commands/err.md):
   228    Print a line to the STDERR
   229  * [`out`](../commands/out.md):
   230    Print a string to the STDOUT with a trailing new line character
   231  * [`tout`](../commands/tout.md):
   232    Print a string to the STDOUT and set it's data-type
   233  
   234  <hr/>
   235  
   236  This document was generated from [gen/user-guide/ansi_doc.yaml](https://github.com/lmorg/murex/blob/master/gen/user-guide/ansi_doc.yaml).