mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-05 03:42:08 +08:00
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package util
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
)
|
|
|
|
const (
|
|
colorRed = 31
|
|
colorGreen = 32
|
|
colorYellow = 33
|
|
)
|
|
|
|
// colorErrPrint prints formatted string in red to stderr
|
|
func ColorErrPrint(msg string) {
|
|
// ANSI escape code for red text
|
|
const redColor = "\033[31m"
|
|
// ANSI escape code to reset color
|
|
const resetColor = "\033[0m"
|
|
msg = redColor + msg + resetColor
|
|
// Print to stderr in red
|
|
fmt.Fprintf(os.Stderr, "%s\n", msg)
|
|
}
|
|
|
|
func ColorSuccessPrint(format string, a ...interface{}) {
|
|
// ANSI escape code for green text is \033[32m
|
|
// \033[0m resets the color
|
|
fmt.Printf("\033[32m"+format+"\033[0m", a...)
|
|
}
|
|
|
|
func colorPrint(colorCode int, format string, a ...any) {
|
|
fmt.Printf("\x1b[%dm%s\x1b[0m\n", colorCode, fmt.Sprintf(format, a...))
|
|
}
|
|
|
|
func colorErrPrint(colorCode int, format string, a ...any) {
|
|
log.Printf("\x1b[%dm%s\x1b[0m\n", colorCode, fmt.Sprintf(format, a...))
|
|
}
|
|
|
|
func ErrorPrint(s string) {
|
|
colorErrPrint(colorRed, "%v", s)
|
|
}
|
|
|
|
func SuccessPrint(s string) {
|
|
colorPrint(colorGreen, "%v", s)
|
|
}
|
|
|
|
func WarningPrint(s string) {
|
|
colorPrint(colorYellow, "Warning: But %v", s)
|
|
}
|
|
|
|
func ErrStr(err error, str string) error {
|
|
return fmt.Errorf("%v;%s", err, str)
|
|
}
|