storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/logger/utils.go (about)

     1  /*
     2   * MinIO Cloud Storage, (C) 2018 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 logger
    18  
    19  import (
    20  	"fmt"
    21  	"regexp"
    22  	"runtime"
    23  
    24  	"storj.io/minio/pkg/color"
    25  )
    26  
    27  var ansiRE = regexp.MustCompile("(\x1b[^m]*m)")
    28  
    29  // Print ANSI Control escape
    30  func ansiEscape(format string, args ...interface{}) {
    31  	var Esc = "\x1b"
    32  	fmt.Printf("%s%s", Esc, fmt.Sprintf(format, args...))
    33  }
    34  
    35  func ansiMoveRight(n int) {
    36  	if runtime.GOOS == "windows" {
    37  		return
    38  	}
    39  	if color.IsTerminal() {
    40  		ansiEscape("[%dC", n)
    41  	}
    42  }
    43  
    44  func ansiSaveAttributes() {
    45  	if runtime.GOOS == "windows" {
    46  		return
    47  	}
    48  	if color.IsTerminal() {
    49  		ansiEscape("7")
    50  	}
    51  }
    52  
    53  func ansiRestoreAttributes() {
    54  	if runtime.GOOS == "windows" {
    55  		return
    56  	}
    57  	if color.IsTerminal() {
    58  		ansiEscape("8")
    59  	}
    60  
    61  }