File: colors.go

package info (click to toggle)
golang-github-mightyguava-jl 0.1.0%2Bgit20220705%2B8771236337c6-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,112 kB
  • sloc: makefile: 5
file content (68 lines) | stat: -rw-r--r-- 1,086 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package jl

import (
	"fmt"
)

type Color int

// Foreground text colors
const (
	Black Color = iota + 30
	Red
	Green
	Yellow
	Blue
	Magenta
	Cyan
	White
)

// Foreground Hi-Intensity text colors
const (
	HiBlack Color = iota + 90
	HiRed
	HiGreen
	HiYellow
	HiBlue
	HiMagenta
	HiCyan
	HiWhite
)

// AllColors is the set of colors used by default by DefaultCompactFieldFmts for ColorSequence.
var AllColors = []Color{
	// Skipping black because it's invisible on dark terminal backgrounds.
	// Skipping red because it's too prominent and means error
	Green,
	Yellow,
	Blue,
	Magenta,
	Cyan,
	White,
	HiBlack,
	HiRed,
	HiGreen,
	HiYellow,
	HiBlue,
	HiMagenta,
	HiCyan,
	HiWhite,
}

// ColorText wraps a text with ANSI escape codes to produce terminal colors.
func ColorText(c Color, text string) string {
	return fmt.Sprintf("\x1b[%dm%s\x1b[0m", c, text)
}

// LevelColors is a mapping of log level strings to colors.
var LevelColors = map[string]Color{
	"trace": White,
	"debug": White,
	"info": Green,
	"warn": Yellow,
	"warning": Yellow,
	"error": Red,
	"fatal": Red,
	"panic": Red,
}