github.com/apcera/util@v0.0.0-20180322191801-7a50bc84ee48/terminal/terminal_colors.go (about)

     1  // Copyright 2014 Apcera Inc. All rights reserved.
     2  
     3  package terminal
     4  
     5  import "strconv"
     6  
     7  //---------------------------------------------------------------------------
     8  // Display helpers
     9  //---------------------------------------------------------------------------
    10  
    11  // ColorizeEscapeNamespace gives us a color namespace, escaped much like %q
    12  // would, but without the quotes (as they don't get colored).
    13  func ColorizeEscapeNamespace(ns string) string {
    14  	ourNs := strconv.Quote(ns)
    15  	if len(ourNs) < 2 {
    16  		// should panic, this is an API violation from strconv.Quote
    17  		return ns
    18  	}
    19  	ourNs = ourNs[1 : len(ourNs)-1]
    20  	ourColor := ColorSuccess
    21  	if ourNs != ns {
    22  		ourColor = ColorWarn
    23  	}
    24  	return Colorize(ourColor, ourNs)
    25  }