本文整理汇总了Golang中github.com/agtorre/gocolorize.NewColor函数的典型用法代码示例。如果您正苦于以下问题:Golang NewColor函数的具体用法?Golang NewColor怎么用?Golang NewColor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewColor函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
//Revel Example
//first set some color information
info := gocolorize.NewColor("green")
warning := gocolorize.NewColor("yellow")
critical := gocolorize.NewColor("black+u:red")
//We could also do this
//critical.ToggleUnderline()
//helper functions to shorten code
i := info.Paint
w := warning.Paint
c := critical.Paint
//Define the look/feel of the INFO logger
INFO = log.New(os.Stdout, i("INFO "), log.Ldate|log.Lmicroseconds|log.Lshortfile)
WARNING = log.New(os.Stdout, w("WARNING "), log.Ldate|log.Lmicroseconds|log.Lshortfile)
CRITICAL = log.New(os.Stdout, c("CRITICAL")+" ", log.Ldate|log.Lmicroseconds|log.Lshortfile)
//print out some messages, note the i wrappers for yellow text on the actual info string
INFO.Println(i("Loaded module x"))
INFO.Println(i("Loaded module y"))
WARNING.Println(w("Failed to load module z"))
e := MyError{What: "Failed"}
CRITICAL.Println(c("Failed with an error code:", e))
}
开发者ID:LeVuVanThinh,项目名称:waiterbot,代码行数:31,代码来源:logging.go
示例2: getColorByte
func (l *loggingT) getColorByte(s severity, b []byte) []byte {
var c gocolorize.Colorize
switch s {
case warningLog:
c = gocolorize.NewColor("yellow")
case errorLog:
c = gocolorize.NewColor("red")
case fatalLog:
c = gocolorize.NewColor("magenta")
default:
c = gocolorize.NewColor("green")
}
return []byte(c.Paint(string(b)))
}
开发者ID:rshmelev,项目名称:glog,代码行数:14,代码来源:glog.go
示例3: showDiff
func showDiff(oldText, newText string) {
dmp := diffmatchpatch.New()
diffs := dmp.DiffMain(oldText, newText, true)
for _, diff := range diffs {
switch diff.Type {
case diffmatchpatch.DiffInsert:
color := gocolorize.NewColor("green")
printLinesWithPrefix(color.Paint("+"), diff.Text)
case diffmatchpatch.DiffDelete:
color := gocolorize.NewColor("red")
printLinesWithPrefix(color.Paint("-"), diff.Text)
}
}
}
开发者ID:k0kubun,项目名称:changelogger,代码行数:15,代码来源:diff.go
示例4: main
func main() {
loggers.IsDebug = os.Getenv("GBW_DEBUG") == "1"
fmt.Println(gocolorize.NewColor("magenta").Paint("gobuildweb > Build a Golang web application.\n"))
cmds := map[string]Command{
"run": commandRun,
"dist": commandDist,
}
flag.Parse()
args := flag.Args()
if len(args) == 0 {
usage()
}
if cmd, ok := cmds[args[0]]; !ok {
usage()
} else {
if fi, err := os.Stat("project.toml"); os.IsNotExist(err) {
loggers.ERROR.Fatalf("Please provide a project.toml for web project.")
} else if err != nil {
loggers.ERROR.Fatalf("Accessing project.toml file error, %v.", err)
} else if fi.IsDir() {
loggers.ERROR.Fatalf("project.toml cannot be a directory.")
}
if _, err := toml.DecodeFile("project.toml", &rootConfig); err != nil {
loggers.ERROR.Fatalf("Cannot decode the project.toml into TOML format, %v", err)
}
loggers.SUCC.Printf("Loaded project.toml... %s", rootConfig.Package.Name)
if err := cmd(args[1:]); err != nil {
loggers.ERROR.Fatalf("Executing command [%v] error, %v", args[0], err)
}
}
}
开发者ID:JeekyYang,项目名称:gobuildweb,代码行数:33,代码来源:main.go
示例5: Parse
func Parse() {
if runtime.GOOS == "windows" {
gocolorize.SetPlain(true)
}
var err = gcfg.ReadFileInto(&AppCfg, "App.cfg")
if err != nil {
errorf("Missing App.cfg")
os.Exit(1)
}
fmt.Fprintf(os.Stdout, gocolorize.NewColor("Blue").Paint(AppCfg.App.Header))
flag.Usage = func() { usage(1) }
flag.Parse()
args := flag.Args()
if len(args) < 1 || args[0] == "help" {
if len(args) == 1 {
usage(0)
}
if len(args) > 1 {
for _, cmd := range commands {
if cmd.Name() == args[1] {
tmpl(os.Stdout, AppCfg.Template.helpTemplate, cmd)
return
}
}
}
usage(2)
}
// Commands use panic to abort execution when something goes wrong.
// Panics are logged at the point of error. Ignore those.
defer func() {
if err := recover(); err != nil {
if _, ok := err.(LoggedError); !ok {
// This panic was not expecred/logged.
panic(err)
}
os.Exit(1)
}
}()
for _, cmd := range commands {
if cmd.Name() == args[0] {
cmd.Run(args[1:])
return
}
}
errorf("Unknown command.\n Run '%q help' for usage", args[0])
}
开发者ID:zypeh,项目名称:docflag,代码行数:52,代码来源:docflag.go
示例6: main
func main() {
// one way to define a stateful colorizer
var green gocolorize.Colorize
green.SetColor(gocolorize.Green)
g := green.Paint
// Another way to do it
red := gocolorize.Colorize{Fg: gocolorize.Red}
r := red.Paint
// now with string construction
green_black := gocolorize.Colorize{Fg: gocolorize.Blue}
// toggle attributes
green_black.ToggleUnderline()
b := green_black.Paint
//all in 1 line
c := gocolorize.NewColor("yellow:black").Paint
//r := gocolorize.COLOR_RED
fmt.Println(b("On the twelfth day of Christmas"))
fmt.Println(b("my true love sent to me:"))
fmt.Println(g("Twelve"), c("Drummers"), r("Drumming"))
fmt.Println(g("Eleven"), c("Pipers"), r("Piping"))
fmt.Println(g("Ten"), c("Lords"), r("a Leaping"))
fmt.Println(g("Nine"), c("Ladies"), r("Dancing"))
fmt.Println(g("Eight"), c("Maids"), r("a Milking"))
fmt.Println(g("Seven"), c("Swans"), r("a Swimming"))
fmt.Println(g("Six"), c("Geese"), r("a Laying"))
fmt.Println(g("Five"), c("Golden"), r("Rings"))
fmt.Println(g("Four"), c("Calling"), r("Birds"))
fmt.Println(g("Three"), c("French"), r("Hens"))
fmt.Println(g("Two"), c("Turtle"), r("Doves"))
fmt.Println(b("and a Partridge in a Pear Tree"))
}
开发者ID:pondyond,项目名称:leanote-all,代码行数:37,代码来源:song.go
示例7:
HttpSslKey string // e.g. "/path/to/key.pem"
// All cookies dropped by the framework begin with this prefix.
CookiePrefix string
// Cookie domain
CookieDomain string
// Cookie flags
CookieHttpOnly bool
CookieSecure bool
// Delimiters to use when rendering templates
TemplateDelims string
//Logger colors
colors = map[string]gocolorize.Colorize{
"trace": gocolorize.NewColor("magenta"),
"info": gocolorize.NewColor("green"),
"warn": gocolorize.NewColor("yellow"),
"error": gocolorize.NewColor("red"),
}
error_log = revelLogs{c: colors["error"], w: os.Stderr}
// Loggers
TRACE = log.New(ioutil.Discard, "TRACE ", log.Ldate|log.Ltime|log.Lshortfile)
INFO = log.New(ioutil.Discard, "INFO ", log.Ldate|log.Ltime|log.Lshortfile)
WARN = log.New(ioutil.Discard, "WARN ", log.Ldate|log.Ltime|log.Lshortfile)
ERROR = log.New(&error_log, "ERROR ", log.Ldate|log.Ltime|log.Lshortfile)
Initialized bool
开发者ID:jemkzheng,项目名称:revel,代码行数:30,代码来源:revel.go
示例8: init
Long: `sync checks the GOPATH for consistency with the given package's GLOCKFILE
For example:
glock sync github.com/robfig/glock
It verifies that each entry in the GLOCKFILE is at the expected revision.
If a dependency is not at the expected revision, it is re-downloaded and synced.
Commands are built if necessary.
`,
}
var (
color = flag.Bool("color", true, "if true, colorize terminal output")
info = gocolorize.NewColor("green").Paint
warning = gocolorize.NewColor("yellow").Paint
critical = gocolorize.NewColor("red").Paint
disabled = func(args ...interface{}) string { return fmt.Sprint(args...) }
)
func init() {
cmdSync.Run = runSync // break init loop
}
func runSync(cmd *Command, args []string) {
if len(args) == 0 {
cmdSync.Usage()
return
}
开发者ID:joeshaw,项目名称:glock,代码行数:31,代码来源:sync.go
示例9: init
func init() {
INFO = log.New(os.Stdout, "(gbw) [INFO] ", 0)
SUCC = log.New(&ColoredLogger{gocolorize.NewColor("green"), os.Stdout}, "(gbw) [SUCC] ", 0)
WARN = log.New(&ColoredLogger{gocolorize.NewColor("yellow"), os.Stdout}, "(gbw) [WARN] ", 0)
ERROR = log.New(&ColoredLogger{gocolorize.NewColor("red"), os.Stdout}, "(gbw) [ERROR] ", 0)
}
开发者ID:JeekyYang,项目名称:gobuildweb,代码行数:6,代码来源:logger.go
示例10: Init
package cli
import (
"fmt"
"github.com/agtorre/gocolorize"
"github.com/kr/beanstalk"
)
var TitleStyle = gocolorize.NewColor("green")
var InfoStyle = gocolorize.NewColor("yellow")
type Command struct {
Host string `short:"h" long:"host" description:"beanstalkd host addr." required:"true" default:"localhost:11300"`
conn *beanstalk.Conn
}
func (c *Command) Init() error {
var err error
c.conn, err = beanstalk.Dial("tcp", c.Host)
if err != nil {
return err
}
return nil
}
func (c *Command) PrintJob(id uint64, body []byte) error {
s, err := c.conn.StatsJob(id)
if err != nil {
开发者ID:sunyuantao,项目名称:beanstool,代码行数:31,代码来源:command.go
示例11: GetLevelColorMsg
package wlog
import (
"fmt"
"github.com/agtorre/gocolorize"
"github.com/mabetle/mcore/mterm"
)
var (
trace = gocolorize.NewColor("magenta")
debug = gocolorize.NewColor("cyan")
info = gocolorize.NewColor("green")
warn = gocolorize.NewColor("yellow")
err = gocolorize.NewColor("red")
//helper functions to longen code
d = debug.Paint
i = info.Paint
w = warn.Paint
e = err.Paint
t = trace.Paint
)
func GetLevelColorMsg(level string, v ...interface{}) string {
// default no color.
msg := fmt.Sprint(v...)
levelLevel := GetStringLevel(level)
// xterm can show color.
if mterm.IsXterm() {
switch levelLevel {
开发者ID:mabetle,项目名称:mlog,代码行数:31,代码来源:level_color_msg.go
示例12: Execute
"fmt"
"strconv"
"strings"
"github.com/agtorre/gocolorize"
"github.com/mcuadros/termtable"
)
const (
HighSeverity = iota
NormalSeverity
LowSeverity
)
var TubeStatsRetrievalError = errors.New("Unable to retrieve tube stats")
var HighSeverityStyle = gocolorize.NewColor("white:red")
var NormalSeverityStyle = gocolorize.NewColor("green")
type StatsCommand struct {
Tubes string `short:"t" long:"tubes" description:"tubes to be listed (separated by ,). By default all are listed"`
Command
}
func (c *StatsCommand) Execute(args []string) error {
if err := c.Init(); err != nil {
return err
}
if err := c.PrintStats(); err != nil {
return err
开发者ID:pmatseykanets,项目名称:beanstool,代码行数:31,代码来源:stats.go
注:本文中的github.com/agtorre/gocolorize.NewColor函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论