當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Color.SprintFunc方法代碼示例

本文整理匯總了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
}
開發者ID:aemengo,項目名稱:fly,代碼行數:80,代碼來源:render.go

示例2: newDesc

func newDesc(s string, c *color.Color) desc {
	return desc{s, c.SprintFunc()}
}
開發者ID:klaidliadon,項目名稱:console,代碼行數:3,代碼來源:config.go

示例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))
}
開發者ID:uber,項目名稱:go-torch,代碼行數:6,代碼來源:torchlog.go


注:本文中的github.com/fatih/color.Color.SprintFunc方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。