ANSI-Project 1.0
Make quick ANSI formats to beautify terminal output
Macros
ansi.h File Reference
#include <stdio.h>

Go to the source code of this file.

Macros

#define ANSI_ESC   "\x1B"
 
#define ANSI_CSI   "\x9B"
 
#define ANSI_DSC   "\x90"
 
#define ANSI_OSC   "\x9D"
 
#define ANSI_RESET   ANSI_ESC "[0m"
 
#define ANSI_BOLD   ANSI_ESC "[1m"
 
#define ANSI_FAINT   ANSI_ESC "[2m"
 
#define ANSI_ITALIC   ANSI_ESC "[3m"
 
#define ANSI_UNDER   ANSI_ESC "[4m"
 
#define ANSI_SBLINK   ANSI_ESC "[5m"
 
#define ANSI_RBLINK   ANSI_ESC "[6m"
 
#define ANSI_REVERSE   ANSI_ESC "[7m"
 
#define ANSI_HIDE   ANSI_ESC "[8m"
 
#define ANSI_STRIKE   ANSI_ESC "[9m"
 
#define ANSI_DEF_FONT   ANSI_ESC "[10m"
 
#define ANSI_Franktur   ANSI_ESC "[20m"
 
#define ANSI_BOLD_OFF   ANSI_ESC "[21m"
 
#define ANSI_HI_OFF   ANSI_ESC "[22m"
 
#define ANSI_ITALIC_OFF   ANSI_ESC "[23m"
 
#define ANSI_UNDER_OFF   ANSI_ESC "[24m"
 
#define ANSI_BLINK_OFF   ANSI_ESC "[25m"
 
#define ANSI_REVERSE_OFF   ANSI_ESC "[27m"
 
#define ANSI_REVEAL   ANSI_ESC "[28m"
 
#define ANSI_STRIKE_OFF   ANSI_ESC "[29m"
 
#define ANSI_BLACK   ANSI_ESC "[30m"
 
#define ANSI_RED   ANSI_ESC "[31m"
 
#define ANSI_GREEN   ANSI_ESC "[32m"
 
#define ANSI_YELLOW   ANSI_ESC "[33m"
 
#define ANSI_BLUE   ANSI_ESC "[34m"
 
#define ANSI_PURPLE   ANSI_ESC "[35m"
 
#define ANSI_CYAN   ANSI_ESC "[36m"
 
#define ANSI_WHITE   ANSI_ESC "[37m"
 
#define ANSI_DEFAULT   ANSI_ESC "[39m"
 
#define ANSI_BK_BLACK   ANSI_ESC "[40m"
 
#define ANSI_BK_RED   ANSI_ESC "[41m"
 
#define ANSI_BK_GREEN   ANSI_ESC "[42m"
 
#define ANSI_BK_YELLOW   ANSI_ESC "[43m"
 
#define ANSI_BK_BLUE   ANSI_ESC "[44m"
 
#define ANSI_BK_PURPLE   ANSI_ESC "[45m"
 
#define ANSI_BK_CYAN   ANSI_ESC "[46m"
 
#define ANSI_BK_WHITE   ANSI_ESC "[47m"
 
#define ANSI_BK_DEFAULT   ANSI_ESC "[49m"
 
#define ANSI_BLACK_HI   ANSI_ESC "[90m"
 
#define ANSI_RED_HI   ANSI_ESC "[91m"
 
#define ANSI_GREEN_HI   ANSI_ESC "[92m"
 
#define ANSI_YELLOW_HI   ANSI_ESC "[93m"
 
#define ANSI_BLUE_HI   ANSI_ESC "[94m"
 
#define ANSI_PURPLE_HI   ANSI_ESC "[95m"
 
#define ANSI_CYAN_HI   ANSI_ESC "[96m"
 
#define ANSI_WHITE_HI   ANSI_ESC "[97m"
 
#define ANSI_BK_BLACK_HI   ANSI_ESC "[100m"
 
#define ANSI_BK_RED_HI   ANSI_ESC "[101m"
 
#define ANSI_BK_GREEN_HI   ANSI_ESC "[102m"
 
#define ANSI_BK_YELLOW_HI   ANSI_ESC "[103m"
 
#define ANSI_BK_BLUE_HI   ANSI_ESC "[104m"
 
#define ANSI_BK_PURPLE_HI   ANSI_ESC "[105m"
 
