ANSIEscapeCode.Cursor.showCursor // \u{001B}[?25h
showCursor() // Show cursor.
Erase
Erase in Display
\u{001B}[(n)J: Clear 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.
ANSIEscapeCode.Erase.eraseInDisplay(.entireScreen) // \u{001B}[2J
eraseInDisplay(.fromCursorToBeginningOfScreen) // Erase content from cursor to beginning of screen.
Erase in Line
\u{001B}[(n)K: Erase part of the line. If n is zero (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.
ANSIEscapeCode
Control terminal cursor and font or erase content. Build modern, interactive command line tool with colorful and dynamic output strings.
https://en.wikipedia.org/wiki/ANSI_escape_code
Table of Contents
Installation
Add ANSIEscapeCode to
Package.swift
.Cursor
Up
\u{001B}[(n)A
: Move cursor upn
(default 1) cells.Down
\u{001B}[(n)B
: Move cursor downn
(default 1) cells.Forward
\u{001B}[(n)C
: Move cursor forwardn
(default 1) cells.Backward
\u{001B}[(n)D
: Move cursor backwardn
(default 1) cells.Next Line
\u{001B}[(n)E
: Move cursor to beginning of the linen
(default 1) lines down.Previous Line
\u{001B}[(n)F
: Move cursor to beginning of the linen
(default 1) lines up.Column
\u{001B}[(n)G
: Move cursor to columnn
.Position
\u{001B}[(n);(m)1H
: Move cursor to rown
, columnm
.Save Position
\u{001B}[s
: Save cursor position.Restore Position
\u{001B}[u
: Restore cursor position.Hide
\u{001B}[?25l
: Hide cursor.Show
\u{001B}[?25h
: Show cursor.Erase
Erase in Display
\u{001B}[(n)J
: Clear part of the screen. Ifn
is 0 (or missing), clear from cursor to end of screen. Ifn
is 1, clear from cursor to beginning of the screen. Ifn
is 2, clear entire screen.Erase in Line
\u{001B}[(n)K
: Erase part of the line. Ifn
is zero (or missing), clear from cursor to the end of the line. Ifn
is 1, clear from cursor to beginning of the line. Ifn
is 2, clear entire line. Cursor position does not change.Scroll
Scroll Up
\u{001B}[(n)S
: Scroll whole page up byn
(default 1) lines. New lines are added at the bottom.Scroll Down
\u{001B}[(n)T
: Scroll whole page down byn
(default 1) lines. New lines are added at the top.Decoration
Reset
\u{001B}[0m
: Reset all decoration attributes.Reset Background Color
\u{001B}[39m
: Reset background decoration attributes.Bold
\u{001B}[1m
: Make output bold.Italic
\u{001B}[3m
: Make output italic.Underline
\u{001B}[4m
: Make output have underline.Blink
\u{001B}[5m
: Make output blink.Text Color
\u{001B}[(COLOR)m
Set text color on terminal. CheckTextColor.swift
for available colors.Text 8 Bits Color
\u{001B}[38;5;(COLOR)m
Set text 8 bits color on terminal. Check here for available colors.Text RGB Color
\u{001B}[38;2;(RED);(GREEN);(BLUE)m
Set text RGB color on terminal. Check here for more.Background Color
\u{001B}[(COLOR)m
Set text background color on terminal. CheckBackgroundColor.swift
for available colors.Background 8 Bits Color
\u{001B}[38;5;(COLOR)m
Set text background 8 bits color on terminal. Check here for available colors.Background RGB Color
\u{001B}[48;2;(RED);(GREEN);(BLUE)m
Set text background RGB color on terminal. Check here for more.Contribute
If you have good idea or suggestion? Please, don’t hesitate to open a pull request or send me an email.
Hope you enjoy building command line tool with ANSIEscapeCode!