Documentation ¶
Overview ¶
Typical usage is to use Parseln() or MustParseln(), and use the resulting string in succeeding `fmt` or `log` calls.
package main import ( "fmt" "github.com/foize/go.sgr" ) func main() { exampleString := sgr.MustParseln("This is an example: [fg-red bold] important text [reset] normal text again.") fmt.Print(exampleString) secretNumberFormat := sgr.MustParseln("The secret number is [bg-17 blink]%d") fmt.Printf(secretNumberFormat, 42) fmt.Println("This text is normal again, MustParseln puts a reset at the end of the line.") }
If you want to use an opening square bracket you should escape it like this:
sgr.MustParseln("foo [[ bar")
This will print "foo [ bar".
Index ¶
- Constants
- Variables
- func BgColor(num uint8) string
- func FgColor(num uint8) string
- func MustParse(format string) string
- func MustParseWithoutReset(format string) string
- func MustParseln(format string) string
- func Parse(format string) (string, error)
- func ParseWithoutReset(format string) (string, error)
- func Parseln(format string) (string, error)
- func Print(a ...interface{}) (n int, err error)
- func Printf(format string, a ...interface{}) (n int, err error)
- func Println(a ...interface{}) (n int, err error)
- type ColorWriter
Constants ¶
View Source
const ( FgBlack = "\x1b[38;05;0m" FgRed = "\x1b[38;05;1m" FgGreen = "\x1b[38;05;2m" FgYellow = "\x1b[38;05;3m" FgBlue = "\x1b[38;05;4m" FgMagenta = "\x1b[38;05;5m" FgCyan = "\x1b[38;05;6m" FgGrey = "\x1b[38;05;7m" FgWhite = "\x1b[38;05;255m" BgBlack = "\x1b[48;05;0m" BgRed = "\x1b[48;05;1m" BgGreen = "\x1b[48;05;2m" BgYellow = "\x1b[48;05;3m" BgBlue = "\x1b[48;05;4m" BgMagenta = "\x1b[48;05;5m" BgCyan = "\x1b[48;05;6m" BgGrey = "\x1b[48;05;7m" BgWhite = "\x1b[48;05;255m" )
Color strings
View Source
const ( Reset = "\x1b[0m" // Reset all SGR options. ResetForegroundColor = "\x1b[39m" // Reset foreground color. ResetBackgroundColor = "\x1b[49m" // Reset background color. Bold = "\x1b[1m" BoldOff = "\x1b[22m" Underline = "\x1b[4m" UnderlineOff = "\x1b[24m" Blink = "\x1b[5m" // Less then 150 per minute. BlinkOff = "\x1b[25m" ImageNegative = "\x1b[7m" // Set reversed-video active (foreground and background negative). ImagePositive = "\x1b[27m" // Reset reversed-video to normal. Framed = "\x1b[51m" Encircled = "\x1b[52m" FramedEncircledOff = "\x1b[54m" Overlined = "\x1b[53m" OverlinedOff = "\x1b[55m" )
Option strings
Variables ¶
View Source
var ExistingNewline = []byte(FgWhite + BgGreen + `↵ ` + Reset)
ExistingNewline is written to the Writer set to ColorWriter when the written bytes ended with a newline
View Source
var ForcedNewline = []byte(FgWhite + BgRed + `↵ ` + Reset)
ForcedNewline is written to the Writer set to ColorWriter when the written bytes didn't end with a newline
Functions ¶
func MustParseWithoutReset ¶
func MustParseln ¶
func ParseWithoutReset ¶
func Print ¶
Print wraps fmt.Print All arguments with type string are parsed before calling fmt.Print
Types ¶
type ColorWriter ¶
type ColorWriter struct {
// contains filtered or unexported fields
}
ColorWriter implements io.Writer
func NewColorWriter ¶
func NewColorWriter(w io.Writer, color string, forceNewline bool) *ColorWriter
NewColorWriter creates a new ColorWriter. example: NewColorWriter(os.Stdout, sgr.FgBlue, true)
Click to show internal directories.
Click to hide internal directories.