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


Golang ansi.Color函數代碼示例

本文整理匯總了Golang中github.com/mgutz/ansi.Color函數的典型用法代碼示例。如果您正苦於以下問題:Golang Color函數的具體用法?Golang Color怎麽用?Golang Color使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Color函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: PrintMissingEnv

// PrintMissingEnv ...
func PrintMissingEnv(name string, path string, err error) {
	if err != nil {
		errLine := ansi.Color(
			fmt.Sprintf(
				"%s",
				err,
			),
			"red",
		)

		fmt.Fprintln(
			os.Stderr,
			errLine,
		)
	}

	helpLine := ansi.Color(
		fmt.Sprintf(
			"missing %s in %s",
			name,
			path,
		),
		"yellow",
	)

	fmt.Fprintln(
		os.Stderr,
		helpLine,
	)
}
開發者ID:johnmcconnell,項目名稱:chenv,代碼行數:31,代碼來源:chenv.go

示例2: main

func main() {

	log.Fatalln("@todo refactor")

	if err := checkEnv(); err != nil {
		log.Fatal(err)
	}

	for _, cmd := range getCommands() {
		out, err := exec.Command(cmd.name, cmd.args...).CombinedOutput()
		if cmd.rm {
			defer os.Remove(cmd.name)
		}
		args := strings.Join(cmd.args, " ")
		if err != nil {
			log.Fatalf(ansi.Color("Failed:\n%s %s => %s\n%s", "red"), cmd.name, args, err, out)
		}

		log.Printf("%s %s", cmd.name, args)
		if nil != out && len(out) > 0 {
			log.Printf("%s", out)
		}
	}
	log.Println(ansi.Color("Done", "green"))
}
開發者ID:levcom,項目名稱:csfw,代碼行數:25,代碼來源:main.go

示例3: newFileRecord

func newFileRecord(path string) *FileRecord {
	fr := FileRecord{}
	fr.input.path = path

	fr.debug = log.New(ioutil.Discard, "@@ ", 0)
	fr.info = log.New(&fr.logBuf, ":: ", 0)
	fr.plain = log.New(&fr.logBuf, "", 0)
	fr.section = log.New(&fr.logBuf, "==> ", 0)
	fr.warning = log.New(&fr.logBuf, ":: Warning: ", 0)
	fr.error = log.New(&fr.logBuf, ":: Error: ", 0)

	if options.Debug {
		fr.debug.SetOutput(&fr.logBuf)
	}

	if options.Color {
		fr.debug.SetPrefix(ansi.Color(fr.debug.Prefix(), "cyan+b"))
		fr.info.SetPrefix(ansi.Color(fr.info.Prefix(), "magenta+b"))
		fr.section.SetPrefix(ansi.Color(fr.section.Prefix(), "green+b"))
		fr.warning.SetPrefix(ansi.Color(fr.warning.Prefix(), "yellow+b"))
		fr.error.SetPrefix(ansi.Color(fr.error.Prefix(), "red+b"))
	}

	return &fr
}
開發者ID:Ambrevar,項目名稱:Demlo,代碼行數:25,代碼來源:demlo.go

示例4: prettyPrint

