本文整理汇总了Golang中github.com/fatih/color.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: init
func init() {
// Initialize default loggers.
Error = log.New(
&context{
c: color.New(color.FgRed, color.Bold),
w: os.Stderr,
}, "", 0,
)
Warn = log.New(
&context{
c: color.New(color.FgYellow),
w: os.Stderr,
}, "", 0,
)
Info = log.New(
&context{
c: color.New(color.FgGreen),
w: os.Stdout,
}, "", 0,
)
Trace = log.New(
&context{
c: color.New(color.FgCyan),
w: os.Stdout,
}, "", 0,
)
}
开发者ID:gocore,项目名称:goal,代码行数:27,代码来源:log.go
示例2: mainList
// mainList - is a handler for mc ls command
func mainList(ctx *cli.Context) {
checkListSyntax(ctx)
args := ctx.Args()
// Operating system tool behavior
if globalMimicFlag && !ctx.Args().Present() {
args = []string{"."}
}
console.SetCustomTheme(map[string]*color.Color{
"File": color.New(color.FgWhite),
"Dir": color.New(color.FgCyan, color.Bold),
"Size": color.New(color.FgYellow),
"Time": color.New(color.FgGreen),
})
config := mustGetMcConfig()
for _, arg := range args {
targetURL, err := getCanonicalizedURL(arg, config.Aliases)
fatalIf(err.Trace(arg), "Unable to parse argument ‘"+arg+"’.")
// if recursive strip off the "..."
err = doListCmd(stripRecursiveURL(targetURL), isURLRecursive(targetURL))
fatalIf(err.Trace(targetURL), "Unable to list target ‘"+targetURL+"’.")
}
}
开发者ID:axcoto-lab,项目名称:mc,代码行数:27,代码来源:ls-main.go
示例3: runTestsViaRunner
// runTestsViaRunner runs all the tests at the given source path via the runner.
func runTestsViaRunner(runner TestRunner, path string) bool {
log.Printf("Starting test run of %s via %v runner", path, runner.Title())
// Run setup for the runner.
err := runner.SetupIfNecessary()
if err != nil {
errHighlight := color.New(color.FgRed, color.Bold)
errHighlight.Print("ERROR: ")
text := color.New(color.FgWhite)
text.Printf("Could not setup %s runner: %v\n", runner.Title(), err)
return false
}
// Iterate over each test file in the source path. For each, compile the code into
// JS at a temporary location and then pass the temporary location to the test
// runner.
return compilerutil.WalkSourcePath(path, func(currentPath string, info os.FileInfo) (bool, error) {
if !strings.HasSuffix(info.Name(), "_test"+parser.SERULIAN_FILE_EXTENSION) {
return false, nil
}
success, err := buildAndRunTests(currentPath, runner)
if err != nil {
return true, err
}
if success {
return true, nil
} else {
return true, fmt.Errorf("Failure in test of file %s", currentPath)
}
})
}
开发者ID:Serulian,项目名称:compiler,代码行数:35,代码来源:runner.go
示例4: PrintUnassignedWarning
func PrintUnassignedWarning(writer io.Writer, commits []*git.Commit) (n int64, err error) {
var output bytes.Buffer
// Let's be colorful!
redBold := color.New(color.FgRed).Add(color.Bold).SprintFunc()
fmt.Fprint(&output,
redBold("Warning: There are some commits missing the Story-Id tag.\n"))
red := color.New(color.FgRed).SprintFunc()
fmt.Fprint(&output,
red("Make sure that this is alright before proceeding further.\n\n"))
hashRe := regexp.MustCompile("^[0-9a-f]{40}$")
yellow := color.New(color.FgYellow).SprintFunc()
for _, commit := range commits {
var (
sha = commit.SHA
source = commit.Source
title = prompt.ShortenCommitTitle(commit.MessageTitle)
)
if hashRe.MatchString(commit.Source) {
source = "unknown commit source branch"
}
fmt.Fprintf(&output, " %v | %v | %v\n", yellow(sha), yellow(source), title)
}
// Write the output to the writer.
return io.Copy(ansicolor.NewAnsiColorWriter(writer), &output)
}
开发者ID:salsaflow,项目名称:salsaflow,代码行数:32,代码来源:unassigned_warning.go
示例5: mainConfig
// mainConfig is the handle for "mc config" sub-command. writes configuration data in json format to config file.
func mainConfig(ctx *cli.Context) {
checkConfigSyntax(ctx)
// set new custom coloring
console.SetCustomTheme(map[string]*color.Color{
"Alias": color.New(color.FgCyan, color.Bold),
"AliasMessage": color.New(color.FgGreen, color.Bold),
"URL": color.New(color.FgWhite),
})
arg := ctx.Args().First()
tailArgs := ctx.Args().Tail()
switch strings.TrimSpace(arg) {
case "add":
if strings.TrimSpace(tailArgs.First()) == "alias" {
addAlias(tailArgs.Get(1), tailArgs.Get(2))
}
case "remove":
if strings.TrimSpace(tailArgs.First()) == "alias" {
removeAlias(tailArgs.Get(1))
}
case "list":
if strings.TrimSpace(tailArgs.First()) == "alias" {
listAliases()
}
}
}
开发者ID:axcoto-lab,项目名称:mc,代码行数:29,代码来源:config-main.go
示例6: GenerateSummary
func (this *Wigo) GenerateSummary(showOnlyErrors bool) (summary string) {
red := color.New(color.FgRed).SprintfFunc()
yellow := color.New(color.FgYellow).SprintfFunc()
summary += fmt.Sprintf("%s running on %s \n", this.Version, this.LocalHost.Name)
summary += fmt.Sprintf("Local Status : %d\n", this.LocalHost.Status)
summary += fmt.Sprintf("Global Status : %d\n\n", this.GlobalStatus)
if this.LocalHost.Status != 100 || !showOnlyErrors {
summary += "Local probes : \n\n"
for probeName := range this.LocalHost.Probes {
if this.LocalHost.Probes[probeName].Status > 100 && this.LocalHost.Probes[probeName].Status < 300 {
summary += yellow("\t%-25s : %d %s\n", this.LocalHost.Probes[probeName].Name, this.LocalHost.Probes[probeName].Status, strings.Replace(this.LocalHost.Probes[probeName].Message, "%", "%%", -1))
} else if this.LocalHost.Probes[probeName].Status >= 300 {
summary += red("\t%-25s : %d %s\n", this.LocalHost.Probes[probeName].Name, this.LocalHost.Probes[probeName].Status, strings.Replace(this.LocalHost.Probes[probeName].Message, "%", "%%", -1))
} else {
summary += fmt.Sprintf("\t%-25s : %d %s\n", this.LocalHost.Probes[probeName].Name, this.LocalHost.Probes[probeName].Status, strings.Replace(this.LocalHost.Probes[probeName].Message, "%", "%%", -1))
}
}
summary += "\n"
}
if this.GlobalStatus >= 200 && len(this.RemoteWigos) > 0 {
summary += "Remote Wigos : \n\n"
}
summary += this.GenerateRemoteWigosSummary(0, showOnlyErrors, this.Version)
return
}
开发者ID:root-gg,项目名称:wigo,代码行数:33,代码来源:global.go
示例7: StatusMessage
func StatusMessage(view *gocui.View, data interface{}) {
yellow := color.New(color.FgYellow).SprintFunc()
white := color.New(color.FgWhite).SprintFunc()
timestamp := time.Now().Format("03:04")
fmt.Fprintf(view, "-> [%s] * %s\n", yellow(timestamp), white(data))
}
开发者ID:mephux,项目名称:komanda-cli,代码行数:7,代码来源:format.go
示例8: mainList
// mainList - is a handler for mc ls command
func mainList(ctx *cli.Context) {
// Additional command speific theme customization.
console.SetColor("File", color.New(color.FgWhite))
console.SetColor("Dir", color.New(color.FgCyan, color.Bold))
console.SetColor("Size", color.New(color.FgYellow))
console.SetColor("Time", color.New(color.FgGreen))
// check 'ls' cli arguments
checkListSyntax(ctx)
args := ctx.Args()
isIncomplete := ctx.Bool("incomplete")
// mimic operating system tool behavior
if globalMimicFlag && !ctx.Args().Present() {
args = []string{"."}
}
targetURLs, err := args2URLs(args.Head())
fatalIf(err.Trace(args...), "One or more unknown URL types passed.")
for _, targetURL := range targetURLs {
// if recursive strip off the "..."
var clnt client.Client
clnt, err = url2Client(stripRecursiveURL(targetURL))
fatalIf(err.Trace(targetURL), "Unable to initialize target ‘"+targetURL+"’.")
err = doList(clnt, isURLRecursive(targetURL), isIncomplete)
fatalIf(err.Trace(clnt.GetURL().String()), "Unable to list target ‘"+clnt.GetURL().String()+"’.")
}
}
开发者ID:koolhead17,项目名称:mc,代码行数:31,代码来源:ls-main.go
示例9: main
func main() {
cy := color.New(color.FgCyan).Add(color.BlinkSlow).PrintfFunc()
ma := color.New(color.FgMagenta).Add(color.BlinkSlow).PrintfFunc()
c1 := make(chan string)
c2 := make(chan string)
go func() {
time.Sleep(time.Second * 1)
c1 <- "one"
}()
go func() {
time.Sleep(time.Second * 2)
c2 <- "two"
}()
for i := 0; i < 2; i++ {
select {
case msg1 := <-c1:
cy("received %v ", msg1)
emoji.Printf(":beer:\n")
case msg2 := <-c2:
ma("received %v ", msg2)
emoji.Printf(":pizza:")
}
}
fmt.Println("")
}
开发者ID:igncp,项目名称:code-gym,代码行数:29,代码来源:select.go
示例10: shareSetColor
// shareSetColor sets colors share sub-commands.
func shareSetColor() {
// Additional command speific theme customization.
console.SetColor("Share", color.New(color.FgGreen, color.Bold))
console.SetColor("Expires", color.New(color.FgRed, color.Bold))
console.SetColor("URL", color.New(color.FgCyan, color.Bold))
console.SetColor("File", color.New(color.FgRed, color.Bold))
}
开发者ID:koolhead17,项目名称:mc,代码行数:8,代码来源:share.go
示例11: mainList
// mainList - is a handler for mc ls command
func mainList(ctx *cli.Context) {
// Additional command speific theme customization.
console.SetColor("File", color.New(color.FgWhite))
console.SetColor("Dir", color.New(color.FgCyan, color.Bold))
console.SetColor("Size", color.New(color.FgYellow))
console.SetColor("Time", color.New(color.FgGreen))
// Set global flags from context.
setGlobalsFromContext(ctx)
// check 'ls' cli arguments.
checkListSyntax(ctx)
// Set command flags from context.
isRecursive := ctx.Bool("recursive")
isIncomplete := ctx.Bool("incomplete")
args := ctx.Args()
// mimic operating system tool behavior.
if !ctx.Args().Present() {
args = []string{"."}
}
for _, targetURL := range args {
var clnt client.Client
clnt, err := newClient(targetURL)
fatalIf(err.Trace(targetURL), "Unable to initialize target ‘"+targetURL+"’.")
err = doList(clnt, isRecursive, isIncomplete)
if err != nil {
errorIf(err.Trace(clnt.GetURL().String()), "Unable to list target ‘"+clnt.GetURL().String()+"’.")
continue
}
}
}
开发者ID:fwessels,项目名称:mc,代码行数:36,代码来源:ls-main.go
示例12: ExecuteCommand
func ExecuteCommand(c *template.Template, fname string) error {
cmdStr, err := evalTemplate(c, &templateArg{File: fname})
if err != nil {
return err
}
cmd := exec.Command("bash", "-c", cmdStr)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
fmt.Println()
color.New(color.Bold).Printf("Execute by letter > ")
fmt.Println(cmdStr)
err = cmd.Run()
status, err := exitStatus(err)
if err != nil {
return err
}
color.New(color.Bold).Print("Finished command with status code ")
var colorAttr color.Attribute
if status == 0 {
colorAttr = color.FgGreen
} else {
colorAttr = color.FgRed
}
color.New(color.Bold, colorAttr).Println(status)
return nil
}
开发者ID:pocke,项目名称:letter,代码行数:32,代码来源:execute.go
示例13: SetChannelState
//SetChannelState sets the Channel inside the State
func SetChannelState(dg *discordgo.Session) {
State.InsertMode = false
guild := State.Guild
d := color.New(color.FgYellow, color.Bold)
d.Printf("Select a Channel:\n")
for key, channel := range guild.Channels {
if channel.Type == "text" {
fmt.Printf("%d:%s\n", key, channel.Name)
}
}
var response int
fmt.Scanf("%d\n", &response)
for guild.Channels[response].Type != "text" {
Error := color.New(color.FgRed, color.Bold)
Error.Printf("That's a voice channel, you know this is a CLI right?\n")
d.Printf("Select a Channel:\n")
fmt.Scanf("%d\n", &response)
}
State.Channel = guild.Channels[response]
Clear()
State.InsertMode = true
}
开发者ID:iopred,项目名称:discord-cli,代码行数:28,代码来源:init.go
示例14: Print
func (l *Summary) Print(out io.Writer, colored bool) {
info := func(a ...interface{}) { fmt.Fprintln(out, a...) }
warn := info
fail := info
success := info
color.Output = out
if colored {
warn = color.New(color.FgYellow).PrintlnFunc()
fail = color.New(color.FgRed).PrintlnFunc()
success = color.New(color.FgGreen).PrintlnFunc()
}
if len(l.Errors) == 0 {
message := "[OK] All is well!"
success(message)
return
}
for _, e := range l.Errors {
switch e.Level {
case 0:
info(e.Error())
case 1:
warn(e.Error())
case 2:
fail(e.Error())
}
}
if l.Severity() > 1 {
message := "[CRITICAL] Some critical problems found."
fail(message)
}
}
开发者ID:pkdevbox,项目名称:flint,代码行数:33,代码来源:summary.go
示例15: mainDiff
// mainDiff - is a handler for mc diff command
func mainDiff(ctx *cli.Context) {
checkDiffSyntax(ctx)
console.SetCustomTheme(map[string]*color.Color{
"DiffMessage": color.New(color.FgGreen, color.Bold),
"DiffOnlyInFirst": color.New(color.FgRed, color.Bold),
"DiffType": color.New(color.FgYellow, color.Bold),
"DiffSize": color.New(color.FgMagenta, color.Bold),
})
config := mustGetMcConfig()
firstArg := ctx.Args().First()
secondArg := ctx.Args().Last()
firstURL, err := getCanonicalizedURL(firstArg, config.Aliases)
fatalIf(err.Trace(firstArg), "Unable to parse first argument ‘"+firstArg+"’.")
secondURL, err := getCanonicalizedURL(secondArg, config.Aliases)
fatalIf(err.Trace(secondArg), "Unable to parse second argument ‘"+secondArg+"’.")
newFirstURL := stripRecursiveURL(firstURL)
for diff := range doDiffCmd(newFirstURL, secondURL, isURLRecursive(firstURL)) {
fatalIf(diff.Error.Trace(newFirstURL, secondURL), "Failed to diff ‘"+firstURL+"’ and ‘"+secondURL+"’.")
console.Println(diff.String())
}
}
开发者ID:axcoto-lab,项目名称:mc,代码行数:27,代码来源:diff-main.go
示例16: FetchHTMLDoc
func FetchHTMLDoc(url string) (doc *goquery.Document, err error) {
retries := 15
err = errors.New("Init Errir")
for retries > 0 && err != nil {
doc, err = goquery.NewDocument(url)
if err != nil {
c := color.New(color.FgMagenta)
c.Println(retries, "RETRYING! Error in fetching http:", err)
time.Sleep(10 * time.Second)
}
retries = retries - 1
}
if err != nil {
fmt.Println(err)
return
}
if retries < 14 {
c := color.New(color.FgGreen)
c.Printf("\nRecovered from http error in %d tries\n", 14-retries)
}
return
}
开发者ID:rohanraja,项目名称:flipgo,代码行数:28,代码来源:htmlfetch.go
示例17: boolToColor
func boolToColor(b bool) *color.Color {
if b {
return color.New(color.FgGreen)
} else {
return color.New(color.FgHiRed)
}
}
开发者ID:vektorlab,项目名称:otter,代码行数:7,代码来源:helpers.go
示例18: main
func main() {
red := color.New(color.FgRed).SprintFunc()
green := color.New(color.FgGreen).SprintFunc()
t1 := time.Now()
fmt.Printf("START: %s\n", time.Now().UTC().Format(time.RFC3339))
for i := 0; i < Threads; i++ {
go hitEsearch()
}
for i := 0; i < Threads; i++ {
<-c // wait for one task to complete
}
fmt.Printf("Complete: %v\n", perf)
t2 := time.Now()
duration := t2.Sub(t1)
s := duration.String()
dur, _ := time.ParseDuration("300ms")
if t2.Sub(t1) > dur {
s = red(s)
} else {
s = green(s)
}
total := Threads * Requests
num := int(total) / int(duration.Seconds())
fmt.Printf("END: %s -- %s %d Requests %d Requests/Second\n",
time.Now().UTC().Format(time.RFC3339), s, total, num)
}
开发者ID:thecaddy,项目名称:perf-elasticsearch,代码行数:29,代码来源:perf.go
示例19: mainList
// mainList - is a handler for mc ls command
func mainList(ctx *cli.Context) {
checkListSyntax(ctx)
args := ctx.Args()
// Operating system tool behavior
if globalMimicFlag && !ctx.Args().Present() {
args = []string{"."}
}
console.SetCustomTheme(map[string]*color.Color{
"File": color.New(color.FgWhite),
"Dir": color.New(color.FgCyan, color.Bold),
"Size": color.New(color.FgYellow),
"Time": color.New(color.FgGreen),
})
targetURLs, err := args2URLs(args)
fatalIf(err.Trace(args...), "One or more unknown URL types passed.")
for _, targetURL := range targetURLs {
// if recursive strip off the "..."
var clnt client.Client
clnt, err = target2Client(stripRecursiveURL(targetURL))
fatalIf(err.Trace(targetURL), "Unable to initialize target ‘"+targetURL+"’.")
err = doList(clnt, isURLRecursive(targetURL), len(targetURLs) > 1)
fatalIf(err.Trace(clnt.URL().String()), "Unable to list target ‘"+clnt.URL().String()+"’.")
}
}
开发者ID:akiradeveloper,项目名称:mc,代码行数:30,代码来源:ls-main.go
示例20: toColor
func toColor(s interface{}, r RefType) string {
if r == Hyperlink {
return color.New(color.FgHiCyan).SprintFunc()(s)
} else {
return color.New(color.FgYellow).SprintFunc()(s)
}
}
开发者ID:rdingwall,项目名称:go-webcrawler,代码行数:7,代码来源:main.go
注:本文中的github.com/fatih/color.New函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论