storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/pkg/color/color.go (about) 1 /* 2 * MinIO Cloud Storage, (C) 2019 MinIO, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package color 18 19 import ( 20 "fmt" 21 22 "github.com/fatih/color" 23 ) 24 25 // global colors. 26 var ( 27 // Check if we stderr, stdout are dumb terminals, we do not apply 28 // ansi coloring on dumb terminals. 29 IsTerminal = func() bool { 30 return !color.NoColor 31 } 32 33 Bold = func() func(a ...interface{}) string { 34 if IsTerminal() { 35 return color.New(color.Bold).SprintFunc() 36 } 37 return fmt.Sprint 38 }() 39 40 RedBold = func() func(format string, a ...interface{}) string { 41 if IsTerminal() { 42 return color.New(color.FgRed, color.Bold).SprintfFunc() 43 } 44 return fmt.Sprintf 45 }() 46 47 Red = func() func(format string, a ...interface{}) string { 48 if IsTerminal() { 49 return color.New(color.FgRed).SprintfFunc() 50 } 51 return fmt.Sprintf 52 }() 53 54 Blue = func() func(format string, a ...interface{}) string { 55 if IsTerminal() { 56 return color.New(color.FgBlue).SprintfFunc() 57 } 58 return fmt.Sprintf 59 }() 60 61 Yellow = func() func(format string, a ...interface{}) string { 62 if IsTerminal() { 63 return color.New(color.FgYellow).SprintfFunc() 64 } 65 return fmt.Sprintf 66 }() 67 68 Green = func() func(a ...interface{}) string { 69 if IsTerminal() { 70 return color.New(color.FgGreen).SprintFunc() 71 } 72 return fmt.Sprint 73 }() 74 75 GreenBold = func() func(a ...interface{}) string { 76 if IsTerminal() { 77 return color.New(color.FgGreen, color.Bold).SprintFunc() 78 } 79 return fmt.Sprint 80 }() 81 82 CyanBold = func() func(a ...interface{}) string { 83 if IsTerminal() { 84 return color.New(color.FgCyan, color.Bold).SprintFunc() 85 } 86 return fmt.Sprint 87 }() 88 89 YellowBold = func() func(format string, a ...interface{}) string { 90 if IsTerminal() { 91 return color.New(color.FgYellow, color.Bold).SprintfFunc() 92 } 93 return fmt.Sprintf 94 }() 95 96 BlueBold = func() func(format string, a ...interface{}) string { 97 if IsTerminal() { 98 return color.New(color.FgBlue, color.Bold).SprintfFunc() 99 } 100 return fmt.Sprintf 101 }() 102 103 BgYellow = func() func(format string, a ...interface{}) string { 104 if IsTerminal() { 105 return color.New(color.BgYellow).SprintfFunc() 106 } 107 return fmt.Sprintf 108 }() 109 110 Black = func() func(format string, a ...interface{}) string { 111 if IsTerminal() { 112 return color.New(color.FgBlack).SprintfFunc() 113 } 114 return fmt.Sprintf 115 }() 116 117 FgRed = func() func(a ...interface{}) string { 118 if IsTerminal() { 119 return color.New(color.FgRed).SprintFunc() 120 } 121 return fmt.Sprint 122 }() 123 124 BgRed = func() func(format string, a ...interface{}) string { 125 if IsTerminal() { 126 return color.New(color.BgRed).SprintfFunc() 127 } 128 return fmt.Sprintf 129 }() 130 131 FgWhite = func() func(format string, a ...interface{}) string { 132 if IsTerminal() { 133 return color.New(color.FgWhite).SprintfFunc() 134 } 135 return fmt.Sprintf 136 }() 137 )