Documentation
¶
Index ¶
- Constants
- Variables
- func CursorMove(x, y int) string
- func CursorPos(x, y int) string
- func CursorPosX(x int) string
- func CursorPosY(y int) string
- func DisableVirtualTerminal(fd uintptr) error
- func EnableVirtualTerminal(fd uintptr) error
- func Image(img []byte) string
- func ImageWidthHeight(img []byte, height, width int, preserveAspectRatio bool) string
- func Link(url, text string) string
- func Optional(sequence string) string
- func Scroll(n int) string
- func SetCwd(dir string) string
- func TextDeleteChars(n int) string
- func TextDeleteLines(n int) string
- func TextEraseChars(n int) string
- func TextInsertChars(n int) string
- func TextInsertLines(n int) string
- func TrueColor(r, g, b uint64) string
- type ConsoleDim
Constants ¶
const ( // ASCII control characters (character code 0-31) AsciiNull = iota AsciiStartOfHeading AsciiStartOfText AsciiEndOfText AsciiEndOfTransmission AsciiEnquiry AsciiAcknowledge AsciiBell AsciiBackspace AsciiHorizontalTab AsciiLineFeed AsciiVerticalTab AsciiFormFeed AsciiCarriageReturn AsciiShiftOut AsciiShiftIn AsciiDataLinkEscape AsciiDeviceControlOne AsciiDeviceControlTwo AsciiDeviceControlThree AsciiDeviceControlFour AsciiNegativeAcknowledge AsciiSyncIdle AsciiEndOfTransmissionBlock AsciiCancel AsciiEndOfMedium AsciiSubstitute AsciiEscape AsciiFileSeparator AsciiGroupSeparator AsciiRecordSeparator AsciiUnitSeparaTOR AsciiDelete = 127 )
const ( Esc = "\u001B[" Osc = "\u001B]" Bel = "\u0007" )
Common fragments of escape sequences
const ( CursorUp = Esc + "A" CursorDown = Esc + "B" CursorForward = Esc + "C" CursorBackward = Esc + "D" CursorNextLine = Esc + "E" CursorPrevLine = Esc + "F" CursorLeft = Esc + "G" CursorTop = Esc + "d" CursorTopLeft = Esc + "H" CursorSave = Esc + "s" CursorRestore = Esc + "u" CursorBlinkEnable = Esc + "?12h" CursorBlinkDisable = Esc + "?12I" CursorShow = Esc + "?25h" CursorHide = Esc + "?25l" ScrollUp = Esc + "S" ScrollDown = Esc + "T" TextInsertChar = Esc + "@" TextDeleteChar = Esc + "P" TextEraseChar = Esc + "X" TextInsertLine = Esc + "L" TextDeleteLine = Esc + "M" EraseRight = Esc + "K" EraseLeft = Esc + "1K" EraseLine = Esc + "2K" EraseDown = Esc + "J" EraseUp = Esc + "1J" EraseScreen = Esc + "2J" TextColorBlack = Esc + "30m" TextColorRed = Esc + "31m" TextColorGreen = Esc + "32m" TextColorYellow = Esc + "33m" TextColorBlue = Esc + "34m" TextColorMagenta = Esc + "35m" TextColorCyan = Esc + "36m" TextColorWhite = Esc + "37m" TextColorBrightBlack = Esc + "90m" TextColorBrightRed = Esc + "91m" TextColorBrightGreen = Esc + "92m" TextColorBrightYellow = Esc + "93m" TextColorBrightBlue = Esc + "94m" TextColorBrightMagenta = Esc + "95m" TextColorBrightCyan = Esc + "96m" TextColorBrightWhite = Esc + "97m" BackgroundColorBlack = Esc + "40m" BackgroundColorRed = Esc + "41m" BackgroundColorGreen = Esc + "42m" BackgroundColorYellow = Esc + "43m" BackgroundColorBlue = Esc + "44m" BackgroundColorMagenta = Esc + "45m" BackgroundColorCyan = Esc + "46m" BackgroundColorWhite = Esc + "47m" BackgroundColorBrightBlack = Esc + "100m" BackgroundColorBrightRed = Esc + "101m" BackgroundColorBrightGreen = Esc + "102m" BackgroundColorBrightYellow = Esc + "103m" BackgroundColorBrightBlue = Esc + "104m" BackgroundColorBrightMagenta = Esc + "105m" BackgroundColorBrightCyan = Esc + "106m" BackgroundColorBrightWhite = Esc + "107m" ColorReset = Esc + "0m" ClearScreen = "\u001Bc" )
Common ANSI escapes sequences. These should be used when the desired action is only needed once; otherwise, use the functions (e.g. moving a cursor several lines/columns). See: https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
const ( CursorSavePosition = Esc + "s" CursorRestorePosition = Esc + "u" )
ANSI escape sequences for saving and restoring the cursor position
Variables ¶
var AllowANSI bool
var IsTerminal bool
Functions ¶
func CursorMove ¶
CursorMove returns an escape sequence to move the cursor relative to its current position.
func CursorPos ¶
CursorPos returns an escape sequence to move the cursor to a coordinate pair, where (0, 0) is the origin (top-left corner).
func CursorPosX ¶
CursorPosX returns an escape sequence to move the cursor to an x-coordinate (column) at the current y-coordinate (row), where 0 is the leftmost.
func CursorPosY ¶
CursorPosY returns an escape sequence to move the cursor to an y-coordinate (row) at the current x-coordinate (column), where 0 is the topmost.
func DisableVirtualTerminal ¶
DisableVirtualTerminal disables virtual terminal escapes sequences for a console handle. It is only effective when built for Windows. On other OSes, it will simply return nil.
func EnableVirtualTerminal ¶
EnableVirtualTerminal enables virtual terminal escapes sequences for a console handle. It is only effective when built for Windows. On other OSes, it will simply return nil.
func Image ¶
Image returns an escape sequence to display an image, preserving the original height and width.
func ImageWidthHeight ¶
ImageWidthHeight returns an escape sequence to display an image.
func Scroll ¶
Scroll returns an escape sequence to scroll the current window. A positive number of lines indicates scrolling up, while a negative number of lines indicates scrolling down.
func TextDeleteChars ¶
TextDeleteChars returns an escape sequence to delete characters to the right of, and including, the current cursor position, shifting existing characters to the left.
func TextDeleteLines ¶
TextDeleteLines returns an escape sequence to delete the lines below, and including, the current cursor row.
func TextEraseChars ¶
TextEraseChars returns an escape sequence to insert spaces to the right of, and including, the current cursor position, overwriting existing characters to the right.
func TextInsertChars ¶
TextInsertChars returns an escape sequence to insert spaces to the right of, and including, the current cursor position, shifting existing characters to the right.
func TextInsertLines ¶
TextInsertLines returns an escape sequence to insert blank lines below, and including the current cursor row, shifting existing lines downwards.
Types ¶
type ConsoleDim ¶
ConsoleDim represents the dimensions of a console in rows and columns.
func GetConsoleSize ¶
func GetConsoleSize(fd uintptr) (*ConsoleDim, error)