本文整理匯總了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,
)
}
示例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"))
}
示例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
}
示例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)
}
}
示例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)
}
示例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,
)
}
示例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")
}
示例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
}
示例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
}
示例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))
}
}
示例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)
}
示例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"]),
}, "")
}
示例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)
}
}
示例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"))
}
}
示例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"))
}
}