本文整理匯總了Golang中github.com/fatih/color.Color.SprintFunc方法的典型用法代碼示例。如果您正苦於以下問題:Golang Color.SprintFunc方法的具體用法?Golang Color.SprintFunc怎麽用?Golang Color.SprintFunc使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/fatih/color.Color
的用法示例。
在下文中一共展示了Color.SprintFunc方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Render
func Render(dst io.Writer, src eventstream.EventStream) int {
var buildConfig event.TaskConfig
exitStatus := 0
for {
ev, err := src.NextEvent()
if err != nil {
if err == io.EOF {
return exitStatus
} else {
fmt.Fprintf(dst, "failed to parse next event: %s\n", err)
return 255
}
}
switch e := ev.(type) {
case event.Log:
fmt.Fprintf(dst, "%s", e.Payload)
case event.InitializeTask:
buildConfig = e.TaskConfig
if buildConfig.Image != "" {
fmt.Fprintf(dst, "\x1b[1minitializing with %s\x1b[0m\n", buildConfig.Image)
} else {
fmt.Fprintf(dst, "\x1b[1minitializing\x1b[0m\n")
}
case event.StartTask:
argv := strings.Join(append([]string{buildConfig.Run.Path}, buildConfig.Run.Args...), " ")
fmt.Fprintf(dst, "\x1b[1mrunning %s\x1b[0m\n", argv)
case event.FinishTask:
exitStatus = e.ExitStatus
case event.Error:
errCol := ui.ErroredColor.SprintFunc()
fmt.Fprintf(dst, "%s\n", errCol(e.Message))
case event.Status:
var printColor *color.Color
switch e.Status {
case "started":
continue
case "succeeded":
printColor = ui.SucceededColor
case "failed":
printColor = ui.FailedColor
if exitStatus == 0 {
exitStatus = 1
}
case "errored":
printColor = ui.ErroredColor
if exitStatus == 0 {
exitStatus = 2
}
case "aborted":
printColor = ui.AbortedColor
if exitStatus == 0 {
exitStatus = 3
}
default:
fmt.Fprintf(dst, "unknown status: %s", e.Status)
return 255
}
printColorFunc := printColor.SprintFunc()
fmt.Fprintf(dst, "%s\n", printColorFunc(e.Status))
return exitStatus
}
}
return 255
}
示例2: newDesc
func newDesc(s string, c *color.Color) desc {
return desc{s, c.SprintFunc()}
}
示例3: getPrefix
// getPrefix generates the log prefix in the given color
func getPrefix(level string, color *color.Color) string {
currentTime := time.Now().Format("15:04:05")
toColoredString := color.SprintFunc()
return toColoredString(fmt.Sprintf("%s[%s] ", level, currentTime))
}