本文整理匯總了Golang中github.com/mgutz/ansi.ColorFunc函數的典型用法代碼示例。如果您正苦於以下問題:Golang ColorFunc函數的具體用法?Golang ColorFunc怎麽用?Golang ColorFunc使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ColorFunc函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: init
func init() {
errCol = ansi.ColorFunc("white+b:red")
warnCol = ansi.ColorFunc("208+b")
infoCol = ansi.ColorFunc("white+b")
debugCol = ansi.ColorFunc("white")
bold = ansi.ColorFunc("white+b")
}
示例2: RemoveFormat
// RemoveFormat removes the current format
func RemoveFormat() {
LInfo = "info"
LWarn = "warn"
LErr = "error"
LStart = "start"
LDone = "done"
STime = ansi.ColorFunc("")
SFail = ansi.ColorFunc("")
SKey = ansi.ColorFunc("")
SVal = ansi.ColorFunc("")
}
示例3: Status
// Status implements the `got status` command.
func Status(c *cli.Context) {
// Open the database
db := util.OpenDB()
defer db.Close()
// Colored output
yellow := ansi.ColorFunc("yellow+h:black")
green := ansi.ColorFunc("green+h:black")
red := ansi.ColorFunc("red+h:black")
// Perform operations in a read-only lock
err := db.View(func(tx *bolt.Tx) error {
// Get the current commit sha
info := tx.Bucket(util.INFO)
objects := tx.Bucket(util.OBJECTS)
current := info.Get(util.CURRENT)
// Find the differences between the working directory and the tree of the current commit.
differences := []Difference{}
if current != nil {
// Load commit object
commit := types.DeserializeCommitObject(objects.Get(current))
util.DebugLog("Comparing working directory to commit '" + commit.Message + "'.")
differences = TreeDiff(objects, commit.Tree, ".")
} else {
// Compare directory to the empty hash
util.DebugLog("Comparing working directory to empty tree.")
differences = TreeDiff(objects, types.EMPTY, ".")
}
// Print out the found differences
for _, difference := range differences {
line := fmt.Sprintf("%s %s", difference.Type, difference.FilePath)
if difference.Type == "A" {
fmt.Println(green(line))
}
if difference.Type == "R" {
fmt.Println(red(line))
}
if difference.Type == "M" {
fmt.Println(yellow(line))
}
}
return nil
})
if err != nil {
log.Fatal("Error reading from the database.")
}
}
示例4: AssertJSONBody
func AssertJSONBody(tb testing.TB, exp, act interface{}) {
red := ansi.ColorCode("red+h:black")
green := ansi.ColorCode("green+h:black")
yellow := ansi.ColorFunc("yellow+h")
reset := ansi.ColorCode("reset")
var actBuf bytes.Buffer
err := json.Indent(&actBuf, []byte(act.(string)), "", " ")
if err != nil {
fmt.Println(red, "Invalid json: ", act, reset)
}
act = string(actBuf.Bytes())
var expBuf bytes.Buffer
err = json.Indent(&expBuf, []byte(exp.(string)), "", " ")
if err != nil {
fmt.Println(red, "Invalid json: ", exp, reset)
}
exp = string(expBuf.Bytes())
if !reflect.DeepEqual(exp, act) {
_, file, line, _ := runtime.Caller(1)
fmt.Println(yellow(fmt.Sprintf("%s:%d", filepath.Base(file), line)))
fmt.Println(green, "Expected: ", exp, reset)
fmt.Println(red, " Got: ", act, reset)
tb.FailNow()
}
}
示例5: printCommit
// Prints the information for one commit in the log, including ascii graph on left side of commits if
// -graph arg is true.
func printCommit(node LogNode, db datas.Database) (err error) {
lineno := 0
doColor := func(s string) string { return s }
if useColor {
doColor = ansi.ColorFunc("red+h")
}
fmt.Printf("%s%s\n", genGraph(node, lineno), doColor(node.commit.Hash().String()))
parents := commitRefsFromSet(node.commit.Get(datas.ParentsField).(types.Set))
lineno++
if len(parents) > 1 {
pstrings := []string{}
for _, cr := range parents {
pstrings = append(pstrings, cr.TargetHash().String())
}
fmt.Printf("%sMerge: %s\n", genGraph(node, lineno), strings.Join(pstrings, " "))
} else if len(parents) == 1 {
fmt.Printf("%sParent: %s\n", genGraph(node, lineno), parents[0].TargetHash().String())
} else {
fmt.Printf("%sParent: None\n", genGraph(node, lineno))
}
if *maxLines != 0 {
var n int
if *showValue {
n, err = writeCommitLines(node, *maxLines, lineno, os.Stdout)
} else {
n, err = writeDiffLines(node, db, *maxLines, lineno, os.Stdout)
}
lineno += n
}
return
}
示例6: PrintUsage
func (self *Context) PrintUsage() {
if self.App.Usage != "" {
self.Print(self.App.Usage)
return
}
boldUnderline := ansi.ColorFunc("white+bu")
self.Print("\n%s", boldUnderline("COMMANDS"))
maxLength1 := getMaxLength(self.App.Commands)
maxLength2 := getMaxLength(self.App.Flags) + 2
maxLength := maxLength1
if maxLength2 > maxLength1 {
maxLength = maxLength2
}
for _, k := range self.App.CommandKeys {
command := padRight(k, " ", maxLength+3)
self.Print(command + self.App.Commands[k])
}
if len(self.App.FlagKeys) > 0 {
self.Print("\n%s", boldUnderline("FLAGS"))
for _, k := range self.App.FlagKeys {
flag := padRight("--"+k, " ", maxLength+3)
desc := self.App.Flags[k]
if self.App.FlagDefaults[k] != "" {
desc += " (default: " + self.App.FlagDefaults[k] + ")"
}
self.Print(flag + desc)
}
}
}
示例7: handleMessage
func handleMessage(msg wray.Message) {
redColor := ansi.ColorFunc("red+h")
capColor := ansi.ColorFunc("yellow")
infoColor := ansi.ColorFunc("white")
s, err := strconv.Unquote(msg.Data)
if err != nil {
fmt.Println("Error: ", err)
}
var m logMessage
err = json.Unmarshal([]byte(s), &m)
if err != nil {
fmt.Println("Error:", err)
}
var level string
var colorFunc func(string) string
switch m.Severity {
case 0:
level = "TRACE"
colorFunc = infoColor
case 1:
level = "DEBUG"
colorFunc = infoColor
case 2:
level = "INFO"
colorFunc = infoColor
case 3:
level = "WARN"
colorFunc = capColor
case 4:
level = "ERROR"
colorFunc = redColor
case 5:
level = "IMPORTANT"
colorFunc = redColor
case 6:
level = "FATAL"
colorFunc = redColor
}
fmt.Println(colorFunc(fmt.Sprintf("%s [%s] - %s", m.Time, level, m.Message)))
}
示例8: cmdList
func cmdList(c *cli.Context) error {
conf, err := config.Open(c.GlobalString("config"))
if err != nil {
Logger.Fatalf("Cannot load configuration: %v", err)
return nil
}
// ansi coloring
greenColorize := func(input string) string { return input }
redColorize := func(input string) string { return input }
yellowColorize := func(input string) string { return input }
if terminal.IsTerminal(int(os.Stdout.Fd())) {
greenColorize = ansi.ColorFunc("green+b+h")
redColorize = ansi.ColorFunc("red")
yellowColorize = ansi.ColorFunc("yellow")
}
fmt.Printf("Listing entries\n\n")
for _, host := range conf.Hosts.SortedList() {
options := host.Options()
options.Remove("User")
options.Remove("Port")
host.ApplyDefaults(&conf.Defaults)
fmt.Printf(" %s -> %s\n", greenColorize(host.Name()), host.Prototype())
if len(options) > 0 {
fmt.Printf(" %s %s\n", yellowColorize("[custom options]"), strings.Join(options.ToStringList(), " "))
}
fmt.Println()
}
generalOptions := conf.Defaults.Options()
if len(generalOptions) > 0 {
fmt.Println(greenColorize(" (*) General options:"))
for _, opt := range conf.Defaults.Options() {
fmt.Printf(" %s: %s\n", redColorize(opt.Name), opt.Value)
}
fmt.Println()
}
return nil
}
示例9: init
func init() {
flag.Usage = func() {
fmt.Printf("Usage: ./colorize -color 'red:green' -alt=false\n")
flag.PrintDefaults()
}
flag.Parse()
if *colorFlag != "" {
color = ansi.ColorFunc(*colorFlag)
}
}
示例10: String
func (m *Map) String() string {
var b bytes.Buffer
// Nice colors for debugging.
r := ansi.ColorFunc("red")
g := ansi.ColorFunc("green")
for y := 0; y < m.size; y++ {
for x := 0; x < m.size; x++ {
v := m.get(x, y)
if v > 0 {
fmt.Fprint(&b, r(fmt.Sprintf("%.2f ", v)))
} else {
fmt.Fprint(&b, g(fmt.Sprintf("%.2f ", v)))
}
}
fmt.Fprint(&b, "\n")
}
return b.String()
}
示例11: getColorFunction
func getColorFunction(code string) ColorizeFunc {
var (
colorFunc ColorizeFunc
ok bool
)
if colorFunc, ok = colorFuncMap[code]; ok {
return colorFunc
}
colorFunc = ColorizeFunc(ansi.ColorFunc(code))
colorFuncMap[code] = colorFunc
return colorFunc
}
示例12: Log
func Log(c *cli.Context) {
db := util.OpenDB()
defer db.Close()
yellow := ansi.ColorFunc("yellow+h:black")
// Perform operations in a read-only lock
db.View(func(tx *bolt.Tx) error {
info := tx.Bucket(util.INFO)
objects := tx.Bucket(util.OBJECTS)
headsBytes := info.Get(util.HEADS)
if headsBytes != nil {
queue := types.DeserializeHashes(headsBytes)
// TODO: Keep a visited set, so we don't repeat commits
for len(queue) > 0 {
i := GetNewestCommit(objects, queue)
// Get commit and remove it from the priority queue
commitSha := queue[i]
commit := types.DeserializeCommitObject(objects.Get(commitSha))
queue = append(queue[:i], queue[i+1:]...)
fmt.Printf(yellow("commit %s\n"), commitSha)
fmt.Printf("Message: %s\n", commit.Message)
fmt.Printf("Author: %s\n", commit.Author)
fmt.Printf("Date: %s\n", commit.Time)
if len(commit.Parents) > 0 {
fmt.Printf("Parents: %s\n", commit.Parents)
}
fmt.Printf("Tree: %s\n", commit.Tree)
fmt.Println()
// Append parents of this commit to the queue
queue = append(queue, commit.Parents...)
}
return nil
}
fmt.Println("There are no commits in this repository...")
return nil
})
}
示例13: init
func init() {
ansi.DisableColors(false)
cyan = ansi.ColorFunc("cyan")
red = ansi.ColorFunc("red+b")
yellow = ansi.ColorFunc("yellow+b")
redInverse = ansi.ColorFunc("white:red")
gray = ansi.ColorFunc("black+h")
magenta = ansi.ColorFunc("magenta+h")
writer = colorable.NewColorableStdout()
}
示例14: AssertEqual
func AssertEqual(tb testing.TB, exp, act interface{}) {
if !reflect.DeepEqual(exp, act) {
yellow := ansi.ColorFunc("yellow+h")
green := ansi.ColorCode("green+h:black")
red := ansi.ColorCode("red+h:black")
reset := ansi.ColorCode("reset")
_, file, line, _ := runtime.Caller(1)
fmt.Println(yellow(fmt.Sprintf("%s:%d", filepath.Base(file), line)))
fmt.Println(green, "Expected: ", exp, reset)
fmt.Println(red, " Got: ", act, reset)
tb.FailNow()
}
}
示例15: main
func main() {
reset := ansi.ColorCode("reset")
msg := ansi.Color("red+b", "red+b:white")
fmt.Println(msg, reset)
msg = ansi.Color("green", "green")
fmt.Println(msg, reset)
msg = ansi.Color("background white", "black:white")
fmt.Println(msg, reset)
warn := ansi.ColorFunc("yellow:black")
fmt.Println(warn("this is warning!"), reset)
lime := ansi.ColorCode("green+h:black")
fmt.Println(lime, "Lime message.", reset)
}