Documentation
¶
Overview ¶
Package ansi provides support for text encoded ANSI, focusing especially on escape and control sequences.
Primary focus is on bridging the ANSI world into the Unicode/UTF-8 world.
ISO-2022 is currently supported minimally and assumed to be in UTF-8 mode at all times via the "ESC % G" sequence.
Example (Decode_main) ¶
package main import ( "bytes" "fmt" "io" "log" "os" "unicode/utf8" "github.com/jcorbin/anansi/ansi" ) func main() { switch err := run(); err { case nil: case io.EOF: fmt.Println(err) default: log.Fatal(err) } } func run() error { const minRead = 128 var buf bytes.Buffer for { // read more input... buf.Grow(minRead) p := buf.Bytes() p = p[len(p):cap(p)] n, err := os.Stdin.Read(p) if err != nil { return err } if n == 0 { continue } _, _ = buf.Write(p[:n]) // ...and process it if err := process(&buf); err != nil { return err } } } func process(buf *bytes.Buffer) error { for buf.Len() > 0 { e, a, n := ansi.DecodeEscape(buf.Bytes()) if n > 0 { buf.Next(n) } // have a complete escape sequence if e != 0 { handleEscape(e, a) continue } // Decode a rune... switch r, n := utf8.DecodeRune(buf.Bytes()); r { case 0x90, 0x9D, 0x9E, 0x9F: // DCS, OSC, PM, APC return nil // ... need more bytes to complete a partial string. case 0x9B: // CSI return nil // ... need more bytes to complete a partial control sequence. case 0x1B: // ESC if p := buf.Bytes(); len(p) == cap(p) { return nil // ... need more bytes to determine if an escape sequence can be decoded. } fallthrough // ... literal ESC default: buf.Next(n) handleRune(r) } } return nil } func handleEscape(e ansi.Escape, a []byte) { fmt.Print(e) if len(a) > 0 { fmt.Printf(" %q", a) } fmt.Printf("\r\n") } func handleRune(r rune) { switch { // print C0 controls phonetically case r < 0x20, r == 0x7f: fmt.Printf("^%s", string(0x40^r)) // print C1 controls mnemonically case 0x80 <= r && r <= 0x9f: fmt.Print(ansi.C1Names[r&0x1f]) // print normal rune default: fmt.Print(string(r)) } }
Output:
Index ¶
- Constants
- Variables
- func DecodeCursorCardinal(id Escape, a []byte) (d image.Point, _ bool)
- func DecodeNumber(p []byte) (r, n int, _ error)
- func DecodeRune(p []byte) (rune, int)
- func DecodeXtermExtendedMouse(id Escape, arg []byte) (b MouseState, p Point, err error)
- type ColorModel
- type ColorModelFunc
- type ColorTheme
- type Escape
- func (id Escape) AppendTo(p []byte) []byte
- func (id Escape) AppendWith(p []byte, arg ...byte) []byte
- func (id Escape) CSI() (byte, bool)
- func (id Escape) ESC() (byte, bool)
- func (id Escape) IsCharacterSetControl() bool
- func (id Escape) IsEscape() bool
- func (id Escape) Size() int
- func (id Escape) String() string
- func (id Escape) With(arg ...byte) Seq
- func (id Escape) WithInts(args ...int) Seq
- func (id Escape) WithPoint(p Point) Seq
- type Mode
- type MouseDecodeError
- type MouseState
- func (ms MouseState) ButtonID() uint8
- func (ms MouseState) ButtonName() string
- func (ms MouseState) IsDrag() bool
- func (ms MouseState) IsMotion() bool
- func (ms MouseState) IsPress() (id uint8, is bool)
- func (ms MouseState) IsRelease() bool
- func (ms MouseState) Modifier() MouseState
- func (ms MouseState) ModifierName() string
- func (ms MouseState) String() string
- type Palette
- type Point
- func (p Point) Add(q image.Point) Point
- func (p Point) Diff(q Point) image.Point
- func (p Point) Div(k int) Point
- func (p Point) Eq(q Point) bool
- func (p Point) In(r Rectangle) bool
- func (p Point) Mul(k int) Point
- func (p Point) Sub(q image.Point) Point
- func (p Point) ToImage() image.Point
- func (p Point) Valid() bool
- type Rectangle
- func (r Rectangle) Add(p image.Point) Rectangle
- func (r Rectangle) Canon() Rectangle
- func (r Rectangle) Dx() int
- func (r Rectangle) Dy() int
- func (r Rectangle) Empty() bool
- func (r Rectangle) Eq(s Rectangle) bool
- func (r Rectangle) In(s Rectangle) bool
- func (r Rectangle) Inset(n int) Rectangle
- func (r Rectangle) Intersect(s Rectangle) Rectangle
- func (r Rectangle) Overlaps(s Rectangle) bool
- func (r Rectangle) Size() image.Point
- func (r Rectangle) String() string
- func (r Rectangle) Sub(p image.Point) Rectangle
- func (r Rectangle) ToImage() image.Rectangle
- func (r Rectangle) Union(s Rectangle) Rectangle
- type SGRAttr
- func (attr SGRAttr) AppendTo(p []byte) []byte
- func (attr SGRAttr) BG() (c SGRColor, set bool)
- func (attr SGRAttr) ControlString() string
- func (attr SGRAttr) Diff(other SGRAttr) SGRAttr
- func (attr SGRAttr) FG() (c SGRColor, set bool)
- func (attr SGRAttr) Merge(other SGRAttr) SGRAttr
- func (attr SGRAttr) SansBG() SGRAttr
- func (attr SGRAttr) SansFG() SGRAttr
- func (attr SGRAttr) Size() int
- func (attr SGRAttr) String() string
- type SGRColor
- type SGRColorMap
- type Seq
Examples ¶
Constants ¶
const ( ModeMouseVt200 = ModePrivate | 1000 ModeMouseVt200Highlight = ModePrivate | 1001 ModeMouseBtnEvent = ModePrivate | 1002 ModeMouseAnyEvent = ModePrivate | 1003 ModeMouseFocusEvent = ModePrivate | 1004 ModeMouseExt = ModePrivate | 1005 ModeMouseSgrExt = ModePrivate | 1006 ModeMouseUrxvtExt = ModePrivate | 1015 ModeAlternateScroll = ModePrivate | 1007 ModeMetaReporting = ModePrivate | 1036 ModeAlternateScreen = ModePrivate | 1049 ModeBracketedPaste = ModePrivate | 2004 )
xterm mode constants; see http://invisible-island.net/xterm/ctlseqs/ctlseqs.html.
const ( SGRCodeClear = 0 // clear all special attributes SGRCodeBold = 1 // bold or increased intensity SGRCodeDim = 2 // dim or secondary color on gigi SGRCodeItalic = 3 // italic SGRCodeUnderscore = 4 // underscore SGRCodeSlow = 5 // slow blink SGRCodeFast = 6 // fast blink SGRCodeNegative = 7 // negative image SGRCodeConcealed = 8 // concealed (do not display character echoed locally) // uncommon vt220 codes SGRCodeCancelBold = 22 // cancel bold or dim attribute only SGRCodeCancelUnderline = 24 // cancel underline attribute only SGRCodeCancelFast = 25 // cancel fast or slow blink attribute only SGRCodeCancelNegative = 27 // cancel negative image attribute only SGRCodeFGBlack = 30 // write with black SGRCodeFGRed = 31 // write with red SGRCodeFGGreen = 32 // write with green SGRCodeFGYellow = 33 // write with yellow SGRCodeFGBlue = 34 // write with blue SGRCodeFGMagenta = 35 // write with magenta SGRCodeFGCyan = 36 // write with cyan SGRCodeFGWhite = 37 // write with white SGRCodeBGBlack = 40 // set background to black SGRCodeBGRed = 41 // set background to red SGRCodeBGGreen = 42 // set background to green SGRCodeBGYellow = 43 // set background to yellow SGRCodeBGBlue = 44 // set background to blue SGRCodeBGMagenta = 45 // set background to magenta SGRCodeBGCyan = 46 // set background to cyan SGRCodeBGWhite = 47 // set background to white )
SGR Set Graphics Rendition (affects character attributes)
const ( // SGRAttrMask selects all normal attr bits (excluding FG, BBG, and SGRAttrClear) SGRAttrMask = SGRAttrBold | SGRAttrDim | SGRAttrItalic | SGRAttrUnderscore | SGRAttrNegative | SGRAttrConceal // SGRAttrFGMask selects any set FG color. SGRAttrFGMask = SGRAttr(sgrColorSet|sgrColorMask) << sgrFGShift // SGRAttrBGMask selects any set BG color. SGRAttrBGMask = SGRAttr(sgrColorSet|sgrColorMask) << sgrBGShift )
const (
ShowCursor = ModePrivate | 25
)
TODO http://www.disinterest.org/resource/MUD-Dev/1997q1/000244.html and others
Variables ¶
var ( // DECGON graphics on for VT105, DECHTS horiz tab set for LA34/LA120 DECGON = ESC('1') // DECGOFF graphics off VT105, DECCAHT clear all horz tabs LA34/LA120 DECGOFF = ESC('2') // DECVTS set vertical tab for LA34/LA120 DECVTS = ESC('3') // DECCAVT clear all vertical tabs for LA34/LA120 DECCAVT = ESC('4') // DECXMT Host requests that VT132 transmit as if ENTER were pressed DECXMT = ESC('5') // DECSC Save cursor position and character attributes DECSC = ESC('7') // DECRC Restore cursor and attributes to previously saved position DECRC = ESC('8') // DECANSI Switch from VT52 mode to VT100 mode DECANSI = ESC('<') // DECKPAM Set keypad to applications mode (ESCape instead of digits) DECKPAM = ESC('=') // DECKPNM Set keypad to numeric mode (digits intead of ESCape seq) DECKPNM = ESC('>') )
var ( /*ICH Insert CHaracter [10@ = Make room for 10 characters at current position */ ICH = CSI('@') /*CUU CUrsor Up [A = Move up one line, stop at top of screen, [9A = move up 9 */ CUU = CSI('A') /*CUD CUrsor Down [B = Move down one line, stop at bottom of screen */ CUD = CSI('B') /*CUF CUrsor Forward [C = Move forward one position, stop at right edge of screen */ CUF = CSI('C') /*CUB CUrsor Backward [D = Same as BackSpace, stop at left edge of screen */ CUB = CSI('D') /*CNL Cursor to Next Line [5E = Move to first position of 5th line down */ CNL = CSI('E') /*CPL Cursor to Previous Line [5F = Move to first position of 5th line previous */ CPL = CSI('F') /*CHA Cursor Horizontal position Absolute [40G = Move to column 40 of current line */ CHA = CSI('G') /*CUP CUrsor Position [H = Home [24;80H = Row 24, Column 80 */ CUP = CSI('H') /*CHT Cursor Horizontal Tabulation [I = Same as HT (Control-I), [3I = Go forward 3 tabs */ CHT = CSI('I') /*ED Erase in Display (cursor does not move) [J = [0J = Erase from current position to end (inclusive) [1J = Erase from beginning to current position (inclusive) [2J = Erase entire display [?0J = Selective erase in display ([?1J, [?2J similar) */ ED = CSI('J') /*EL Erase in Line (cursor does not move) [K = [0K = Erase from current position to end (inclusive) [1K = Erase from beginning to current position [2K = Erase entire current line [?0K = Selective erase to end of line ([?1K, [?2K similar) */ EL = CSI('K') /*IL Insert Line, current line moves down (VT102 series) [3L = Insert 3 lines if currently in scrolling region */ IL = CSI('L') /*DL Delete Line, lines below current move up (VT102 series) [2M = Delete 2 lines if currently in scrolling region */ DL = CSI('M') /*EF Erase in Field (as bounded by protected fields) [0N, [1N, [2N act like [L but within current field */ EF = CSI('N') /*EA Erase in qualified Area (defined by DAQ) [0O, [1O, [2O act like [J but within current area */ EA = CSI('O') /*DCH Delete Character, from current position to end of field [4P = Delete 4 characters, VT102 series */ DCH = CSI('P') /*SEM Set Editing extent Mode (limits ICH and DCH) [0Q = [Q = Insert/delete character affects rest of display [1Q = ICH/DCH affect the current line only [2Q = ICH/DCH affect current field (between tab stops) only [3Q = ICH/DCH affect qualified area (between protected fields) */ SEM = CSI('Q') /*CPR Cursor Position Report (from terminal to host) [24;80R = Cursor is positioned at line 24 column 80 */ CPR = CSI('R') /*SU Scroll up, entire display is moved up, new lines at bottom [3S = Move everything up 3 lines, bring in 3 new lines */ SU = CSI('S') /*SD Scroll down, new lines inserted at top of screen [4T = Scroll down 4, bring previous lines back into view */ SD = CSI('T') /*NP Next Page (if terminal has more than 1 page of memory) [2U = Scroll forward 2 pages */ NP = CSI('U') /*PP Previous Page (if terminal remembers lines scrolled off top) [1V = Scroll backward 1 page */ PP = CSI('V') /*CTC Cursor Tabulation Control [0W = Set horizontal tab for current line at current position [1W = Set vertical tab stop for current line of current page [2W = Clear horiz tab stop at current position of current line [3W = Clear vert tab stop at current line of current page [4W = Clear all horiz tab stops on current line only [5W = Clear all horiz tab stops for the entire terminal [6W = Clear all vert tabs stops for the entire terminal */ CTC = CSI('W') /*ECH Erase CHaracter [4X = Change next 4 characters to "erased" state */ ECH = CSI('X') /*CVT Cursor Vertical Tab [2Y = Move forward to 2nd following vertical tab stop */ CVT = CSI('Y') /*CBT Cursor Back Tab [3Z = Move backwards to 3rd previous horizontal tab stop */ CBT = CSI('Z') /*HPA Horizontal Position Absolute (depends on PUM) [720` = Move to 720 decipoints (1 inch) from left margin [80` = Move to column 80 on LA120 */ HPA = CSI('`') /*HPR Horizontal Position Relative (depends on PUM) [360a = Move 360 decipoints (1/2 inch) from current position [40a = Move 40 columns to right of current position on LA120 */ HPR = CSI('a') /*REP REPeat previous displayable character [80b = Repeat character 80 times */ REP = CSI('b') /*DA Device Attributes [c = Terminal will identify itself [?1;2c = Terminal is saying it is a VT100 with AVO [>0c = Secondary DA request (distinguishes VT240 from VT220) */ DA = CSI('c') /*VPA Vertical Position Absolute (depends on PUM) [90d = Move to 90 decipoints (1/8 inch) from top margin [10d = Move to line 10 if before that else line 10 next page */ VPA = CSI('d') /*VPR Vertical Position Relative (depends on PUM) [720e = Move 720 decipoints (1 inch) down from current position [6e = Advance 6 lines forward on LA120 */ VPR = CSI('e') /*HVP Horizontal and Vertical Position (depends on PUM) [720,1440f = Move to 1 inch down and 2 inches over (decipoints) [24;80f = Move to row 24 column 80 if PUM is set to character */ HVP = CSI('f') /*TBC Tabulation Clear [0g = Clear horizontal tab stop at current position [1g = Clear vertical tab stop at current line (LA120) [2g = Clear all horizontal tab stops on current line only LA120 [3g = Clear all horizontal tab stops in the terminal */ TBC = CSI('g') /*SM Set Standard Mode (. means permanently set on VT100) TODO merge with constants defined in modes.go [0h = Error, this command is ignored [1h = GATM - Guarded Area Transmit Mode, send all (VT132) [2h = KAM - Keyboard Action Mode, disable keyboard input [3h = CRM - Control Representation Mode, show all control chars [4h = IRM - Insertion/Replacement Mode, set insert mode (VT102) [5h = SRTM - Status Report Transfer Mode, report after DCS [6h = ERM - ERasure Mode, erase protected and unprotected [7h = VEM - Vertical Editing Mode, IL/DL affect previous lines [8h, [9h are reserved [10h = HEM - Horizontal Editing mode, ICH/DCH/IRM go backwards [11h = PUM - Positioning Unit Mode, use decipoints for HVP/etc [12h = SRM - Send Receive Mode, transmit without local echo [13h = FEAM - Format Effector Action Mode, FE's are stored [14h = FETM - Format Effector Transfer Mode, send only if stored [15h = MATM - Multiple Area Transfer Mode, send all areas [16h = TTM - Transmit Termination Mode, send scrolling region [17h = SATM - Send Area Transmit Mode, send entire buffer [18h = TSM - Tabulation Stop Mode, lines are independent [19h = EBM - Editing Boundry Mode, all of memory affected [20h = LNM - Linefeed Newline Mode, LF interpreted as CR LF */ SM = CSI('h') /*SMprivate Set Private Mode TODO merge with constants defined in modes.go [?1h = DECCKM - Cursor Keys Mode, send ESC O A for cursor up [?2h = DECANM - ANSI Mode, use ESC < to switch VT52 to ANSI [?3h = DECCOLM - COLumn mode, 132 characters per line [?4h = DECSCLM - SCrolL Mode, smooth scrolling [?5h = DECSCNM - SCreeN Mode, black on white background [?6h = DECOM - Origin Mode, line 1 is relative to scroll region [?7h = DECAWM - AutoWrap Mode, start newline after column 80 [?8h = DECARM - Auto Repeat Mode, key will autorepeat [?9h = DECINLM - INterLace Mode, interlaced for taking photos [?10h = DECEDM - EDit Mode, VT132 is in EDIT mode [?11h = DECLTM - Line Transmit Mode, ignore TTM, send line [?12h = ? [?13h = DECSCFDM - Space Compression/Field Delimiting on, [?14h = DECTEM - Transmit Execution Mode, transmit on ENTER [?15h = ? [?16h = DECEKEM - Edit Key Execution Mode, EDIT key is local [?17h = ? [?18h = DECPFF - Print FormFeed mode, send FF after printscreen [?19h = DECPEXT - Print Extent mode, print entire screen [?20h = OV1 - Overstrike, overlay characters on GIGI [?21h = BA1 - Local BASIC, GIGI to keyboard and screen [?22h = BA2 - Host BASIC, GIGI to host computer [?23h = PK1 - GIGI numeric keypad sends reprogrammable sequences [?24h = AH1 - Autohardcopy before erasing or rolling GIGI screen [?29h = - Use only the proper pitch for the LA100 font [?38h = DECTEK - TEKtronix mode graphics */ SMprivate = SM.With('?') /*MC Media Copy (printer port on VT102) [0i = Send contents of text screen to printer [1i = Fill screen from auxiliary input (printer's keyboard) [2i = Send screen to secondary output device [3i = Fill screen from secondary input device [4i = Turn on copying received data to primary output (VT125) [4i = Received data goes to VT102 screen, not to its printer [5i = Turn off copying received data to primary output (VT125) [5i = Received data goes to VT102's printer, not its screen [6i = Turn off copying received data to secondary output (VT125) [7i = Turn on copying received data to secondary output (VT125) [?0i = Graphics screen dump goes to graphics printer VT125,VT240 [?1i = Print cursor line, terminated by CR LF [?2i = Graphics screen dump goes to host computer VT125,VT240 [?4i = Disable auto print [?5i = Auto print, send a line at a time when linefeed received */ MC = CSI('i') /*RM Reset Mode (. means permanently reset on VT100) TODO merge with constants defined in modes.go [1l = GATM - Transmit only unprotected characters (VT132) [2l = KAM - Enable input from keyboard [3l = CRM - Control characters are not displayable characters [4l = IRM - Reset to replacement mode (VT102) [5l = SRTM - Report only on command (DSR) [6l = ERM - Erase only unprotected fields [7l = VEM - IL/DL affect lines after current line [8l reserved [9l reserved [10l = HEM - ICH and IRM shove characters forward, DCH pulls [11l = PUM - Use character positions for HPA/HPR/VPA/VPR/HVP [12l = SRM - Local echo - input from keyboard sent to screen [13l = FEAM - HPA/VPA/SGR/etc are acted upon when received [14l = FETM - Format Effectors are sent to the printer [15l = MATM - Send only current area if SATM is reset [16l = TTM - Transmit partial page, up to cursor position [17l = SATM - Transmit areas bounded by SSA/ESA/DAQ [18l = TSM - Setting a tab stop on one line affects all lines [19l = EBM - Insert does not overflow to next page [20l = LNM - Linefeed does not change horizontal position */ RM = CSI('l') /*RMprivate Reset Private Mode [?1l = DECCKM - Cursor keys send ANSI cursor position commands [?2l = DECANM - Use VT52 emulation instead of ANSI mode [?3l = DECCOLM - 80 characters per line (erases screen) [?4l = DECSCLM - Jump scrolling [?5l = DECSCNM - Normal screen (white on black background) [?6l = DECOM - Line numbers are independent of scrolling region [?7l = DECAWM - Cursor remains at end of line after column 80 [?8l = DECARM - Keys do not repeat when held down [?9l = DECINLM - Display is not interlaced to avoid flicker [?10l = DECEDM - VT132 transmits all key presses [?11l = DECLTM - Send page or partial page depending on TTM [?12l = ? [?13l = DECSCFDM - Don't suppress trailing spaces on transmit [?14l = DECTEM - ENTER sends ESC S (STS) a request to send [?15l = ? [?16l = DECEKEM - EDIT key transmits either $[10h or $[10l [?17l = ? [?18l = DECPFF - Don't send a formfeed after printing screen [?19l = DECPEXT - Print only the lines within the scroll region [?20l = OV0 - Space is destructive, replace not overstrike, GIGI [?21l = BA0 - No BASIC, GIGI is On-Line or Local [?22l = BA0 - No BASIC, GIGI is On-Line or Local [?23l = PK0 - Ignore reprogramming on GIGI keypad and cursors [?24l = AH0 - No auto-hardcopy when GIGI screen erased [?29l = Allow all character pitches on the LA100 [?38l = DECTEK - Ignore TEKtronix graphics commands */ RMprivate = RM.With('?') /*SGR Set Graphics Rendition (affects character attributes) [0m = Clear all special attributes [1m = Bold or increased intensity [2m = Dim or secondary color on GIGI (superscript on XXXXXX) [3m = Italic (subscript on XXXXXX) [4m = Underscore [0;4m = Clear, then set underline only [5m = Slow blink [6m = Fast blink (overscore on XXXXXX) [7m = Negative image [0;1;7m = Bold + Inverse [8m = Concealed (do not display character echoed locally) [9m = Reserved for future standardization [10m = Select primary font (LA100) [11m - [19m = Select alternate font (LA100 has 11 thru 14) [20m = FRAKTUR (whatever that means) [22m = Cancel bold or dim attribute only (VT220) [24m = Cancel underline attribute only (VT220) [25m = Cancel fast or slow blink attribute only (VT220) [27m = Cancel negative image attribute only (VT220) [30m = Write with black [31m = Write with red [32m = Write with green [33m = Write with yellow [34m = Write with blue [35m = Write with magenta [36m = Write with cyan [37m = Write with white [38m reserved [39m reserved [40m = Set background to black (GIGI) [41m = Set background to red [42m = Set background to green [43m = Set background to yellow [44m = Set background to blue [45m = Set background to magenta [46m = Set background to cyan [47m = Set background to white [48m reserved [49m reserved */ SGR = CSI('m') /*DSR Device Status Report [0n = Terminal is ready, no malfunctions detected [1n = Terminal is busy, retry later [2n = Terminal is busy, it will send DSR when ready [3n = Malfunction, please try again [4n = Malfunction, terminal will send DSR when ready [5n = Command to terminal to report its status [6n = Command to terminal requesting cursor position (CPR) [?15n = Command to terminal requesting printer status, returns [?10n = OK [?11n = not OK [?13n = no printer. [?25n = "Are User Defined Keys Locked?" (VT220) */ DSR = CSI('n') /*DAQ Define Area Qualification starting at current position [0o = Accept all input, transmit on request [1o = Protected and guarded, accept no input, do not transmit [2o = Accept any printing character in this field [3o = Numeric only field [4o = Alphabetic (A-Z and a-z) only [5o = Right justify in area [3;6o = Zero fill in area [7o = Set horizontal tab stop, this is the start of the field [8o = Protected and unguarded, accept no input, do transmit [9o = Space fill in area */ DAQ = CSI('o') )
Control Sequences (defined by ANSI X3.64-1979)
var ( // DECSTR Soft Terminal Reset // [!p = Soft Terminal Reset DECSTR = CSI('p') // SoftReset is a control sequence that causes a soft terminal reset. // NOTE it does not erase the screen or home the cursor; for that also // send ED.With('2') and CUP. SoftReset = DECSTR.With('!') /*DECLL Load LEDs [0q = Turn off all [?1;4q = turns on L1 and L4, etc [154;155;157q = VT100 goes bonkers [2;23!q = Partial screen dump from GIGI to graphics printer [0"q = DECSCA Select Character Attributes off [1"q = DECSCA - designate set as non-erasable [2"q = DECSCA - designate set as erasable */ DECLL = CSI('q') /*DECSTBM Set top and bottom margins (scroll region on VT100) [4;20r = Set top margin at line 4 and bottom at line 20 */ DECSTBM = CSI('r') /*DECSTRM Set left and right margins on LA100,LA120 [5;130s = Set left margin at column 5 and right at column 130 */ DECSTRM = CSI('s') /*DECSLPP Set physical lines per page [66t = Paper has 66 lines (11 inches at 6 per inch) */ DECSLPP = CSI('t') /*DECSHTS Set many horizontal tab stops at once on LA100 [9;17;25;33;41;49;57;65;73;81u = Set standard tab stops */ DECSHTS = CSI('u') /*DECSVTS Set many vertical tab stops at once on LA100 [1;16;31;45v = Set vert tabs every 15 lines */ DECSVTS = CSI('v') /*DECSHORP Set horizontal pitch on LAxxx printers [1w = 10 characters per inch [2w = 12 characters per inch [0w = 10 [3w = 13.2 [4w = 16.5 [5w = 5 [6w = 6 [7w = 6.6 [8w = 8.25 */ DECSHORP = CSI('w') /*DECREQTPARM Request terminal parameters [3;5;2;64;64;1;0x = Report, 7 bit Even, 1200 baud, 1200 baud */ DECREQTPARM = CSI('x') /*DECTST Invoke confidence test [2;1y = Power-up test on VT100 series (and VT100 part of VT125) [3;1y = Power-up test on GIGI (VK100) [4;1y = Power-up test on graphics portion of VT125 */ DECTST = CSI('y') /*DECVERP Set vertical pitch on LA100 [1z = 6 lines per inch [2z = 8 lines per inch [0z = 6 [3z = 12 [4z = 3 [5z = 3 [6z = 4 */ DECVERP = CSI('z') /*DECTTC Transmit Termination Character [0| = No extra characters [1| = terminate with FF */ DECTTC = CSI('|') /*DECPRO Define protected field on VT132 [0} = No protection [1;4;5;7} = Any attribute is protected [254} = Characters with no attributes are protected */ DECPRO = CSI('}') /*DECKEYS Sent by special function keys [1~ = FIND [2~ = INSERT [3~ = REMOVE [4~ = SELECT [5~ = PREV [6~ = NEXT [17~ = F6... [34~ = F20 [23~ = ESC [24~ = BS [25~ = LF [28~ = HELP [29~ = DO */ DECKEYS = CSI('~') )
Private Control Sequences (allowed by ANSI X3.41-1974)
var C1Names = []string{
"<RES@>",
"<RESA>",
"<RESB>",
"<RESC>",
"<IND>",
"<NEL>",
"<SSA>",
"<ESA>",
"<HTS>",
"<HTJ>",
"<VTS>",
"<PLD>",
"<PLU>",
"<RI>",
"<SS2>",
"<SS3>",
"<DCS>",
"<PU1>",
"<PU2>",
"<STS>",
"<CCH>",
"<MW>",
"<SPA>",
"<EPA>",
"<RESX>",
"<RESY>",
"<RESZ>",
"<CSI>",
"<ST>",
"<OSC>",
"<PM>",
"<APC>",
}
C1Names provides representation names for the C1 extended-ASCII control block.
var CMDPalette = ColorTheme{ RGB(0x01, 0x01, 0x01), RGB(0x80, 0x00, 0x00), RGB(0x00, 0x80, 0x00), RGB(0x80, 0x80, 0x00), RGB(0x00, 0x00, 0x80), RGB(0x80, 0x00, 0x80), RGB(0x00, 0x80, 0x80), RGB(0xC0, 0xC0, 0xC0), RGB(0x80, 0x80, 0x80), RGB(0xFF, 0x00, 0x00), RGB(0x00, 0xFF, 0x00), RGB(0xFF, 0xFF, 0x00), RGB(0x00, 0x00, 0xFF), RGB(0xFF, 0x00, 0xFF), RGB(0x00, 0xFF, 0xFF), RGB(0xFF, 0xFF, 0xFF), }
CMDPalette is the color theme used by Windows cmd.exe.
var ColorModel24 = ColorModelFunc(SGRColor.To24Bit)
ColorModel24 upgrades colors to their 24-bit default definitions.
var ColorModelID = ColorModelFunc(func(c SGRColor) SGRColor { return c })
ColorModelID is the identity color model.
var MIRCPalette = ColorTheme{ RGB(0x00, 0x00, 0x00), RGB(0x7F, 0x00, 0x00), RGB(0x00, 0x93, 0x00), RGB(0xFC, 0x7F, 0x00), RGB(0x00, 0x00, 0x7F), RGB(0x9C, 0x00, 0x9C), RGB(0x00, 0x93, 0x93), RGB(0xD2, 0xD2, 0xD2), RGB(0x7F, 0x7F, 0x7F), RGB(0xFF, 0x00, 0x00), RGB(0x00, 0xFC, 0x00), RGB(0xFF, 0xFF, 0x00), RGB(0x00, 0x00, 0xFC), RGB(0xFF, 0x00, 0xFF), RGB(0x00, 0xFF, 0xFF), RGB(0xFF, 0xFF, 0xFF), }
MIRCPalette is the color theme used by mIRC.
var Palette3 = Palette{ SGRBlack, SGRRed, SGRGreen, SGRYellow, SGRBlue, SGRMagenta, SGRCyan, SGRWhite, }
Palette3 is the classic 3-bit palette of 8 colors.
var Palette3Colors = Palette{ RGB(0x00, 0x00, 0x00), RGB(0x80, 0x00, 0x00), RGB(0x00, 0x80, 0x00), RGB(0x80, 0x80, 0x00), RGB(0x00, 0x00, 0x80), RGB(0x80, 0x00, 0x80), RGB(0x00, 0x80, 0x80), RGB(0xC0, 0xC0, 0xC0), }
Palette3Colors is the canonical 24-bit definitions for the classic 3-bit palette of 8 colors.
var Palette4 = Palette3.concat( SGRBrightBlack, SGRBrightRed, SGRBrightGreen, SGRBrightYellow, SGRBrightBlue, SGRBrightMagenta, SGRBrightCyan, SGRBrightWhite, )
Palette4 is the extended 4-bit palette of the 8 classic colors and their bright counterparts.
var Palette4Colors = Palette3Colors.concat( RGB(0x80, 0x80, 0x80), RGB(0xFF, 0x00, 0x00), RGB(0x00, 0xFF, 0x00), RGB(0xFF, 0xFF, 0x00), RGB(0x00, 0x00, 0xFF), RGB(0xFF, 0x00, 0xFF), RGB(0x00, 0xFF, 0xFF), RGB(0xFF, 0xFF, 0xFF), )
Palette4Colors is the canonical 24-bit definitions for the extended 4-bit palette of 16 colors.
var Palette8 = Palette4.concat( SGRCube16, SGRCube17, SGRCube18, SGRCube19, SGRCube20, SGRCube21, SGRCube22, SGRCube23, SGRCube24, SGRCube25, SGRCube26, SGRCube27, SGRCube28, SGRCube29, SGRCube30, SGRCube31, SGRCube32, SGRCube33, SGRCube34, SGRCube35, SGRCube36, SGRCube37, SGRCube38, SGRCube39, SGRCube40, SGRCube41, SGRCube42, SGRCube43, SGRCube44, SGRCube45, SGRCube46, SGRCube47, SGRCube48, SGRCube49, SGRCube50, SGRCube51, SGRCube52, SGRCube53, SGRCube54, SGRCube55, SGRCube56, SGRCube57, SGRCube58, SGRCube59, SGRCube60, SGRCube61, SGRCube62, SGRCube63, SGRCube64, SGRCube65, SGRCube66, SGRCube67, SGRCube68, SGRCube69, SGRCube70, SGRCube71, SGRCube72, SGRCube73, SGRCube74, SGRCube75, SGRCube76, SGRCube77, SGRCube78, SGRCube79, SGRCube80, SGRCube81, SGRCube82, SGRCube83, SGRCube84, SGRCube85, SGRCube86, SGRCube87, SGRCube88, SGRCube89, SGRCube90, SGRCube91, SGRCube92, SGRCube93, SGRCube94, SGRCube95, SGRCube96, SGRCube97, SGRCube98, SGRCube99, SGRCube100, SGRCube101, SGRCube102, SGRCube103, SGRCube104, SGRCube105, SGRCube106, SGRCube107, SGRCube108, SGRCube109, SGRCube110, SGRCube111, SGRCube112, SGRCube113, SGRCube114, SGRCube115, SGRCube116, SGRCube117, SGRCube118, SGRCube119, SGRCube120, SGRCube121, SGRCube122, SGRCube123, SGRCube124, SGRCube125, SGRCube126, SGRCube127, SGRCube128, SGRCube129, SGRCube130, SGRCube131, SGRCube132, SGRCube133, SGRCube134, SGRCube135, SGRCube136, SGRCube137, SGRCube138, SGRCube139, SGRCube140, SGRCube141, SGRCube142, SGRCube143, SGRCube144, SGRCube145, SGRCube146, SGRCube147, SGRCube148, SGRCube149, SGRCube150, SGRCube151, SGRCube152, SGRCube153, SGRCube154, SGRCube155, SGRCube156, SGRCube157, SGRCube158, SGRCube159, SGRCube160, SGRCube161, SGRCube162, SGRCube163, SGRCube164, SGRCube165, SGRCube166, SGRCube167, SGRCube168, SGRCube169, SGRCube170, SGRCube171, SGRCube172, SGRCube173, SGRCube174, SGRCube175, SGRCube176, SGRCube177, SGRCube178, SGRCube179, SGRCube180, SGRCube181, SGRCube182, SGRCube183, SGRCube184, SGRCube185, SGRCube186, SGRCube187, SGRCube188, SGRCube189, SGRCube190, SGRCube191, SGRCube192, SGRCube193, SGRCube194, SGRCube195, SGRCube196, SGRCube197, SGRCube198, SGRCube199, SGRCube200, SGRCube201, SGRCube202, SGRCube203, SGRCube204, SGRCube205, SGRCube206, SGRCube207, SGRCube208, SGRCube209, SGRCube210, SGRCube211, SGRCube212, SGRCube213, SGRCube214, SGRCube215, SGRCube216, SGRCube217, SGRCube218, SGRCube219, SGRCube220, SGRCube221, SGRCube222, SGRCube223, SGRCube224, SGRCube225, SGRCube226, SGRCube227, SGRCube228, SGRCube229, SGRCube230, SGRCube231, SGRGray1, SGRGray2, SGRGray3, SGRGray4, SGRGray5, SGRGray6, SGRGray7, SGRGray8, SGRGray9, SGRGray10, SGRGray11, SGRGray12, SGRGray13, SGRGray14, SGRGray15, SGRGray16, SGRGray17, SGRGray18, SGRGray19, SGRGray20, SGRGray21, SGRGray22, SGRGray23, SGRGray24, )
Palette8 is the extended 8-bit palette of the first 16 extended colors, a 6x6x6=216 color cube, and 24 shades of gray.
var Palette8Colors = Palette4Colors.concat( RGB(0x00, 0x00, 0x00), RGB(0x00, 0x00, 0x5F), RGB(0x00, 0x00, 0x87), RGB(0x00, 0x00, 0xAF), RGB(0x00, 0x00, 0xD7), RGB(0x00, 0x00, 0xFF), RGB(0x00, 0x5F, 0x00), RGB(0x00, 0x5F, 0x5F), RGB(0x00, 0x5F, 0x87), RGB(0x00, 0x5F, 0xAF), RGB(0x00, 0x5F, 0xD7), RGB(0x00, 0x5F, 0xFF), RGB(0x00, 0x87, 0x00), RGB(0x00, 0x87, 0x5F), RGB(0x00, 0x87, 0x87), RGB(0x00, 0x87, 0xAF), RGB(0x00, 0x87, 0xD7), RGB(0x00, 0x87, 0xFF), RGB(0x00, 0xAF, 0x00), RGB(0x00, 0xAF, 0x5F), RGB(0x00, 0xAF, 0x87), RGB(0x00, 0xAF, 0xAF), RGB(0x00, 0xAF, 0xD7), RGB(0x00, 0xAF, 0xFF), RGB(0x00, 0xD7, 0x00), RGB(0x00, 0xD7, 0x5F), RGB(0x00, 0xD7, 0x87), RGB(0x00, 0xD7, 0xAF), RGB(0x00, 0xD7, 0xD7), RGB(0x00, 0xD7, 0xFF), RGB(0x00, 0xFF, 0x00), RGB(0x00, 0xFF, 0x5F), RGB(0x00, 0xFF, 0x87), RGB(0x00, 0xFF, 0xAF), RGB(0x00, 0xFF, 0xD7), RGB(0x00, 0xFF, 0xFF), RGB(0x5F, 0x00, 0x00), RGB(0x5F, 0x00, 0x5F), RGB(0x5F, 0x00, 0x87), RGB(0x5F, 0x00, 0xAF), RGB(0x5F, 0x00, 0xD7), RGB(0x5F, 0x00, 0xFF), RGB(0x5F, 0x5F, 0x00), RGB(0x5F, 0x5F, 0x5F), RGB(0x5F, 0x5F, 0x87), RGB(0x5F, 0x5F, 0xAF), RGB(0x5F, 0x5F, 0xD7), RGB(0x5F, 0x5F, 0xFF), RGB(0x5F, 0x87, 0x00), RGB(0x5F, 0x87, 0x5F), RGB(0x5F, 0x87, 0x87), RGB(0x5F, 0x87, 0xAF), RGB(0x5F, 0x87, 0xD7), RGB(0x5F, 0x87, 0xFF), RGB(0x5F, 0xAF, 0x00), RGB(0x5F, 0xAF, 0x5F), RGB(0x5F, 0xAF, 0x87), RGB(0x5F, 0xAF, 0xAF), RGB(0x5F, 0xAF, 0xD7), RGB(0x5F, 0xAF, 0xFF), RGB(0x5F, 0xD7, 0x00), RGB(0x5F, 0xD7, 0x5F), RGB(0x5F, 0xD7, 0x87), RGB(0x5F, 0xD7, 0xAF), RGB(0x5F, 0xD7, 0xD7), RGB(0x5F, 0xD7, 0xFF), RGB(0x5F, 0xFF, 0x00), RGB(0x5F, 0xFF, 0x5F), RGB(0x5F, 0xFF, 0x87), RGB(0x5F, 0xFF, 0xAF), RGB(0x5F, 0xFF, 0xD7), RGB(0x5F, 0xFF, 0xFF), RGB(0x87, 0x00, 0x00), RGB(0x87, 0x00, 0x5F), RGB(0x87, 0x00, 0x87), RGB(0x87, 0x00, 0xAF), RGB(0x87, 0x00, 0xD7), RGB(0x87, 0x00, 0xFF), RGB(0x87, 0x5F, 0x00), RGB(0x87, 0x5F, 0x5F), RGB(0x87, 0x5F, 0x87), RGB(0x87, 0x5F, 0xAF), RGB(0x87, 0x5F, 0xD7), RGB(0x87, 0x5F, 0xFF), RGB(0x87, 0x87, 0x00), RGB(0x87, 0x87, 0x5F), RGB(0x87, 0x87, 0x87), RGB(0x87, 0x87, 0xAF), RGB(0x87, 0x87, 0xD7), RGB(0x87, 0x87, 0xFF), RGB(0x87, 0xAF, 0x00), RGB(0x87, 0xAF, 0x5F), RGB(0x87, 0xAF, 0x87), RGB(0x87, 0xAF, 0xAF), RGB(0x87, 0xAF, 0xD7), RGB(0x87, 0xAF, 0xFF), RGB(0x87, 0xD7, 0x00), RGB(0x87, 0xD7, 0x5F), RGB(0x87, 0xD7, 0x87), RGB(0x87, 0xD7, 0xAF), RGB(0x87, 0xD7, 0xD7), RGB(0x87, 0xD7, 0xFF), RGB(0x87, 0xFF, 0x00), RGB(0x87, 0xFF, 0x5F), RGB(0x87, 0xFF, 0x87), RGB(0x87, 0xFF, 0xAF), RGB(0x87, 0xFF, 0xD7), RGB(0x87, 0xFF, 0xFF), RGB(0xAF, 0x00, 0x00), RGB(0xAF, 0x00, 0x5F), RGB(0xAF, 0x00, 0x87), RGB(0xAF, 0x00, 0xAF), RGB(0xAF, 0x00, 0xD7), RGB(0xAF, 0x00, 0xFF), RGB(0xAF, 0x5F, 0x00), RGB(0xAF, 0x5F, 0x5F), RGB(0xAF, 0x5F, 0x87), RGB(0xAF, 0x5F, 0xAF), RGB(0xAF, 0x5F, 0xD7), RGB(0xAF, 0x5F, 0xFF), RGB(0xAF, 0x87, 0x00), RGB(0xAF, 0x87, 0x5F), RGB(0xAF, 0x87, 0x87), RGB(0xAF, 0x87, 0xAF), RGB(0xAF, 0x87, 0xD7), RGB(0xAF, 0x87, 0xFF), RGB(0xAF, 0xAF, 0x00), RGB(0xAF, 0xAF, 0x5F), RGB(0xAF, 0xAF, 0x87), RGB(0xAF, 0xAF, 0xAF), RGB(0xAF, 0xAF, 0xD7), RGB(0xAF, 0xAF, 0xFF), RGB(0xAF, 0xD7, 0x00), RGB(0xAF, 0xD7, 0x5F), RGB(0xAF, 0xD7, 0x87), RGB(0xAF, 0xD7, 0xAF), RGB(0xAF, 0xD7, 0xD7), RGB(0xAF, 0xD7, 0xFF), RGB(0xAF, 0xFF, 0x00), RGB(0xAF, 0xFF, 0x5F), RGB(0xAF, 0xFF, 0x87), RGB(0xAF, 0xFF, 0xAF), RGB(0xAF, 0xFF, 0xD7), RGB(0xAF, 0xFF, 0xFF), RGB(0xD7, 0x00, 0x00), RGB(0xD7, 0x00, 0x5F), RGB(0xD7, 0x00, 0x87), RGB(0xD7, 0x00, 0xAF), RGB(0xD7, 0x00, 0xD7), RGB(0xD7, 0x00, 0xFF), RGB(0xD7, 0x5F, 0x00), RGB(0xD7, 0x5F, 0x5F), RGB(0xD7, 0x5F, 0x87), RGB(0xD7, 0x5F, 0xAF), RGB(0xD7, 0x5F, 0xD7), RGB(0xD7, 0x5F, 0xFF), RGB(0xD7, 0x87, 0x00), RGB(0xD7, 0x87, 0x5F), RGB(0xD7, 0x87, 0x87), RGB(0xD7, 0x87, 0xAF), RGB(0xD7, 0x87, 0xD7), RGB(0xD7, 0x87, 0xFF), RGB(0xD7, 0xAF, 0x00), RGB(0xD7, 0xAF, 0x5F), RGB(0xD7, 0xAF, 0x87), RGB(0xD7, 0xAF, 0xAF), RGB(0xD7, 0xAF, 0xD7), RGB(0xD7, 0xAF, 0xFF), RGB(0xD7, 0xD7, 0x00), RGB(0xD7, 0xD7, 0x5F), RGB(0xD7, 0xD7, 0x87), RGB(0xD7, 0xD7, 0xAF), RGB(0xD7, 0xD7, 0xD7), RGB(0xD7, 0xD7, 0xFF), RGB(0xD7, 0xFF, 0x00), RGB(0xD7, 0xFF, 0x5F), RGB(0xD7, 0xFF, 0x87), RGB(0xD7, 0xFF, 0xAF), RGB(0xD7, 0xFF, 0xD7), RGB(0xD7, 0xFF, 0xFF), RGB(0xFF, 0x00, 0x00), RGB(0xFF, 0x00, 0x5F), RGB(0xFF, 0x00, 0x87), RGB(0xFF, 0x00, 0xAF), RGB(0xFF, 0x00, 0xD7), RGB(0xFF, 0x00, 0xFF), RGB(0xFF, 0x5F, 0x00), RGB(0xFF, 0x5F, 0x5F), RGB(0xFF, 0x5F, 0x87), RGB(0xFF, 0x5F, 0xAF), RGB(0xFF, 0x5F, 0xD7), RGB(0xFF, 0x5F, 0xFF), RGB(0xFF, 0x87, 0x00), RGB(0xFF, 0x87, 0x5F), RGB(0xFF, 0x87, 0x87), RGB(0xFF, 0x87, 0xAF), RGB(0xFF, 0x87, 0xD7), RGB(0xFF, 0x87, 0xFF), RGB(0xFF, 0xAF, 0x00), RGB(0xFF, 0xAF, 0x5F), RGB(0xFF, 0xAF, 0x87), RGB(0xFF, 0xAF, 0xAF), RGB(0xFF, 0xAF, 0xD7), RGB(0xFF, 0xAF, 0xFF), RGB(0xFF, 0xD7, 0x00), RGB(0xFF, 0xD7, 0x5F), RGB(0xFF, 0xD7, 0x87), RGB(0xFF, 0xD7, 0xAF), RGB(0xFF, 0xD7, 0xD7), RGB(0xFF, 0xD7, 0xFF), RGB(0xFF, 0xFF, 0x00), RGB(0xFF, 0xFF, 0x5F), RGB(0xFF, 0xFF, 0x87), RGB(0xFF, 0xFF, 0xAF), RGB(0xFF, 0xFF, 0xD7), RGB(0xFF, 0xFF, 0xFF), RGB(0x08, 0x08, 0x08), RGB(0x12, 0x12, 0x12), RGB(0x1C, 0x1C, 0x1C), RGB(0x26, 0x26, 0x26), RGB(0x30, 0x30, 0x30), RGB(0x3A, 0x3A, 0x3A), RGB(0x44, 0x44, 0x44), RGB(0x4E, 0x4E, 0x4E), RGB(0x58, 0x58, 0x58), RGB(0x62, 0x62, 0x62), RGB(0x6C, 0x6C, 0x6C), RGB(0x76, 0x76, 0x76), RGB(0x80, 0x80, 0x80), RGB(0x8A, 0x8A, 0x8A), RGB(0x94, 0x94, 0x94), RGB(0x9E, 0x9E, 0x9E), RGB(0xA8, 0xA8, 0xA8), RGB(0xB2, 0xB2, 0xB2), RGB(0xBC, 0xBC, 0xBC), RGB(0xC6, 0xC6, 0xC6), RGB(0xD0, 0xD0, 0xD0), RGB(0xDA, 0xDA, 0xDA), RGB(0xE4, 0xE4, 0xE4), RGB(0xEE, 0xEE, 0xEE), )
Palette8Colors is the canonical 24-bit definitions for the extended 8-bit palette of 256 colors
var PuTTYPalette = ColorTheme{ RGB(0x00, 0x00, 0x00), RGB(0xBB, 0x00, 0x00), RGB(0x00, 0xBB, 0x00), RGB(0xBB, 0xBB, 0x00), RGB(0x00, 0x00, 0xBB), RGB(0xBB, 0x00, 0xBB), RGB(0x00, 0xBB, 0xBB), RGB(0xBB, 0xBB, 0xBB), RGB(0x55, 0x55, 0x55), RGB(0xFF, 0x55, 0x55), RGB(0x55, 0xFF, 0x55), RGB(0xFF, 0xFF, 0x55), RGB(0x55, 0x55, 0xFF), RGB(0xFF, 0x55, 0xFF), RGB(0x55, 0xFF, 0xFF), RGB(0xFF, 0xFF, 0xFF), }
PuTTYPalette is the color theme used by PuTTY.
var SGRColorCanon = make(SGRColorMap, len(Palette8))
SGRColorCanon implements a canonical mapping from 24-bit colors back to their 3, 4, and 8-bit palette aliases.
var SGRReset = SGR.With(SGRCodeClear)
SGRReset resets graphic rendition (foreground, background, text and other character attributes) to default.
var TermnialAppPalette = ColorTheme{ RGB(0x00, 0x00, 0x00), RGB(0xC2, 0x36, 0x21), RGB(0x25, 0xBC, 0x24), RGB(0xAD, 0xAD, 0x27), RGB(0x49, 0x2E, 0xE1), RGB(0xD3, 0x38, 0xD3), RGB(0x33, 0xBB, 0xC8), RGB(0xCB, 0xCC, 0xCD), RGB(0x81, 0x83, 0x83), RGB(0xFC, 0x39, 0x1F), RGB(0x31, 0xE7, 0x22), RGB(0xEA, 0xEC, 0x23), RGB(0x58, 0x33, 0xFF), RGB(0xF9, 0x35, 0xF8), RGB(0x14, 0xF0, 0xF0), RGB(0xE9, 0xEB, 0xEB), }
TermnialAppPalette is the color theme used by Mac Terminal.App.
var UbuntuPalette = ColorTheme{ RGB(0xDE, 0x38, 0x2B), RGB(0x39, 0xB5, 0x4A), RGB(0xFF, 0xC7, 0x06), RGB(0x00, 0x6F, 0xB8), RGB(0x76, 0x26, 0x71), RGB(0x2C, 0xB5, 0xE9), RGB(0xCC, 0xCC, 0xCC), RGB(0xFF, 0xFF, 0xFF), RGB(0x80, 0x80, 0x80), RGB(0x00, 0xFF, 0x00), RGB(0xFF, 0xFF, 0x00), RGB(0x00, 0x00, 0xFF), RGB(0xAD, 0xD8, 0xE6), RGB(0x00, 0xFF, 0xFF), RGB(0xE0, 0xFF, 0xFF), RGB(0xFF, 0xFF, 0xFF), }
UbuntuPalette is the color theme used by Ubuntu.
var VGAPalette = ColorTheme{ RGB(0x00, 0x00, 0x00), RGB(0xAA, 0x00, 0x00), RGB(0x00, 0xAA, 0x00), RGB(0xAA, 0x55, 0x00), RGB(0x00, 0x00, 0xAA), RGB(0xAA, 0x00, 0xAA), RGB(0x00, 0xAA, 0xAA), RGB(0xAA, 0xAA, 0xAA), RGB(0x55, 0x55, 0x55), RGB(0xFF, 0x55, 0x55), RGB(0x55, 0xFF, 0x55), RGB(0xFF, 0xFF, 0x55), RGB(0x55, 0x55, 0xFF), RGB(0xFF, 0x55, 0xFF), RGB(0x55, 0xFF, 0xFF), RGB(0xFF, 0xFF, 0xFF), }
VGAPalette is the classic VGA color theme.
var XPalette = ColorTheme{ RGB(0x00, 0x00, 0x00), RGB(0xFF, 0x00, 0x00), RGB(0x00, 0xFF, 0x00), RGB(0xFF, 0xFF, 0x00), RGB(0x00, 0x00, 0xFF), RGB(0xFF, 0x00, 0xFF), RGB(0x00, 0xFF, 0xFF), RGB(0xFF, 0xFF, 0xFF), RGB(0x80, 0x80, 0x80), RGB(0xFF, 0x00, 0x00), RGB(0x90, 0xEE, 0x90), RGB(0xFF, 0xFF, 0xE0), RGB(0xAD, 0xD8, 0xE6), RGB(0xFF, 0x00, 0xFF), RGB(0xE0, 0xFF, 0xFF), RGB(0xFF, 0xFF, 0xFF), }
XPalette is the color theme used by X.
var XTermPalette = ColorTheme{ RGB(0x00, 0x00, 0x00), RGB(0xCD, 0x00, 0x00), RGB(0x00, 0xCD, 0x00), RGB(0xCD, 0xCD, 0x00), RGB(0x00, 0x00, 0xEE), RGB(0xCD, 0x00, 0xCD), RGB(0x00, 0xCD, 0xCD), RGB(0xE5, 0xE5, 0xE5), RGB(0x7F, 0x7F, 0x7F), RGB(0xFF, 0x00, 0x00), RGB(0x00, 0xFF, 0x00), RGB(0xFF, 0xFF, 0x00), RGB(0x5C, 0x5C, 0xFF), RGB(0xFF, 0x00, 0xFF), RGB(0x00, 0xFF, 0xFF), RGB(0xFF, 0xFF, 0xFF), }
XTermPalette is the color theme used by xTerm.
Functions ¶
func DecodeCursorCardinal ¶
DecodeCursorCardinal decodes a cardinal cursor move, one of: CUU, CUD, CUF, or CUB.
func DecodeNumber ¶
DecodeNumber decodes a signed base-10 encoded number from the beginning of the given byte buffer. If the first byte is ';', it is skipped. Returns the decode number and the number of bytes decoded, or a non-nil decode error (either errRange or errSyntax).
func DecodeRune ¶
DecodeRune normalizes ANSI escaped control runes on top of normal UTF-8 decoding. If the first two bytes in p are \x1b (ESCape) and any byte from \x40 through \x5f (ASCII Uppercase), than it returns (cr, 2) where cr is the corresponding rune from U+0080 through U+009F (C1 Control).
For example, the most commonly seen escape sequence is "\x1B[" which encodes the '\u009B' Control Sequence Introducer (CSI) rune.
func DecodeXtermExtendedMouse ¶
func DecodeXtermExtendedMouse(id Escape, arg []byte) (b MouseState, p Point, err error)
DecodeXtermExtendedMouse decodes xterm extended (mode 1006) mouse control sequences of the form:
CSI < Cb ; Cx ; Cy M CSI < Cb ; Cx ; Cy m
Types ¶
type ColorModel ¶
ColorModel implements an SGR color model.
func ColorModels ¶
func ColorModels(models ...ColorModel) ColorModel
ColorModels combines the given models into a single ColorModel that applies each in serial.
type ColorModelFunc ¶
ColorModelFunc is a convenient way to implement to implement simple SGR color models.
func (ColorModelFunc) Convert ¶
func (f ColorModelFunc) Convert(c SGRColor) SGRColor
Convert calls the aliased function.
type ColorTheme ¶
type ColorTheme Palette
ColorTheme is a Palette for the first N (usually 16) colors; its conversion falls back to the normal 8-bit palette.
func (ColorTheme) Convert ¶
func (theme ColorTheme) Convert(c SGRColor) SGRColor
Convert returns the theme color definition, or its 8-bit palette definition, if the color is not already 24-bit color.
type Escape ¶
type Escape rune
Escape identifies an ANSI control code, escape sequence, or control sequence as a Unicode codepoint.
C0 and C1 controls are represented using their natural Unicode codepoints:
U+0000-U+001F: C0 controls U+0080-U+009F: C1 controls
The region U+EF00 through U+EFFF within the Private Use Area of the Basic Multilingual Plane is used to identify ANSI escape and control sequences.
Escape function are mapped into the range U+EF00-U+EF7f:
U+EF00-U+EF1F: unused / undefined : ASCII C0 range U+EF20-U+EF2F: character set selection functions : ASCII symbol range: <Space> and !"#$%&'()*+,-./ U+EF30-U+EF3F: private ESCape-sequence functions : ASCII number range: 0123456789:;<=>? U+EF40-U+EF5F: non-standard ESCape-sequence functions : ASCII uppercase range: @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_ : NOTE: won't be seen in practice; translated to C1 controls. U+EF60-U+EF7E: standard ESCape-sequence functions : ASCII lowercase range: `abcdefghijklmnopqrstuvwxyz{|}~ U+EF7F: malformed ESC sequence : ASCII <Delete>
Control functions are mapped into the range U+EF80-U+EFff:
U+EF80-U+EFBF: unused / undefined : ASCII C0, symbols, and numbers U+EFC0-U+EFFE: CSI functions : ASCII uppercase or lowercase U+EFFF: malformed CSI sequence : ASCII <Delete>
For example the control sequence for CUrsor Backwards (CUB) is CSI+D, typically encoded as "\x1b[D" identified by U+EFC4 = U+EF80 + 'D'.
func DecodeEscape ¶
DecodeEscape unpacks a UTF-8 encoded ANSI escape sequence at the beginning of p returning its Escape identifier, argument, and the number of bytes consumed by decoding it. If the returned escape identifier is non-zero, then it represents a complete escape sequence (perhaps malformed!).
The bytes p[:n] have been processed after DecodeEscape() returns: they're either represented by the returned Escape value or by subsequent bytes remaining in p[n:]. The caller MUST NOT pass the bytes in p[:n] to DecodeEscape() again, and SHOULD NOT look at them itself.
If the returned escape identifier is 0, the caller MAY proceed to decode a UTF-8 rune from p[n:]; if this rune turns out to be ESCape (U+001B), the caller MAY decide either to process it immediately, or whether to wait for additional input bytes which may complete an ESCape sequence.
func (Escape) AppendWith ¶
AppendWith appends the escape code and any given argument bytes to the given byte slice.
func (Escape) CSI ¶
CSI returns the byte name of the CSI control sequence identified by this escape value, if any; returns 0 and false otherwise.
func (Escape) ESC ¶
ESC returns the byte name of the ESCape sequence identified by this escape value, if any; returns 0 false otherwise.
func (Escape) IsCharacterSetControl ¶
IsCharacterSetControl returns true if the escape identifier is a character control rune, or an character set control escape sequence. Such controls can be ignored in a modern UTF-8 terminal.
func (Escape) IsEscape ¶
IsEscape returns true if the esacpe value isn't a normal rune; that is if it's in the range U+EF00 thru U+EFFF.
func (Escape) String ¶
String returns a string representation of the identified control, escape sequence, or control sequence: C0 controls are represented phonetically, C1 controls are represented mnemonically, escape sequences are "ESC+b", control sequences are "CSI+b", and the two malformed sentinel codepoints are "ESC+INVALID" and "CSI+INVALID" respectively. All other codepoints (albeit invalid Escape values) are represented using normal "U+XXXX" notation.
func (Escape) With ¶
With constructs an escape sequence with this identifier and given argument byte(s). Panics if the escape id is a normal non-Escape rune. See Seq.With for details.
type Mode ¶
type Mode uint64
Mode is an ANSI terminal mode constant.
const (
ModeMouseX10 Mode = 9
)
private mode constants TODO more coverage
const (
ModePrivate Mode = 1 << 63
)
Mode bit fields
func DecodeMode ¶
DecodeMode decodes a single mode parameter from escape argument bytes.
type MouseDecodeError ¶
MouseDecodeError represents an error decoding a mouse control sequence argument.
func (MouseDecodeError) Error ¶
func (mde MouseDecodeError) Error() string
type MouseState ¶
type MouseState uint8
MouseState represents buttons presses, button releases, motions, and scrolling.
const ( MouseButton1 MouseState = 0 MouseButton2 MouseState = 1 MouseButton3 MouseState = 2 MouseNoButton MouseState = 3 MouseModShift MouseState = 1 << 2 // 4 MouseModMeta MouseState = 1 << 3 // 8 MouseModControl MouseState = 1 << 4 // 16 MouseMotion MouseState = 1 << 5 // 32 MouseWheel MouseState = 1 << 6 // 64 MouseRelease MouseState = 1 << 7 // 128 )
MouseState constants, mapped directly to xterm's state bit fields. Users should usually be better served by functions like MouseState.ButtonID(), MouseState.Modifier(), and all the MouseState.Is* variants.
func (MouseState) ButtonID ¶
func (ms MouseState) ButtonID() uint8
ButtonID returns a normalized mouse button number: 1=left, 2=middle, 3=right, 4=wheel-up, 5=wheel-down (the value 6 is not technically impossible, but shouldn't be seen in practice).
func (MouseState) ButtonName ¶
func (ms MouseState) ButtonName() string
ButtonName returns a string representing the button, like "left".
func (MouseState) IsDrag ¶
func (ms MouseState) IsDrag() bool
IsDrag returns true if the state represents motion with a button held.
func (MouseState) IsMotion ¶
func (ms MouseState) IsMotion() bool
IsMotion returns true if the mouse state represents motion (with or without a button held).
func (MouseState) IsPress ¶
func (ms MouseState) IsPress() (id uint8, is bool)
IsPress returns true if the state represents a button press.
func (MouseState) IsRelease ¶
func (ms MouseState) IsRelease() bool
IsRelease returns true if the state represents a button release.
func (MouseState) Modifier ¶
func (ms MouseState) Modifier() MouseState
Modifier returns just the modifier bits, which can be tested against the constants MouseModShift, MouseModControl, and MouseModMeta.
func (MouseState) ModifierName ¶
func (ms MouseState) ModifierName() string
ModifierName returns a string representing the Modifier() bits, like "shift+ctrl".
func (MouseState) String ¶
func (ms MouseState) String() string
type Palette ¶
type Palette []SGRColor
Palette is a limited palette of color for legacy terminals.
type Point ¶
Point represents an ANSI screen point, relative to a 1,1 column,row origin.
This naturally aligns with the requirements of parsing and building ANSI control sequences (e.g. for cursor positioning and mouse events), while allowing the 1,1-origin semantic to be type checked.
var ZP Point
ZP is the zero point value; it is not a valid point, but useful only for signalling an undefined point.
func DecodePoint ¶
DecodePoint decose a screen point, e.g. from a CUP sequence, into an 1,1 origin-relative Point value.
func Pt ¶
Pt constructs an ANSI screen point; panics if either of the x or y components is not a counting number (> 0).
func PtFromImage ¶
PtFromImage creates an ANSI screen point from an image point, converting from 0,0 origin to 1,1 origin. Panics if the return value would have been not Point.Valid().
func (Point) Add ¶
Add the given relative image point to a copy of the receiver screen point, returning the copy.
func (Point) Diff ¶
Diff computes the relative difference (an image point) between two screen points.
func (Point) Sub ¶
Sub tract the given relative image point to a copy of the receiver screen point, returning the copy.
type Rectangle ¶
type Rectangle struct{ Min, Max Point }
Rectangle represents an ANSI screen rectangle, defined by a pair of ANSI screen points.
var ZR Rectangle
ZR is the zero rectangle value; it is not a valid rectangle, but useful only for signalling an undefined rectangle.
func Rect ¶
Rect constructs an ANSI screen rectangle; panics if either of the pairs of x,y components are invalid.
func RectFromImage ¶
RectFromImage creates an ANSI screen rectangle from an image rectangle, converting from 0,0 origin to 1,1 origin. Panics if either of the return value's points would not be Point.Valid().
func (Rectangle) Canon ¶
Canon returns the canonical version of r. The returned rectangle has minimum and maximum coordinates swapped if necessary so that it is well-formed.
func (Rectangle) Eq ¶
Eq reports whether r and s contain the same set of points. All empty rectangles are considered equal.
func (Rectangle) Inset ¶
Inset returns the rectangle r inset by n, which may be negative. If either of r's dimensions is less than 2*n then an empty rectangle near the center of r will be returned.
func (Rectangle) Intersect ¶
Intersect returns the largest rectangle contained by both r and s. If the two rectangles do not overlap then an empty rectangle at r.Min.
type SGRAttr ¶
type SGRAttr uint64
SGRAttr represents commonly used SGR attributes (ignoring blinks and fonts).
const ( // Causes a clear code to be written before the rest of any other attr // codes; the attr value isn't additive to whatever current state is. SGRAttrClear SGRAttr = 1 << iota // Bit fields for the 6 useful classic SGRCode*s SGRAttrBold SGRAttrDim SGRAttrItalic SGRAttrUnderscore SGRAttrNegative SGRAttrConceal )
SGRAttr attribute bitfields.
var SGRClear SGRAttr
SGRClear is the zero value of SGRAttr, represents no attributes set, and will encode to an SGR clear code (CSI 0 m).
func DecodeSGR ¶
DecodeSGR decodes an SGR attribute value from the given byte buffer; if non-nil error is returned, then n indicates the index of the offending byte.
func (SGRAttr) AppendTo ¶
AppendTo appends the appropriate ansi SGR control sequence to the given byte slice to affect any set bits or fg/bg colors in attr. If no bits or colors are set, append a clear code.
func (SGRAttr) BG ¶
BG returns any set background color, and a bool indicating if it was actually set (to distinguish from 0=black).
func (SGRAttr) ControlString ¶
ControlString returns the appropriate ansi SGR control sequence as a string value.
func (SGRAttr) Diff ¶
Diff returns the attr value which must be merged with the receiver to result in the given value.
func (SGRAttr) FG ¶
FG returns any set foreground color, and a bool indicating if it was actually set (to distinguish from 0=black).
type SGRColor ¶
type SGRColor uint32
SGRColor represents an SGR foreground or background color in any generation of color space.
const ( // The first 8 colors from the 3-bit space. SGRBlack SGRColor = iota SGRRed SGRGreen SGRYellow SGRBlue SGRMagenta SGRCyan SGRWhite // The 8 high intensity colors from 4-bit space. SGRBrightBlack SGRBrightRed SGRBrightGreen SGRBrightYellow SGRBrightBlue SGRBrightMagenta SGRBrightCyan SGRBrightWhite // 8-bit color space: 216 color cube; see colors.go. SGRCube16 SGRCube17 SGRCube18 SGRCube19 SGRCube20 SGRCube21 SGRCube22 SGRCube23 SGRCube24 SGRCube25 SGRCube26 SGRCube27 SGRCube28 SGRCube29 SGRCube30 SGRCube31 SGRCube32 SGRCube33 SGRCube34 SGRCube35 SGRCube36 SGRCube37 SGRCube38 SGRCube39 SGRCube40 SGRCube41 SGRCube42 SGRCube43 SGRCube44 SGRCube45 SGRCube46 SGRCube47 SGRCube48 SGRCube49 SGRCube50 SGRCube51 SGRCube52 SGRCube53 SGRCube54 SGRCube55 SGRCube56 SGRCube57 SGRCube58 SGRCube59 SGRCube60 SGRCube61 SGRCube62 SGRCube63 SGRCube64 SGRCube65 SGRCube66 SGRCube67 SGRCube68 SGRCube69 SGRCube70 SGRCube71 SGRCube72 SGRCube73 SGRCube74 SGRCube75 SGRCube76 SGRCube77 SGRCube78 SGRCube79 SGRCube80 SGRCube81 SGRCube82 SGRCube83 SGRCube84 SGRCube85 SGRCube86 SGRCube87 SGRCube88 SGRCube89 SGRCube90 SGRCube91 SGRCube92 SGRCube93 SGRCube94 SGRCube95 SGRCube96 SGRCube97 SGRCube98 SGRCube99 SGRCube100 SGRCube101 SGRCube102 SGRCube103 SGRCube104 SGRCube105 SGRCube106 SGRCube107 SGRCube108 SGRCube109 SGRCube110 SGRCube111 SGRCube112 SGRCube113 SGRCube114 SGRCube115 SGRCube116 SGRCube117 SGRCube118 SGRCube119 SGRCube120 SGRCube121 SGRCube122 SGRCube123 SGRCube124 SGRCube125 SGRCube126 SGRCube127 SGRCube128 SGRCube129 SGRCube130 SGRCube131 SGRCube132 SGRCube133 SGRCube134 SGRCube135 SGRCube136 SGRCube137 SGRCube138 SGRCube139 SGRCube140 SGRCube141 SGRCube142 SGRCube143 SGRCube144 SGRCube145 SGRCube146 SGRCube147 SGRCube148 SGRCube149 SGRCube150 SGRCube151 SGRCube152 SGRCube153 SGRCube154 SGRCube155 SGRCube156 SGRCube157 SGRCube158 SGRCube159 SGRCube160 SGRCube161 SGRCube162 SGRCube163 SGRCube164 SGRCube165 SGRCube166 SGRCube167 SGRCube168 SGRCube169 SGRCube170 SGRCube171 SGRCube172 SGRCube173 SGRCube174 SGRCube175 SGRCube176 SGRCube177 SGRCube178 SGRCube179 SGRCube180 SGRCube181 SGRCube182 SGRCube183 SGRCube184 SGRCube185 SGRCube186 SGRCube187 SGRCube188 SGRCube189 SGRCube190 SGRCube191 SGRCube192 SGRCube193 SGRCube194 SGRCube195 SGRCube196 SGRCube197 SGRCube198 SGRCube199 SGRCube200 SGRCube201 SGRCube202 SGRCube203 SGRCube204 SGRCube205 SGRCube206 SGRCube207 SGRCube208 SGRCube209 SGRCube210 SGRCube211 SGRCube212 SGRCube213 SGRCube214 SGRCube215 SGRCube216 SGRCube217 SGRCube218 SGRCube219 SGRCube220 SGRCube221 SGRCube222 SGRCube223 SGRCube224 SGRCube225 SGRCube226 SGRCube227 SGRCube228 SGRCube229 SGRCube230 SGRCube231 // 8-bit color space: 24 shades of gray; see colors.go. SGRGray1 SGRGray2 SGRGray3 SGRGray4 SGRGray5 SGRGray6 SGRGray7 SGRGray8 SGRGray9 SGRGray10 SGRGray11 SGRGray12 SGRGray13 SGRGray14 SGRGray15 SGRGray16 SGRGray17 SGRGray18 SGRGray19 SGRGray20 SGRGray21 SGRGray22 SGRGray23 SGRGray24 )
SGRColor constants.
func RGBA ¶
RGBA creates an SGRColor from color.Color() alpha-premultiplied values, ignoring the alpha value. Clips components to 0xffff before converting to 24-bit color (8-bit per channel).
type SGRColorMap ¶
SGRColorMap implements an SGR ColorModel around a map; any colors not in the map are passed through.
func (SGRColorMap) Convert ¶
func (cm SGRColorMap) Convert(c SGRColor) SGRColor
Convert a color through the map, passing through any misses.
type Seq ¶
type Seq struct {
// contains filtered or unexported fields
}
Seq represents an escape sequence, led either by ESC or CSI control sequence for writing to some output. May only be constructed by any of the Escape.With family of methods.
func (Seq) With ¶
With returns a copy of the sequence with the given argument bytes added. Argument bytes will be written immediately after the ESCape identifier itself.