本文整理匯總了Golang中github.com/fatih/color.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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,
)
}
示例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+"’.")
}
}
示例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)
}
})
}
示例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)
}
示例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()
}
}
}
示例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
}
示例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))
}
示例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()+"’.")
}
}
示例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("")
}
示例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))
}
示例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
}
}
}
示例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
}
示例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
}
示例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)
}
}
示例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())
}
}