package core:terminal/ansi
Overview
Constant references to many widely-supported ANSI escape codes.
Primarily used in terminal emulators for enhanced graphics, such as colors, text styling, and animated displays.
For example, you can print out a line of cyan text like this:
fmt.println(ansi.CSI + ansi.FG_CYAN + ansi.SGR + "Hellope!" + ansi.CSI + ansi.RESET + ansi.SGR)
The helper procedures can also be used to color text and control the terminal:
fmt.println(ansi.color("Hellope!", ansi.FG_CYAN))
fmt.print(ansi.clear_screen() + ansi.hide_cursor() + ansi.enter_alt_screen())
fmt.print(ansi.move_cursor(2, 4) + "Hellope!")
fmt.print(ansi.exit_alt_screen() + ansi.show_cursor())
Formatting helpers also accept a caller-provided buffer to avoid allocating:
sgr_buf: [len(ansi.FG_CYAN) + 3]byte fmt.print(ansi.sgr(sgr_buf[:], ansi.FG_CYAN)) cursor_buf: [ansi.CURSOR_SEQUENCE_BUF_MAX]byte fmt.print(ansi.move_cursor(cursor_buf[:], 2, 4))
Multiple SGR (Select Graphic Rendition) codes can be joined by semicolons:
fmt.println(ansi.CSI + ansi.BOLD + ";" + ansi.FG_BLUE + ansi.SGR + "Hellope!" + ansi.CSI + ansi.RESET + ansi.SGR)
If your terminal supports 24-bit true color mode, you can also do this:
fmt.println(ansi.CSI + ansi.FG_COLOR_24_BIT + ";0;255;255" + ansi.SGR + "Hellope!" + ansi.CSI + ansi.RESET + ansi.SGR)
For more information, see:
Index
Types (0)
This section is empty.
Constants (113)
- AUX_OFF
- AUX_ON
- BEL
- BLINK_RAPID
- BLINK_SLOW
- BOLD
- BS
- CHA
- CLIPBOARD
- CNL
- CPL
- CSI
- CUB
- CUD
- CUF
- CUP
- CURSOR_SEQUENCE_BUF_MAX
- CUU
- DECASB_ENTER
- DECASB_EXIT
- DECAWM_OFF
- DECAWM_ON
- DECRC
- DECSC
- DECTCEM_HIDE
- DECTCEM_SHOW
- DSR
- ED
- EL
- ENCIRCLED
- ESC
- FAINT
- FRAMED
- HIDE
- HVP
- HYPERLINK
- INVERT
- ITALIC
- OSC
- OVERLINED
- PROPORTIONAL_SPACING
- RCP
- RESET
- SCP
- SD
- SGR
- ST
- STRIKE
- SU
- UNDERLINE
- UNDERLINE_DOUBLE
- WINDOW_TITLE
Variables (0)
This section is empty.
Procedures (29)
Types
This section is empty.
Constants
BG_BLACK ¶
BG_BLACK :: "40"
BG_BLUE ¶
BG_BLUE :: "44"
BG_BRIGHT_BLUE ¶
BG_BRIGHT_BLUE :: "104"
BG_BRIGHT_CYAN ¶
BG_BRIGHT_CYAN :: "106"
BG_BRIGHT_GREEN ¶
BG_BRIGHT_GREEN :: "102"
BG_BRIGHT_MAGENTA ¶
BG_BRIGHT_MAGENTA :: "105"
BG_BRIGHT_RED ¶
BG_BRIGHT_RED :: "101"
BG_BRIGHT_WHITE ¶
BG_BRIGHT_WHITE :: "107"
BG_BRIGHT_YELLOW ¶
BG_BRIGHT_YELLOW :: "103"
BG_COLOR ¶
BG_COLOR :: "48"
BG_CYAN ¶
BG_CYAN :: "46"
BG_DEFAULT ¶
BG_DEFAULT :: "49"
BG_GREEN ¶
BG_GREEN :: "42"
BG_MAGENTA ¶
BG_MAGENTA :: "45"
BG_RED ¶
BG_RED :: "41"
BG_WHITE ¶
BG_WHITE :: "47"
BG_YELLOW ¶
BG_YELLOW :: "43"
BLINK_SLOW ¶
BLINK_SLOW :: "5"
BOLD ¶
BOLD :: "1"
CURSOR_SEQUENCE_BUF_MAX ¶
CURSOR_SEQUENCE_BUF_MAX :: 4 + 6 * size_of(int)
Buffer size sufficient for any cursor movement helper, including move_cursor, for all values representable by int. SGR and color helpers depend on the lengths of their string arguments and have no fixed maximum buffer size.
ENCIRCLED ¶
ENCIRCLED :: "52"
FAINT ¶
FAINT :: "2"
FG_BLACK ¶
FG_BLACK :: "30"
FG_BLUE ¶
FG_BLUE :: "34"
FG_BRIGHT_BLUE ¶
FG_BRIGHT_BLUE :: "94"
FG_BRIGHT_CYAN ¶
FG_BRIGHT_CYAN :: "96"
FG_BRIGHT_GREEN ¶
FG_BRIGHT_GREEN :: "92"
FG_BRIGHT_MAGENTA ¶
FG_BRIGHT_MAGENTA :: "95"
FG_BRIGHT_RED ¶
FG_BRIGHT_RED :: "91"
FG_BRIGHT_WHITE ¶
FG_BRIGHT_WHITE :: "97"
FG_BRIGHT_YELLOW ¶
FG_BRIGHT_YELLOW :: "93"
FG_COLOR ¶
FG_COLOR :: "38"
FG_CYAN ¶
FG_CYAN :: "36"
FG_DEFAULT ¶
FG_DEFAULT :: "39"
FG_GREEN ¶
FG_GREEN :: "32"
FG_MAGENTA ¶
FG_MAGENTA :: "35"
FG_RED ¶
FG_RED :: "31"
FG_WHITE ¶
FG_WHITE :: "37"
FG_YELLOW ¶
FG_YELLOW :: "33"
FONT_ALT1 ¶
FONT_ALT1 :: "11"
FONT_ALT2 ¶
FONT_ALT2 :: "12"
FONT_ALT3 ¶
FONT_ALT3 :: "13"
FONT_ALT4 ¶
FONT_ALT4 :: "14"
FONT_ALT5 ¶
FONT_ALT5 :: "15"
FONT_ALT6 ¶
FONT_ALT6 :: "16"
FONT_ALT7 ¶
FONT_ALT7 :: "17"
FONT_ALT8 ¶
FONT_ALT8 :: "18"
FONT_ALT9 ¶
FONT_ALT9 :: "19"
FONT_PRIMARY ¶
FONT_PRIMARY :: "10"
FRAMED ¶
FRAMED :: "51"
NO_BLINK ¶
NO_BLINK :: "25"
NO_BOLD_FAINT ¶
NO_BOLD_FAINT :: "22"
NO_FRAME_ENCIRCLE ¶
NO_FRAME_ENCIRCLE :: "54"
NO_HIDE ¶
NO_HIDE :: "28"
NO_ITALIC_BLACKLETTER ¶
NO_ITALIC_BLACKLETTER :: "23"
NO_OVERLINE ¶
NO_OVERLINE :: "55"
NO_PROPORTIONAL_SPACING ¶
NO_PROPORTIONAL_SPACING :: "50"
NO_REVERSE ¶
NO_REVERSE :: "27"
NO_STRIKE ¶
NO_STRIKE :: "29"
NO_UNDERLINE ¶
NO_UNDERLINE :: "24"
OVERLINED ¶
OVERLINED :: "53"
PROPORTIONAL_SPACING ¶
PROPORTIONAL_SPACING :: "26"
RESET ¶
RESET :: "0"
STRIKE ¶
STRIKE :: "9"
UNDERLINE ¶
UNDERLINE :: "4"
Variables
This section is empty.
Procedures
clear_display_to_end ¶
clear_display_to_end :: proc() -> string {…}
clear_line ¶
clear_line :: proc() -> string {…}
clear_screen ¶
clear_screen :: proc() -> string {…}
Returns a sequence that clears the screen and moves the cursor to the home position.
clear_to_end_of_line ¶
clear_to_end_of_line :: proc() -> string {…}
clear_to_start_of_line ¶
clear_to_start_of_line :: proc() -> string {…}
color_alloc ¶
color_alloc :: proc(text: any, codes: string, allocator := context.temp_allocator) -> string {…}
disable_auto_wrap ¶
disable_auto_wrap :: proc() -> string {…}
enable_auto_wrap ¶
enable_auto_wrap :: proc() -> string {…}
enter_alt_screen ¶
enter_alt_screen :: proc() -> string {…}
exit_alt_screen ¶
exit_alt_screen :: proc() -> string {…}
hide_cursor ¶
hide_cursor :: proc "contextless" () -> string {…}
move_cursor_alloc ¶
move_cursor_alloc :: proc(row, column: int, allocator := context.temp_allocator) -> string {…}
move_cursor_backward_alloc ¶
move_cursor_backward_alloc :: proc( count: int = 1, allocator := context.temp_allocator, ) -> string {…}
move_cursor_down_alloc ¶
move_cursor_down_alloc :: proc(count: int = 1, allocator := context.temp_allocator) -> string {…}
move_cursor_forward_alloc ¶
move_cursor_forward_alloc :: proc( count: int = 1, allocator := context.temp_allocator, ) -> string {…}
move_cursor_previous_line_alloc ¶
move_cursor_previous_line_alloc :: proc( count: int = 1, allocator := context.temp_allocator, ) -> string {…}
move_cursor_up_alloc ¶
move_cursor_up_alloc :: proc(count: int = 1, allocator := context.temp_allocator) -> string {…}
restore_cursor ¶
restore_cursor :: proc() -> string {…}
save_cursor ¶
save_cursor :: proc() -> string {…}
sgr_alloc ¶
sgr_alloc :: proc(code: string, allocator := context.temp_allocator) -> string {…}
show_cursor ¶
show_cursor :: proc "contextless" () -> string {…}
Procedure Groups
color ¶
color :: proc{ color_alloc, color_buf, }
Wraps text in an SGR style and resets the style afterward.
codes may contain multiple semicolon-separated SGR parameters, such as
BOLD + ";" + FG_RED or FG_COLOR_24_BIT + ";255;0;0".
The buffer form requires enough space for the %v representation of text,
codes, and the surrounding escape sequences.
move_cursor ¶
move_cursor :: proc{ move_cursor_alloc, move_cursor_buf, }
move_cursor_backward ¶
move_cursor_backward :: proc{ move_cursor_backward_alloc, move_cursor_backward_buf, }
move_cursor_down ¶
move_cursor_down :: proc{ move_cursor_down_alloc, move_cursor_down_buf, }
move_cursor_forward ¶
move_cursor_forward :: proc{ move_cursor_forward_alloc, move_cursor_forward_buf, }
move_cursor_previous_line ¶
move_cursor_previous_line :: proc{ move_cursor_previous_line_alloc, move_cursor_previous_line_buf, }
move_cursor_up ¶
move_cursor_up :: proc{ move_cursor_up_alloc, move_cursor_up_buf, }
Source Files
Generation Information
Generated with odin version dev-2026-11 (vendor "odin") Windows_amd64 @ 2026-11-18 21:05:19.828955300 +0000 UTC