File: init.go

package info (click to toggle)
singularity-container 4.1.5%2Bds4-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 43,876 kB
  • sloc: asm: 14,840; sh: 3,190; ansic: 1,751; awk: 414; makefile: 413; python: 99
file content (53 lines) | stat: -rw-r--r-- 1,311 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
package progressui

import (
	"os"
	"runtime"
	"strconv"

	"github.com/morikuni/aec"
)

var colorRun aec.ANSI
var colorCancel aec.ANSI
var colorWarning aec.ANSI
var colorError aec.ANSI

const termHeightMin = 6

var termHeightInitial = termHeightMin
var termHeight = termHeightMin

func init() {
	// As recommended on https://no-color.org/
	if v := os.Getenv("NO_COLOR"); v != "" {
		// nil values will result in no ANSI color codes being emitted.
		return
	} else if runtime.GOOS == "windows" {
		colorRun = termColorMap["cyan"]
		colorCancel = termColorMap["yellow"]
		colorWarning = termColorMap["yellow"]
		colorError = termColorMap["red"]
	} else {
		colorRun = termColorMap["blue"]
		colorCancel = termColorMap["yellow"]
		colorWarning = termColorMap["yellow"]
		colorError = termColorMap["red"]
	}

	// Loosely based on the standard set by Linux LS_COLORS.
	if _, ok := os.LookupEnv("BUILDKIT_COLORS"); ok {
		envColorString := os.Getenv("BUILDKIT_COLORS")
		setUserDefinedTermColors(envColorString)
	}

	// Make the terminal height configurable at runtime.
	termHeightStr := os.Getenv("BUILDKIT_TTY_LOG_LINES")
	if termHeightStr != "" {
		termHeightVal, err := strconv.Atoi(termHeightStr)
		if err == nil && termHeightVal > 0 {
			termHeightInitial = termHeightVal
			termHeight = termHeightVal
		}
	}
}