#define ANSI_BK_CYAN_HI   ANSI_ESC "[106m"
 
#define ANSI_BK_WHITE_HI   ANSI_ESC "[107m"
 
#define ANSI_SGR(str)   ANSI_ESC "[" #str "m"
 
#define ANSI_RGB(r, g, b)   ANSI_ESC "[38;2;" #r ";" #g ";" #b "m"
 
#define ANSI_BK_RGB(r, g, b)   ANSI_ESC "[48;2;" #r ";" #g ";" #b "m"
 
#define ANSI_C0   ANSI_ESC "[1;1H"
 
#define ANSI_CUU1   ANSI_ESC "[1A"
 
#define ANSI_CUD1   ANSI_ESC "[1B"
 
#define ANSI_CUF1   ANSI_ESC "[1C"
 
#define ANSI_CUB1   ANSI_ESC "[1D"
 
#define ANSI_CNL1   ANSI_ESC "[1E"
 
#define ANSI_CPL1   ANSI_ESC "[1F"
 
#define ANSI_SU1   ANSI_ESC "[1S"
 
#define ANSI_SD1   ANSI_ESC "[1T"
 
#define ANSI_ED0   ANSI_ESC "[0J"
 
#define ANSI_ED1   ANSI_ESC "[1J"
 
#define ANSI_ED2   ANSI_ESC "[2J"
 
#define ANSI_ED3   ANSI_ESC "[3J"
 
#define ANSI_EL0   ANSI_ESC "[0K"
 
#define ANSI_EL1   ANSI_ESC "[1K"
 
#define ANSI_EL2   ANSI_ESC "[2K"
 
#define ANSI_AUX_PORT_ON   ANSI_ESC "[5i"
 
#define ANSI_AUX_PORT_OFF   ANSI_ESC "[4i"
 
#define ANSI_DSR   ANSI_ESC "[6n"
 
#define ANSI_SCP   ANSI_ESC "[s"
 
#define ANSI_RCP   ANSI_ESC "[u"
 
#define ANSI_CUU(n)   ANSI_ESC "[" #n "A"
 
#define ANSI_CUD(n)   ANSI_ESC "[" #n "B"
 
#define ANSI_CUF(n)   ANSI_ESC "[" #n "C"
 
#define ANSI_CUB(n)   ANSI_ESC "[" #n "D"
 
#define ANSI_CNL(n)   ANSI_ESC "[" #n "E"
 
#define ANSI_CPL(n)   ANSI_ESC "[" #n "F"
 
#define ANSI_CHA(n)   ANSI_ESC "[" #n "G"
 
#define ANSI_CUP(row, col)   ANSI_ESC "[" #row ";" #col "H"
 
#define ANSI_ED(n)   ANSI_ESC "[" #n "J"
 
#define ANSI_EL(n)   ANSI_ESC "[" #n "K"
 
#define ANSI_SU(n)   ANSI_ESC "[" #n "S"
 
#define ANSI_SD(n)   ANSI_ESC "[" #n "T"
 
#define ANSI_HVP(row, col)   ANSI_ESC "[" #row ";" #col "f"
 
#define ANSI_custom(str)   ANSI_ESC "[" #str
 

Macro Definition Documentation

◆ ANSI_AUX_PORT_OFF

#define ANSI_AUX_PORT_OFF   ANSI_ESC "[4i"

Enable aux serial port usually for local serial printer

