dnote/log/log.go
Sung Won Cho 86d75466ca
Improve text output and error messages (#75)
* Fix newline

* Allow to specify default for confirmation

* Improve error handling

* Include more options and default to vi

* 0.2.1

* Improve error output
2018-02-17 11:48:09 +11:00

57 lines
1.5 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package log
import (
"fmt"
"github.com/fatih/color"
)
var (
SprintfRed = color.New(color.FgRed).SprintfFunc()
SprintfGreen = color.New(color.FgGreen).SprintfFunc()
SprintfYellow = color.New(color.FgYellow).SprintfFunc()
SprintfBlue = color.New(color.FgBlue).SprintfFunc()
SprintfGray = color.New(color.FgWhite).SprintfFunc()
)
var indent = " "
func Info(msg string) {
fmt.Fprintf(color.Output, "%s%s %s", indent, SprintfBlue("•"), msg)
}
func Infof(msg string, v ...interface{}) {
fmt.Fprintf(color.Output, "%s%s %s", indent, SprintfBlue("•"), fmt.Sprintf(msg, v...))
}
func Success(msg string) {
fmt.Fprintf(color.Output, "%s%s %s", indent, SprintfGreen("✔"), msg)
}
func Successf(msg string, v ...interface{}) {
fmt.Fprintf(color.Output, "%s%s %s", indent, SprintfGreen("✔"), fmt.Sprintf(msg, v...))
}
func Plain(msg string) {
fmt.Printf("%s%s", indent, msg)
}
func Plainf(msg string, v ...interface{}) {
fmt.Fprintf(color.Output, "%s%s", indent, fmt.Sprintf(msg, v...))
}
func Warnf(msg string, v ...interface{}) {
fmt.Fprintf(color.Output, "%s%s %s", indent, SprintfRed("•"), fmt.Sprintf(msg, v...))
}
func Error(msg string) {
fmt.Fprintf(color.Output, "%s%s %s", indent, SprintfRed(""), msg)
}
func Errorf(msg string, v ...interface{}) {
fmt.Fprintf(color.Output, "%s%s %s", indent, SprintfRed(""), fmt.Sprintf(msg, v...))
}
func Printf(msg string, v ...interface{}) {
fmt.Fprintf(color.Output, "%s%s %s", indent, SprintfGray("•"), fmt.Sprintf(msg, v...))
}