// The format is:
//   [input] | attr | [output]
func prettyPrint(fr *FileRecord, attr, input, output string, attrMaxlen, valueMaxlen int) {
	colorIn := ""
	colorOut := ""
	if options.Color && input != output &&
		(attr != "parameters" || output != "[-c:a copy]") &&
		((attr != "embedded" && attr != "external") || (len(output) >= 3 && output[len(output)-3:] != " ''")) {
		colorIn = "red"
		colorOut = "green"
	}

	// Replace control characters to avoid mangling the output.
	input = rePrintable.ReplaceAllString(input, " / ")
	output = rePrintable.ReplaceAllString(output, " / ")

	in := []rune(input)
	out := []rune(output)

	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}

	// Print first line with title.
	fr.plain.Printf(
		"%*v["+ansi.Color("%.*s", colorIn)+"] | %-*v | ["+ansi.Color("%.*s", colorOut)+"]\n",
		valueMaxlen-min(valueMaxlen, len(in)), "",
		valueMaxlen, input,
		attrMaxlen, attr,
		valueMaxlen, output)

	// Print the rest that does not fit on first line.
	for i := valueMaxlen; i < len(in) || i < len(out); i += valueMaxlen {
		inLo := min(i, len(in))
		inHi := min(i+valueMaxlen, len(in))
		outLo := min(i, len(out))
		outHi := min(i+valueMaxlen, len(out))

		inDelimLeft, inDelimRight := "[", "]"
		outDelimLeft, outDelimRight := "[", "]"
		if i >= len(in) {
			inDelimLeft, inDelimRight = " ", " "
		}
		if i >= len(out) {
			outDelimLeft, outDelimRight = "", ""
		}

		fr.plain.Printf(
			"%s"+ansi.Color("%s", colorIn)+"%s%*v | %*v | %s"+ansi.Color("%s", colorOut)+"%s\n",
			inDelimLeft,
			string(in[inLo:inHi]),
			inDelimRight,
			valueMaxlen-inHi+inLo, "",
			attrMaxlen, "",
			outDelimLeft,
			string(out[outLo:outHi]),
			outDelimRight)
	}
}
開發者ID:Ambrevar,項目名稱:Demlo,代碼行數:62,代碼來源:analyzer.go

示例5: StartInstance

func (node Node) StartInstance(instance Instance) {
	stolen := node.hesitate(instance)
	if stolen {
		fmt.Println(ansi.Color("yoinked", "yellow"), instance.Index)
		return
	}

	ok := node.volunteer(instance)
	if !ok {
		fmt.Println(ansi.Color("dropped", "red"), instance.Index)
		return
	}

	fmt.Println(ansi.Color("started", "green"), instance.Index)

	// make 25% of them crash after a random amount of time
	//
	// because that's more interesting
	if rand.Intn(4) == 0 {
		instance.MarkedForDeath = true

		go func() {
			time.Sleep(time.Duration(5+rand.Intn(10)) * time.Second)
			node.StopInstance(instance)
		}()
	}

	node.registry.Register(instance)
}
開發者ID:vito,項目名稱:executor-pool-spike,代碼行數:29,代碼來源:node.go

示例6: PrintMissingCurrentEnv

// PrintMissingCurrentEnv ...
func PrintMissingCurrentEnv(err error) {
	if err != nil {
		errLine := ansi.Color(
			fmt.Sprintf(
				"%s",
				err,
			),
			"red",
		)

		fmt.Fprintln(
			os.Stderr,
			errLine,
		)
	}

	helpLine := ansi.Color(
		fmt.Sprintf(
			"%s",
			"did you create a .env?",
		),
		"yellow",
	)

	fmt.Fprintln(
		os.Stderr,
		helpLine,
	)
}
開發者ID:johnmcconnell,項目名稱:chenv,代碼行數:30,代碼來源:chenv.go

示例7: colorizeMessage

func colorizeMessage(color, prefix, message string, args ...interface{}) string {
	prefResult := ""
	if prefix != "" {
		prefResult = ansi.Color(prefix, color+"+b") + " " + ansi.ColorCode("reset")
	}
	return prefResult + ansi.Color(fmt.Sprintf(message, args...), color) + ansi.ColorCode("reset")
}
開發者ID:knobnot,項目名稱:hk,代碼行數:7,代碼來源:util.go

示例8: colorStatus

func colorStatus(word string) string {
	if word == "running" {
		return ansi.Color("running", "green+b")
	} else if word == "stopped" {
		return ansi.Color("stopped", "red+b")
	}
	return word
}
開發者ID:Meabed,項目名稱:aws-ssh-bastion,代碼行數:8,代碼來源:aws.go

示例9: GetLineForPercent

