本文整理匯總了Golang中github.com/fatih/color.Color類的典型用法代碼示例。如果您正苦於以下問題:Golang Color類的具體用法?Golang Color怎麽用?Golang Color使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Color類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: sprintfColor
func (f *Formatter) sprintfColor(c *color.Color, format string, args ...interface{}) string {
if f.DisabledColor || c == nil {
return fmt.Sprintf(format, args...)
} else {
return c.SprintfFunc()(format, args...)
}
}
示例2: write
// returns a function that will format and writes the line extracted from the logs of a given container
func write(prefix string, color *ansi.Color, timestamps bool) func(dest io.Writer, token []byte) (n int, err error) {
return func(dest io.Writer, token []byte) (n int, err error) {
countingWriter := countingWriter{Writer: dest}
if color != nil {
ansi.Output = &countingWriter
color.Set()
}
_, err = countingWriter.Write([]byte(prefix))
if err == nil {
if !timestamps {
// timestamps are always present in the incoming stream for
// sorting purposes, so we strip them if the user didn't ask
// for them
const timestampPrefixLength = 31
strip := timestampPrefixLength
if string(token[0]) == "[" {
// it seems that timestamps are wrapped in [] for events
// streamed in real time during a `docker logs -f`
strip = strip + 2
}
token = token[strip:]
}
_, err = countingWriter.Write(token)
}
if err == nil {
if color != nil {
ansi.Unset()
}
_, err = dest.Write([]byte("\n"))
}
return countingWriter.written, err
}
}
示例3: Print
// Print the codeword contents and type to terminal. For debugging.
func (c *Codeword) Print() {
payload := ""
var color *color.Color = blue
switch c.Type {
case CodewordTypeAddress:
payload = c.Adress()
color = red
case CodewordTypeMessage:
payload = ""
color = green
default:
color = blue
}
parity := utils.TernaryStr(c.ValidParity, "", "*")
color.Printf("%s %s %s ", c.Type, payload, parity)
corr := c.BitCorrections
if corr > 0 {
color.Printf("%d bits corrected", corr)
}
println("")
}
示例4: format
func (l *Log) format(timestamp bool, level int, format string, args []interface{}) string {
ts := ""
if timestamp {
f := l.Palette.Timestamp.SprintfFunc()
ts = f(
"%s", time.Now().Format(l.TimeFmt),
)
}
var p *color.Color
switch level {
case say:
p = l.Palette.Say
case notice:
p = l.Palette.Notice
case warn:
p = l.Palette.Warn
case shout:
p = l.Palette.Shout
case header:
p = l.Palette.Header
default:
panic("unknown log level")
}
return ts + p.SprintfFunc()(format, args...)
}
示例5: printDatagram
func printDatagram(out *color.Color, d *protocol.Datagram) {
re := regexp.MustCompilePOSIX("^00000")
out.Printf("FROM: %s\n", d.From)
out.Printf("SIZE: %d\n", len(d.Data))
data := strings.TrimLeft(hex.Dump(d.Data), "0")
out.Printf("DATA: 000" + re.ReplaceAllString(data, " "))
color.Set(color.Bold)
}
示例6: ResumeHistogram
func (s *RangeHistogram) ResumeHistogram(out *color.Color) {
out.Printf("\n %s:", s.name_)
sortedHisto := make([]int, len(s.data_))
minKey := 999999999
maxKey := 0
for key, _ := range s.data_ {
if key < minKey {
minKey = key
}
if key > maxKey {
maxKey = key
}
}
for key, val := range s.data_ {
sortedHisto[key-minKey] = val
}
for k, v := range sortedHisto {
out.Printf("\n [%d]: %d", k, v)
}
}
示例7: printf
func (b *Buntstift) printf(Color *color.Color, format string, a ...interface{}) (n int, err error) {
Color.Set()
defer b.unsetColor()
return fmt.Fprintf(Output, format, a...)
}
示例8: boldLine
// Print a thick line break (of '=' characters).
func boldLine(c *color.Color) {
c.Set()
defer colorUnset()
lineBreak("=")
}
示例9: line
// Print a thin line break (of '-' characters).
func line(c *color.Color) {
c.Set()
defer colorUnset()
lineBreak("-")
}
示例10: 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
}
示例11: Resume
func (s *ScalarStatistic) Resume(out *color.Color) {
out.Printf("\n %s: %d", s.name_, s.total_)
}
示例12: ResumeRangeAv
func (s *RangeStatistic) ResumeRangeAv(out *color.Color) {
out.Printf("\n %s: min=%d, max=%d av=%f", s.name_, s.min_, s.max_, float64(s.total_)/float64(s.count_))
}
示例13: ResumeRange
func (s *RangeStatistic) ResumeRange(out *color.Color) {
out.Printf("\n %s: min=%d, max=%d", s.name_, s.min_, s.max_)
}
示例14: ResumeAv
func (s *ScalarStatistic) ResumeAv(out *color.Color) {
out.Printf("\n %s av: %f", s.name_, float64(s.total_)/float64(s.count_))
}
示例15: consolePrintln
// consolePrintln - same as print with a new line.
func consolePrintln(tag string, c *color.Color, a ...interface{}) {
privateMutex.Lock()
defer privateMutex.Unlock()
switch tag {
case "Debug":
output := color.Output
color.Output = stderrColoredOutput
if isatty.IsTerminal(os.Stderr.Fd()) {
c.Print(ProgramName() + ": <DEBUG> ")
c.Println(a...)
} else {
fmt.Fprint(color.Output, ProgramName()+": <DEBUG> ")
fmt.Fprintln(color.Output, a...)
}
color.Output = output
case "Fatal":
fallthrough
case "Error":
output := color.Output
color.Output = stderrColoredOutput
if isatty.IsTerminal(os.Stderr.Fd()) {
c.Print(ProgramName() + ": <ERROR> ")
c.Println(a...)
} else {
fmt.Fprint(color.Output, ProgramName()+": <ERROR> ")
fmt.Fprintln(color.Output, a...)
}
color.Output = output
case "Info":
if isatty.IsTerminal(os.Stdout.Fd()) {
c.Print(ProgramName() + ": ")
c.Println(a...)
} else {
fmt.Fprint(color.Output, ProgramName()+": ")
fmt.Fprintln(color.Output, a...)
}
default:
if isatty.IsTerminal(os.Stdout.Fd()) {
c.Println(a...)
} else {
fmt.Fprintln(color.Output, a...)
}
}
}