File: ct_ansi.go

package info (click to toggle)
golang-github-daviddengcn-go-colortext 0.0~git20150719.0.3b18c85-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid, trixie
  • size: 80 kB
  • sloc: makefile: 2
file content (35 lines) | stat: -rw-r--r-- 493 bytes parent folder | download | duplicates (2)
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
// +build !windows

package ct

import (
	"fmt"
)

func resetColor() {
	fmt.Print("\x1b[0m")
}

func changeColor(fg Color, fgBright bool, bg Color, bgBright bool) {
	if fg == None && bg == None {
		return
	} // if

	s := ""
	if fg != None {
		s = fmt.Sprintf("%s%d", s, 30+(int)(fg-Black))
		if fgBright {
			s += ";1"
		} // if
	} // if

	if bg != None {
		if s != "" {
			s += ";"
		} // if
		s = fmt.Sprintf("%s%d", s, 40+(int)(bg-Black))
	} // if

	s = "\x1b[0;" + s + "m"
	fmt.Print(s)
}