func (self *ProgressBar) GetLineForPercent(i int, displayPercent float64) string {
	line := ansi.Color("[", self.BackgroundColor)
	line += ansi.Color(strings.Repeat(self.FillShape, i), self.FillColor)
	line += ansi.Color(strings.Repeat(self.EmptyShape, self.Width-i), self.BackgroundColor)
	line += ansi.Color("] ", self.BackgroundColor) + strings.Replace(fmt.Sprintf("%.01f", displayPercent), ".0", "", -1)
	line += "%% "
	return line
}
開發者ID:ccampbell,項目名稱:clapp,代碼行數:8,代碼來源:progressbar.go

示例10: TestColorize

func TestColorize(t *testing.T) {
	for i := 0; i < 256; i++ {
		f := fmt.Sprintf("%d:default", i)
		b := fmt.Sprintf("default:%d", i)
		fmt.Println(ansi.Color(f, f), ansi.Color(b, b))
	}

}
開發者ID:jaisingh,項目名稱:colorize,代碼行數:8,代碼來源:colorize_test.go

示例11: Colorize

func (s *Sapin) Colorize() {
	s.compute()

	s.output = strings.Replace(s.output, "@", ansi.Color("@", fmt.Sprintf("red+%s", s.ColorOpts)), -1)
	s.output = strings.Replace(s.output, "*", ansi.Color("*", fmt.Sprintf("green+%s", s.ColorOpts)), -1)
	s.output = strings.Replace(s.output, "|", ansi.Color("|", fmt.Sprintf("90+%s", s.ColorOpts)), -1)
	s.output = strings.Replace(s.output, "#", ansi.Color("#", fmt.Sprintf("yellow+%s", s.ColorOpts)), -1)
	s.output = strings.Replace(s.output, "~", ansi.Color("~", fmt.Sprintf("yellow+%s", s.ColorOpts)), -1)
}
開發者ID:johnsmithcraven,項目名稱:go-sapin,代碼行數:9,代碼來源:bonus.go

示例12: Init

func Init() {
	debugFormat = strings.Join([]string{
		ansi.Color("[", Styles["debugPunct"]),
		ansi.Color("%v", Styles["debugInfo"]),
		ansi.Color(":", Styles["debugPunct"]),
		ansi.Color("%v", Styles["debugInfo"]),
		ansi.Color("]", Styles["debugPunct"]),
	}, "")
}
開發者ID:saper,項目名稱:jetpack,代碼行數:9,代碼來源:ui.go

示例13: isProcessOK

func isProcessOK(err error) {
	var msg string

	if err != nil {
		msg = ansi.Color("     [FAIL]", "red+b")
		fmt.Println(msg)
	} else {
		msg = ansi.Color("     [OK]", "green+b")
		fmt.Println(msg)
	}
}
開發者ID:soarpenguin,項目名稱:go-scripts,代碼行數:11,代碼來源:rm_end_space.go

示例14: uiFormat

func uiFormat(color, kind, id string) string {
	if id == "" {
		return fmt.Sprintf("%v %v %%v",
			ansi.Color("%v", Styles["timestamp"]),
			ansi.Color(kind, color))
	} else {
		return fmt.Sprintf("%v %v%v %%v",
			ansi.Color("%v", Styles["timestamp"]),
			ansi.Color(kind+":", color),
			ansi.Color(id, color+"+h"))
	}
}
開發者ID:saper,項目名稱:jetpack,代碼行數:12,代碼來源:ui.go

示例15: buildTestingTGomegaFailHandler

func buildTestingTGomegaFailHandler(t testingT) types.GomegaFailHandler {
	return func(message string, callerSkip ...int) {
		skip := 2 // initial runtime/debug.Stack frame + gomega-matchers.buildTestingTGomegaFailHandler frame
		if len(callerSkip) > 0 {
			skip += callerSkip[0]
		}
		stackTrace := pruneStack(string(debug.Stack()), skip)
		stackTrace = strings.TrimSpace(stackTrace)
		stackTrace = ansi.Color(stackTrace, StacktraceColor)

		t.Errorf("\n%s\n%s", stackTrace, ansi.Color(message, "red"))
	}
}
開發者ID:fgrosse,項目名稱:gomega-matchers,代碼行數:13,代碼來源:testing_t_support.go


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