├── .gitignore ├── LICENSE ├── README.md ├── _examples └── main.go ├── ansi.go └── go.mod /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | *.out 26 | *.html 27 | *.txt -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Dean Karn 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## ansi 2 | ![Project status](https://img.shields.io/badge/version-3.0.0-green.svg) 3 | [![GoDoc](https://godoc.org/github.com/go-playground/ansi?status.svg)](https://godoc.org/github.com/go-playground/ansi) 4 | ![License](https://img.shields.io/dub/l/vibe-d.svg) 5 | 6 | ansi contains a bunch of constants and possibly additional terminal related functionality in the future. 7 | 8 | Why another ANSI library? 9 | ------------------------ 10 | I already had the ANSI escape sequences the way I want them, but was repeating the same code in multiple 11 | projects and so created this to stop that; it solves nothing new. 12 | 13 | Installation 14 | ----------- 15 | 16 | Use go get 17 | 18 | ```shell 19 | go get -u github.com/go-playground/ansi/v3 20 | ``` 21 | 22 | Usage 23 | ------ 24 | ```go 25 | package main 26 | 27 | import ( 28 | "fmt" 29 | 30 | "github.com/go-playground/ansi/v3" 31 | ) 32 | 33 | // make your own combinations if you want 34 | const blinkRed = ansi.Red + ansi.Blink + ansi.Underline 35 | 36 | func main() { 37 | 38 | // Foreground 39 | fmt.Printf("%s%s%s\n", ansi.Black+ansi.GrayBackground, "testing foreground", ansi.Reset) 40 | fmt.Printf("%s%s%s\n", ansi.Gray, "testing foreground", ansi.Reset) 41 | fmt.Printf("%s%s%s\n", ansi.DarkGray, "testing foreground", ansi.Reset) 42 | fmt.Printf("%s%s%s\n", ansi.Red, "testing foreground", ansi.Reset) 43 | fmt.Printf("%s%s%s\n", ansi.LightRed, "testing foreground", ansi.Reset) 44 | fmt.Printf("%s%s%s\n", ansi.Green, "testing foreground", ansi.Reset) 45 | fmt.Printf("%s%s%s\n", ansi.LightGreen, "testing foreground", ansi.Reset) 46 | fmt.Printf("%s%s%s\n", ansi.Yellow, "testing foreground", ansi.Reset) 47 | fmt.Printf("%s%s%s\n", ansi.LightYellow, "testing foreground", ansi.Reset) 48 | fmt.Printf("%s%s%s\n", ansi.Blue, "testing foreground", ansi.Reset) 49 | fmt.Printf("%s%s%s\n", ansi.LightBlue, "testing foreground", ansi.Reset) 50 | fmt.Printf("%s%s%s\n", ansi.Magenta, "testing foreground", ansi.Reset) 51 | fmt.Printf("%s%s%s\n", ansi.LightMagenta, "testing foreground", ansi.Reset) 52 | fmt.Printf("%s%s%s\n", ansi.Cyan, "testing foreground", ansi.Reset) 53 | fmt.Printf("%s%s%s\n", ansi.LightCyan, "testing foreground", ansi.Reset) 54 | fmt.Printf("%s%s%s\n\n", ansi.White, "testing foreground", ansi.Reset) 55 | 56 | // Background 57 | fmt.Printf("%s%s%s\n", ansi.Gray+ansi.BlackBackground, "testing background", ansi.Reset) 58 | fmt.Printf("%s%s%s\n", ansi.Black+ansi.RedBackground, "testing background", ansi.Reset) 59 | fmt.Printf("%s%s%s\n", ansi.Black+ansi.GreenBackground, "testing background", ansi.Reset) 60 | fmt.Printf("%s%s%s\n", ansi.Black+ansi.YellowBackground, "testing background", ansi.Reset) 61 | fmt.Printf("%s%s%s\n", ansi.Black+ansi.BlueBackground, "testing background", ansi.Reset) 62 | fmt.Printf("%s%s%s\n", ansi.Black+ansi.MagentaBackground, "testing background", ansi.Reset) 63 | fmt.Printf("%s%s%s\n", ansi.Black+ansi.CyanBackground, "testing background", ansi.Reset) 64 | fmt.Printf("%s%s%s\n\n", ansi.Black+ansi.GrayBackground, "testing background", ansi.Reset) 65 | 66 | // Inverse 67 | fmt.Printf("%s%s%s\n\n", ansi.Inverse, "testing inverse", ansi.InverseOff) 68 | 69 | // Italics 70 | fmt.Printf("%s%s%s\n\n", ansi.Italics, "testing italics", ansi.ItalicsOff) 71 | 72 | // Underline 73 | fmt.Printf("%s%s%s\n\n", ansi.Underline, "testing underline", ansi.UnderlineOff) 74 | 75 | // Blink 76 | fmt.Printf("%s%s%s\n\n", ansi.Blink, "testing blink", ansi.BlinkOff) 77 | 78 | // Bold 79 | fmt.Printf("%s%s%s %s\n\n", ansi.Bold, "testing bold", ansi.BoldOff, "and normal strings") 80 | 81 | // Custom combination 82 | fmt.Printf("%s%s%s\n", blinkRed, "blink red underline", ansi.Reset) 83 | } 84 | ``` 85 | 86 | Licenses 87 | -------- 88 | - [MIT License](https://raw.githubusercontent.com/go-playground/ansi/master/LICENSE) (MIT), Copyright (c) 2017 Dean Karn 89 | -------------------------------------------------------------------------------- /_examples/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/go-playground/ansi/v3" 7 | ) 8 | 9 | // make your own combinations if you want 10 | const blinkRed = ansi.Red + ansi.Blink + ansi.Underline 11 | 12 | func main() { 13 | 14 | // Foreground 15 | fmt.Printf("%s%s%s\n", ansi.Black+ansi.GrayBackground, "testing foreground", ansi.Reset) 16 | fmt.Printf("%s%s%s\n", ansi.Gray, "testing foreground", ansi.Reset) 17 | fmt.Printf("%s%s%s\n", ansi.DarkGray, "testing foreground", ansi.Reset) 18 | fmt.Printf("%s%s%s\n", ansi.Red, "testing foreground", ansi.Reset) 19 | fmt.Printf("%s%s%s\n", ansi.LightRed, "testing foreground", ansi.Reset) 20 | fmt.Printf("%s%s%s\n", ansi.Green, "testing foreground", ansi.Reset) 21 | fmt.Printf("%s%s%s\n", ansi.LightGreen, "testing foreground", ansi.Reset) 22 | fmt.Printf("%s%s%s\n", ansi.Yellow, "testing foreground", ansi.Reset) 23 | fmt.Printf("%s%s%s\n", ansi.LightYellow, "testing foreground", ansi.Reset) 24 | fmt.Printf("%s%s%s\n", ansi.Blue, "testing foreground", ansi.Reset) 25 | fmt.Printf("%s%s%s\n", ansi.LightBlue, "testing foreground", ansi.Reset) 26 | fmt.Printf("%s%s%s\n", ansi.Magenta, "testing foreground", ansi.Reset) 27 | fmt.Printf("%s%s%s\n", ansi.LightMagenta, "testing foreground", ansi.Reset) 28 | fmt.Printf("%s%s%s\n", ansi.Cyan, "testing foreground", ansi.Reset) 29 | fmt.Printf("%s%s%s\n", ansi.LightCyan, "testing foreground", ansi.Reset) 30 | fmt.Printf("%s%s%s\n\n", ansi.White, "testing foreground", ansi.Reset) 31 | 32 | // Background 33 | fmt.Printf("%s%s%s\n", ansi.Gray+ansi.BlackBackground, "testing background", ansi.Reset) 34 | fmt.Printf("%s%s%s\n", ansi.Black+ansi.RedBackground, "testing background", ansi.Reset) 35 | fmt.Printf("%s%s%s\n", ansi.Black+ansi.GreenBackground, "testing background", ansi.Reset) 36 | fmt.Printf("%s%s%s\n", ansi.Black+ansi.YellowBackground, "testing background", ansi.Reset) 37 | fmt.Printf("%s%s%s\n", ansi.Black+ansi.BlueBackground, "testing background", ansi.Reset) 38 | fmt.Printf("%s%s%s\n", ansi.Black+ansi.MagentaBackground, "testing background", ansi.Reset) 39 | fmt.Printf("%s%s%s\n", ansi.Black+ansi.CyanBackground, "testing background", ansi.Reset) 40 | fmt.Printf("%s%s%s\n\n", ansi.Black+ansi.GrayBackground, "testing background", ansi.Reset) 41 | 42 | // Inverse 43 | fmt.Printf("%s%s%s\n\n", ansi.Inverse, "testing inverse", ansi.InverseOff) 44 | 45 | // Italics 46 | fmt.Printf("%s%s%s\n\n", ansi.Italics, "testing italics", ansi.ItalicsOff) 47 | 48 | // Underline 49 | fmt.Printf("%s%s%s\n\n", ansi.Underline, "testing underline", ansi.UnderlineOff) 50 | 51 | // Blink 52 | fmt.Printf("%s%s%s\n\n", ansi.Blink, "testing blink", ansi.BlinkOff) 53 | 54 | // Bold 55 | fmt.Printf("%s%s%s %s\n\n", ansi.Bold, "testing bold", ansi.BoldOff, "and normal strings") 56 | 57 | // Custom combination 58 | fmt.Printf("%s%s%s\n", blinkRed, "blink red underline", ansi.Reset) 59 | } 60 | -------------------------------------------------------------------------------- /ansi.go: -------------------------------------------------------------------------------- 1 | package ansi 2 | 3 | // EscSeq is a predefined ANSI escape sequence 4 | type EscSeq string 5 | 6 | // ANSI escape sequences 7 | // NOTE: in a standard xterm terminal the light colors will appear BOLD instead of the light variant 8 | const ( 9 | Reset EscSeq = "\x1b[0m" 10 | Italics = "\x1b[3m" 11 | Underline = "\x1b[4m" 12 | Blink = "\x1b[5m" 13 | Inverse = "\x1b[7m" 14 | ItalicsOff = "\x1b[23m" 15 | UnderlineOff = "\x1b[24m" 16 | BlinkOff = "\x1b[25m" 17 | InverseOff = "\x1b[27m" 18 | Black = "\x1b[30m" 19 | DarkGray = "\x1b[30;1m" 20 | Red = "\x1b[31m" 21 | LightRed = "\x1b[31;1m" 22 | Green = "\x1b[32m" 23 | LightGreen = "\x1b[32;1m" 24 | Yellow = "\x1b[33m" 25 | LightYellow = "\x1b[33;1m" 26 | Blue = "\x1b[34m" 27 | LightBlue = "\x1b[34;1m" 28 | Magenta = "\x1b[35m" 29 | LightMagenta = "\x1b[35;1m" 30 | Cyan = "\x1b[36m" 31 | LightCyan = "\x1b[36;1m" 32 | Gray = "\x1b[37m" 33 | White = "\x1b[37;1m" 34 | ResetForeground = "\x1b[39m" 35 | BlackBackground = "\x1b[40m" 36 | RedBackground = "\x1b[41m" 37 | GreenBackground = "\x1b[42m" 38 | YellowBackground = "\x1b[43m" 39 | BlueBackground = "\x1b[44m" 40 | MagentaBackground = "\x1b[45m" 41 | CyanBackground = "\x1b[46m" 42 | GrayBackground = "\x1b[47m" 43 | ResetBackground = "\x1b[49m" 44 | Bold = "\x1b[1m" 45 | BoldOff = "\x1b[22m" 46 | ) 47 | 48 | // Left out due to not being widely supported: 49 | // StrikethroughOn = "\x1b[9m" 50 | // StrikethroughOff = "\x1b[29m" 51 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/go-playground/ansi/v3 2 | 3 | go 1.13 4 | --------------------------------------------------------------------------------