Returns
ESC [4i

◆ ANSI_AUX_PORT_ON

#define ANSI_AUX_PORT_ON   ANSI_ESC "[5i"

Enable aux serial port usually for local serial printer

Returns
ESC [5i

◆ ANSI_BK_BLACK

#define ANSI_BK_BLACK   ANSI_ESC "[40m"

◆ ANSI_BK_BLACK_HI

#define ANSI_BK_BLACK_HI   ANSI_ESC "[100m"

◆ ANSI_BK_BLUE

#define ANSI_BK_BLUE   ANSI_ESC "[44m"

◆ ANSI_BK_BLUE_HI

#define ANSI_BK_BLUE_HI   ANSI_ESC "[104m"

◆ ANSI_BK_CYAN

#define ANSI_BK_CYAN   ANSI_ESC "[46m"

◆ ANSI_BK_CYAN_HI

#define ANSI_BK_CYAN_HI   ANSI_ESC "[106m"

◆ ANSI_BK_DEFAULT

#define ANSI_BK_DEFAULT   ANSI_ESC "[49m"

◆ ANSI_BK_GREEN

#define ANSI_BK_GREEN   ANSI_ESC "[42m"

◆ ANSI_BK_GREEN_HI

#define ANSI_BK_GREEN_HI   ANSI_ESC "[102m"

◆ ANSI_BK_PURPLE

#define ANSI_BK_PURPLE   ANSI_ESC "[45m"

◆ ANSI_BK_PURPLE_HI

#define ANSI_BK_PURPLE_HI   ANSI_ESC "[105m"

◆ ANSI_BK_RED

#define ANSI_BK_RED   ANSI_ESC "[41m"

◆ ANSI_BK_RED_HI

#define ANSI_BK_RED_HI   ANSI_ESC "[101m"

◆ ANSI_BK_RGB

#define ANSI_BK_RGB (   r,
  g,
 
)    ANSI_ESC "[48;2;" #r ";" #g ";" #b "m"

Specify the Background color in RGB

Parameters
rRed value
gGreen value
bBlue value
Returns
String to be printed

◆ ANSI_BK_WHITE

#define ANSI_BK_WHITE   ANSI_ESC "[47m"

◆ ANSI_BK_WHITE_HI

#define ANSI_BK_WHITE_HI   ANSI_ESC "[107m"

◆ ANSI_BK_YELLOW

#define ANSI_BK_YELLOW   ANSI_ESC "[43m"

◆ ANSI_BK_YELLOW_HI

#define ANSI_BK_YELLOW_HI   ANSI_ESC "[103m"

◆ ANSI_BLACK

#define ANSI_BLACK   ANSI_ESC "[30m"

◆ ANSI_BLACK_HI

#define ANSI_BLACK_HI   ANSI_ESC "[90m"

◆ ANSI_BLINK_OFF

#define ANSI_BLINK_OFF   ANSI_ESC "[25m"

◆ ANSI_BLUE

#define ANSI_BLUE   ANSI_ESC "[34m"

◆ ANSI_BLUE_HI

#define ANSI_BLUE_HI   ANSI_ESC "[94m"

◆ ANSI_BOLD

#define ANSI_BOLD   ANSI_ESC "[1m"

◆ ANSI_BOLD_OFF

#define ANSI_BOLD_OFF   ANSI_ESC "[21m"

◆ ANSI_C0

#define ANSI_C0   ANSI_ESC "[1;1H"

Place the cursor in top-left corner Same as CUP(1,1)

Returns
ESC [1;1H

◆ ANSI_CHA

#define ANSI_CHA (   n)    ANSI_ESC "[" #n "G"

Moves the cursor to column n (default 1)

Parameters
n
Returns
String to be printed

◆ ANSI_CNL

#define ANSI_CNL (   n)    ANSI_ESC "[" #n "E"

Moves cursor to beginning of the line n (default 1) lines down.

Parameters
n
Returns
String to be printed

◆ ANSI_CNL1

#define ANSI_CNL1   ANSI_ESC "[1E"

Moves cursor to beginning of the next line

Returns
ESC [1E

◆ ANSI_CPL

#define ANSI_CPL (   n)    ANSI_ESC "[" #n "F"

Moves cursor to beginning of the line n (default 1) lines up.

Parameters
n
Returns
String to be printed

◆ ANSI_CPL1

#define ANSI_CPL1   ANSI_ESC "[1F"

Moves cursor to beginning of the previous line

Returns
ESC [1F

◆ ANSI_CSI

#define ANSI_CSI   "\x9B"

◆ ANSI_CUB

#define ANSI_CUB (   n)    ANSI_ESC "[" #n "D"

Moves the cursor n (default 1) cells backwards

Parameters
n
Returns
String to be printed

◆ ANSI_CUB1

#define ANSI_CUB1   ANSI_ESC "[1D"

Move the cursor 1 cell backwards

Returns
ESC [1D

◆ ANSI_CUD

#define ANSI_CUD (   n)    ANSI_ESC "[" #n "B"

Moves the cursor n (default 1) cells down

Parameters
n
Returns
String to be printed

◆ ANSI_CUD1

#define ANSI_CUD1   ANSI_ESC "[1B"

Move the cursor 1 row down

Returns
ESC [1B

◆ ANSI_CUF

#define ANSI_CUF (   n)    ANSI_ESC "[" #n "C"

Moves the cursor n (default 1) cells forwards

Parameters
n
Returns
String to be printed

◆ ANSI_CUF1

#define ANSI_CUF1   ANSI_ESC "[1C"

Move the cursor 1 cell forwards

Returns
ESC [1C

◆ ANSI_CUP

#define ANSI_CUP (   row,
  col 
)    ANSI_ESC "[" #row ";" #col "H"

Moves the cursor to [row, column]. The values are 1-based.

Parameters
row
col
Returns
String to be printed

◆ ANSI_custom

#define ANSI_custom (   str)    ANSI_ESC "[" #str

Returns a custom ANSI ESCAPE SEQUENCE

Parameters
str
Returns
ESC "[" str

◆ ANSI_CUU

#define ANSI_CUU (   n)    ANSI_ESC "[" #n "A"

Moves the cursor n (default 1) cells up

Parameters
n
Returns
String to be printed

◆ ANSI_CUU1

#define ANSI_CUU1   ANSI_ESC "[1A"

Move the cursor 1 row up

Returns
ESC [1A

◆ ANSI_CYAN

#define ANSI_CYAN   ANSI_ESC "[36m"

◆ ANSI_CYAN_HI

#define ANSI_CYAN_HI   ANSI_ESC "[96m"

◆ ANSI_DEF_FONT

#define ANSI_DEF_FONT   ANSI_ESC "[10m"

Default font

◆ ANSI_DEFAULT

#define ANSI_DEFAULT   ANSI_ESC "[39m"

◆ ANSI_DSC

#define ANSI_DSC   "\x90"

◆ ANSI_DSR

#define ANSI_DSR   ANSI_ESC "[6n"

Reports the cursor position (CPR) by transmitting ESC[n;mR, where n is the row and m is the column.

Returns
ESC [6n

◆ ANSI_ED

#define ANSI_ED (   n)    ANSI_ESC "[" #n "J"

Clears part of the screen. If n is 0 (or missing), clear from cursor to end of screen. If n is 1, clear from cursor to beginning of the screen. If n is 2, clear entire screen (and moves cursor to upper left on DOS ANSI.SYS). If n is 3, clear entire screen and delete all lines saved in the scrollback buffer (this feature was added for xterm and is supported by other terminal applications).

Parameters
n
Returns
String to be printed

◆ ANSI_ED0

#define ANSI_ED0   ANSI_ESC "[0J"

Clear from cursor to end of screen.

Returns
ESC [0J

◆ ANSI_ED1

#define ANSI_ED1   ANSI_ESC "[1J"

Clear from cursor to beginning of the screen

Returns
ESC [1J

◆ ANSI_ED2

#define ANSI_ED2   ANSI_ESC "[2J"

Clear entire screen (and moves cursor to upper left on DOS ANSI.SYS)

Returns
ESC [2J

◆ ANSI_ED3

#define ANSI_ED3   ANSI_ESC "[3J"

Clear entire screen and delete all lines saved in the scrollback buffer (this feature was added for xterm and is supported by other terminal applications)

Returns
ESC [3J

◆ ANSI_EL

#define ANSI_EL (   n)    ANSI_ESC "[" #n "K"

Erases part of the line If n is 0 (or missing), clear from cursor to the end of the line If n is 1, clear from cursor to beginning of the line If n is 2, clear entire line. Cursor position does not change.

Parameters
n
Returns
String to be printed

◆ ANSI_EL0

#define ANSI_EL0   ANSI_ESC "[0K"

Clear from cursor to the end of the line

Returns
ESC [0K

◆ ANSI_EL1

#define ANSI_EL1   ANSI_ESC "[1K"

Clear from cursor to beginning of the line

Returns
ESC [1K

◆ ANSI_EL2

#define ANSI_EL2   ANSI_ESC "[2K"

Clear entire line. Cursor position does not change.

Returns
ESC [2K

◆ ANSI_ESC

#define ANSI_ESC   "\x1B"

◆ ANSI_FAINT

#define ANSI_FAINT   ANSI_ESC "[2m"

◆ ANSI_Franktur

#define ANSI_Franktur   ANSI_ESC "[20m"

Rarely supported font

◆ ANSI_GREEN

#define ANSI_GREEN   ANSI_ESC "[32m"

◆ ANSI_GREEN_HI

#define ANSI_GREEN_HI   ANSI_ESC "[92m"

◆ ANSI_HI_OFF

#define ANSI_HI_OFF   ANSI_ESC "[22m"

◆ ANSI_HIDE

#define ANSI_HIDE   ANSI_ESC "[8m"

◆ ANSI_HVP

#define ANSI_HVP (   row,
  col 
)    ANSI_ESC "[" #row ";" #col "f"

Same as CUP, but counts as a format effector function (like CR or LF) rather than an editor function (like CUD or CNL) This can lead to different handling in certain terminal modes

Parameters
row
col
Returns
String to be printed

◆ ANSI_ITALIC

#define ANSI_ITALIC   ANSI_ESC "[3m"

◆ ANSI_ITALIC_OFF

#define ANSI_ITALIC_OFF   ANSI_ESC "[23m"

◆ ANSI_OSC

#define ANSI_OSC   "\x9D"

◆ ANSI_PURPLE

#define ANSI_PURPLE   ANSI_ESC "[35m"

◆ ANSI_PURPLE_HI

#define ANSI_PURPLE_HI   ANSI_ESC "[95m"

◆ ANSI_RBLINK

#define ANSI_RBLINK   ANSI_ESC "[6m"

◆ ANSI_RCP

#define ANSI_RCP   ANSI_ESC "[u"

Restores the cursor position/state in SCO console mode.

Returns
ESC [u

◆ ANSI_RED

#define ANSI_RED   ANSI_ESC "[31m"

◆ ANSI_RED_HI

#define ANSI_RED_HI   ANSI_ESC "[91m"

◆ ANSI_RESET

#define ANSI_RESET   ANSI_ESC "[0m"

◆ ANSI_REVEAL

#define ANSI_REVEAL   ANSI_ESC "[28m"

◆ ANSI_REVERSE

#define ANSI_REVERSE   ANSI_ESC "[7m"

◆ ANSI_REVERSE_OFF

#define ANSI_REVERSE_OFF   ANSI_ESC "[27m"

◆ ANSI_RGB

#define ANSI_RGB (   r,
  g,
 
)    ANSI_ESC "[38;2;" #r ";" #g ";" #b "m"

Specify the Foreground color in RGB

Parameters
rRed value
gGreen value
bBlue value
Returns
String to be printed

◆ ANSI_SBLINK

#define ANSI_SBLINK   ANSI_ESC "[5m"

◆ ANSI_SCP

#define ANSI_SCP   ANSI_ESC "[s"

Saves the cursor position/state in SCO console mode In vertical split screen mode, instead used to set (as CSI n ; n s) or reset left and right margins.

Returns
ESC [s

◆ ANSI_SD

#define ANSI_SD (   n)    ANSI_ESC "[" #n "T"

Scroll whole page down by n (default 1) lines. New lines are added at the top. (not ANSI.SYS)

Parameters
n
Returns
String to be printed

◆ ANSI_SD1

#define ANSI_SD1   ANSI_ESC "[1T"

Scroll whole page down by 1 line

Returns
ESC [1T

◆ ANSI_SGR

#define ANSI_SGR (   str)    ANSI_ESC "[" #str "m"

Sets colors and style of the characters following this code Example: ANSI_SGR(40;91) makes RED_HI over BK_BLACK

Parameters
str

◆ ANSI_STRIKE

#define ANSI_STRIKE   ANSI_ESC "[9m"

◆ ANSI_STRIKE_OFF

#define ANSI_STRIKE_OFF   ANSI_ESC "[29m"

◆ ANSI_SU

#define ANSI_SU (   n)    ANSI_ESC "[" #n "S"

Scroll whole page up by n (default 1) lines. New lines are added at the bottom. (not ANSI.SYS)

Parameters
n
Returns
String to be printed

◆ ANSI_SU1

#define ANSI_SU1   ANSI_ESC "[1S"

Scroll whole page up by 1 line

Returns
ESC [1S

◆ ANSI_UNDER

#define ANSI_UNDER   ANSI_ESC "[4m"

◆ ANSI_UNDER_OFF

#define ANSI_UNDER_OFF   ANSI_ESC "[24m"

◆ ANSI_WHITE

#define ANSI_WHITE   ANSI_ESC "[37m"

◆ ANSI_WHITE_HI

#define ANSI_WHITE_HI   ANSI_ESC "[97m"

◆ ANSI_YELLOW

#define ANSI_YELLOW   ANSI_ESC "[33m"

◆ ANSI_YELLOW_HI

#define ANSI_YELLOW_HI   ANSI_ESC "[93m"