github.com/kcmerrill/alfred@v0.0.0-20180727171036-06445dcb5e3d/pkg/alfred/output.go (about) 1 package alfred 2 3 import ( 4 "fmt" 5 "time" 6 ) 7 8 func outOK(component, text string, context *Context) { 9 output("Success", component, text, context) 10 } 11 12 func outFail(component, text string, context *Context) { 13 output("Failure", component, text, context) 14 } 15 16 func outWarn(component, text string, context *Context) { 17 output("Warning", component, text, context) 18 } 19 20 func outArgs(component, text string, context *Context) { 21 output("Args", component, text, context) 22 } 23 24 func outPrefix(color, component, text string, context *Context) string { 25 date := "{{ .Text.Grey }}(" + time.Now().Format(time.RFC822) + "){{ .Text.Reset }}" 26 out := elapsed(context) + date + " [" + context.rootDir + "] {{ .Text.Task }}" + context.TaskName + "{{ .Text.Reset }} {{ .Text." + color + " }}" + component + " {{ .Text.Reset}}" + text + "{{ .Text.Reset }}" 27 return out 28 } 29 30 func output(color, component, text string, context *Context) { 31 if context.Text.DisableFormatting { 32 return 33 } 34 out := outPrefix(color, component, text, context) 35 t := translate(out, context) 36 37 fmt.Fprintln(context.Out, t) 38 } 39 40 func outputPrompt(color, component, text string, context *Context) { 41 out := outPrefix(color, component, text, context) 42 t := translate(out, context) 43 fmt.Fprintln(context.Out, t) 44 } 45 46 func cmdOK(text string, context *Context) { 47 outputCommand("Command", "command", text, context) 48 } 49 50 func cmdFail(text string, context *Context) { 51 outputCommand("Failure", "command", text, context) 52 } 53 54 func outputCommand(color, component, text string, context *Context) { 55 if !context.Text.DisableFormatting { 56 date := "{{ .Text.Grey }}(" + time.Now().Format(time.RFC822) + "){{ .Text.Reset }}" 57 out := elapsed(context) + date + " {{ .Text." + color + " }}" 58 t := translate(out, context) + text 59 fmt.Fprintln(context.Out, t) 60 } else { 61 fmt.Fprintln(context.Out, text) 62 } 63 64 logger(text, context) 65 } 66 67 func elapsed(context *Context) string { 68 return "{{ .Text.Grey }}[{{ .Text.Success }}" + padLeft(time.Since(context.Started).Round(time.Second).String(), 8, " ") + "{{ .Text.Grey }}] " 69 }