github.com/minio/console@v1.4.1/pkg/logger/color/color.go (about) 1 // This file is part of MinIO Console Server 2 // Copyright (c) 2022 MinIO, Inc. 3 // 4 // This program is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Affero General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Affero General Public License for more details. 13 // 14 // You should have received a copy of the GNU Affero General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 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 FgRed = func() func(a ...interface{}) string { 41 if IsTerminal() { 42 return color.New(color.FgRed).SprintFunc() 43 } 44 return fmt.Sprint 45 }() 46 47 BgRed = func() func(format string, a ...interface{}) string { 48 if IsTerminal() { 49 return color.New(color.BgRed).SprintfFunc() 50 } 51 return fmt.Sprintf 52 }() 53 54 FgWhite = func() func(format string, a ...interface{}) string { 55 if IsTerminal() { 56 return color.New(color.FgWhite).SprintfFunc() 57 } 58 return fmt.Sprintf 59 }() 60 )