github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/cmd/commands/cli/clio/clio.go (about) 1 /* 2 * Copyright (C) 2017 The "MysteriumNetwork/node" Authors. 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU 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 General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 package clio 19 20 import ( 21 "fmt" 22 "unicode" 23 ) 24 25 const statusColor = "\033[33m" 26 const warningColor = "\033[31m" 27 const successColor = "\033[32m" 28 const infoColor = "\033[93m" 29 30 // Status prints a message with a given status. 31 func Status(label string, items ...interface{}) { 32 fmt.Printf(statusColor+"[%s] \033[0m", label) 33 fmt.Println(sentenceCase(fmt.Sprintln(items...))) 34 } 35 36 // Warn prints a warning. 37 func Warn(items ...interface{}) { 38 fmt.Printf(warningColor + "[WARNING] \033[0m") 39 fmt.Println(sentenceCase(fmt.Sprint(items...))) 40 } 41 42 // Warnf prints a warning using fmt.Printf. 43 func Warnf(format string, items ...interface{}) { 44 fmt.Printf(warningColor + "[WARNING] \033[0m") 45 fmt.Print(sentenceCase(fmt.Sprintf(format, items...))) 46 } 47 48 // Success prints a success message. 49 func Success(items ...interface{}) { 50 fmt.Printf(successColor + "[SUCCESS] \033[0m") 51 fmt.Println(sentenceCase(fmt.Sprint(items...))) 52 } 53 54 // Info prints an information message. 55 func Info(items ...interface{}) { 56 fmt.Printf(infoColor + "[INFO] \033[0m") 57 fmt.Println(sentenceCase(fmt.Sprint(items...))) 58 } 59 60 // Error prints an error message 61 func Error(items ...interface{}) { 62 fmt.Printf(warningColor + "[ERROR] \033[0m") 63 fmt.Println(sentenceCase(fmt.Sprint(items...))) 64 } 65 66 // Infof prints an information message using fmt.Printf. 67 func Infof(format string, items ...interface{}) { 68 fmt.Printf(infoColor + "[INFO] \033[0m") 69 fmt.Print(sentenceCase(fmt.Sprintf(format, items...))) 70 } 71 72 // sentenceCase capitalizes the first letter. 73 func sentenceCase(s string) string { 74 runes := []rune(s) 75 return string(unicode.ToUpper(runes[0])) + string(runes[1:]) 76 }