1// Copyright 2022 The Bazel Authors. All rights reserved. 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15// Package pprint provides colored "pretty print" output helper methods 16package pprint 17 18import ( 19 "fmt" 20 "os" 21) 22 23const ( 24 errorString = "\033[1m\033[31mERROR:\033[0m %s\n" 25 warningString = "\033[35mWARNING:\033[0m %s\n" 26 infoString = "\033[32mINFO:\033[0m %s\n" 27 clearLine = "\033[A\033[K" 28) 29 30// Error prints an error message in bazel style colors 31func Error(errorMsg string, args ...interface{}) { 32 fmt.Fprintf(os.Stderr, errorString, fmt.Sprintf(errorMsg, args...)) 33} 34 35// Warning prints a warning message in bazel style colors 36func Warning(warningMsg string, args ...interface{}) { 37 fmt.Fprintf(os.Stderr, warningString, fmt.Sprintf(warningMsg, args...)) 38} 39 40// Info prints an info message in bazel style colors 41func Info(infoMsg string, args ...interface{}) { 42 fmt.Fprintf(os.Stderr, infoString, fmt.Sprintf(infoMsg, args...)) 43} 44 45// ClearLine deletes the line above the cursor's current position. 46func ClearLine() { 47 fmt.Printf(clearLine) 48} 49