2021-04-18 19:41:13 +00:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-05-09 02:04:36 +00:00
|
|
|
|
|
|
|
package logger
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"regexp"
|
2020-01-13 21:05:51 +00:00
|
|
|
"runtime"
|
2018-05-09 02:04:36 +00:00
|
|
|
|
2021-06-01 21:59:40 +00:00
|
|
|
"github.com/minio/minio/internal/color"
|
2018-05-09 02:04:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var ansiRE = regexp.MustCompile("(\x1b[^m]*m)")
|
|
|
|
|
|
|
|
// Print ANSI Control escape
|
|
|
|
func ansiEscape(format string, args ...interface{}) {
|
2022-01-02 17:15:06 +00:00
|
|
|
Esc := "\x1b"
|
2018-05-09 02:04:36 +00:00
|
|
|
fmt.Printf("%s%s", Esc, fmt.Sprintf(format, args...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func ansiMoveRight(n int) {
|
2020-01-13 21:05:51 +00:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
return
|
|
|
|
}
|
2019-10-04 17:35:33 +00:00
|
|
|
if color.IsTerminal() {
|
2018-08-06 12:46:49 +00:00
|
|
|
ansiEscape("[%dC", n)
|
|
|
|
}
|
2018-05-09 02:04:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func ansiSaveAttributes() {
|
2020-01-13 21:05:51 +00:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
return
|
|
|
|
}
|
2019-10-04 17:35:33 +00:00
|
|
|
if color.IsTerminal() {
|
2018-08-06 12:46:49 +00:00
|
|
|
ansiEscape("7")
|
|
|
|
}
|
2018-05-09 02:04:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func ansiRestoreAttributes() {
|
2020-01-13 21:05:51 +00:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
return
|
|
|
|
}
|
2019-10-04 17:35:33 +00:00
|
|
|
if color.IsTerminal() {
|
2018-08-06 12:46:49 +00:00
|
|
|
ansiEscape("8")
|
|
|
|
}
|
2018-06-18 19:04:46 +00:00
|
|
|
}
|