當前位置: 首頁>>代碼示例>>Golang>>正文


Golang console.Colorize函數代碼示例

本文整理匯總了Golang中github.com/minio/mc/pkg/console.Colorize函數的典型用法代碼示例。如果您正苦於以下問題:Golang Colorize函數的具體用法?Golang Colorize怎麽用?Golang Colorize使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Colorize函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: mainVersion

func mainVersion(ctx *cli.Context) {
	if ctx.Args().First() == "help" {
		cli.ShowCommandHelpAndExit(ctx, "version", 1) // last argument is exit code
	}

	setVersionPalette(ctx.GlobalString("colors"))

	if globalJSONFlag {
		tB, e := json.Marshal(
			struct {
				Version struct {
					Value  string `json:"value"`
					Format string `json:"format"`
				} `json:"version"`
			}{
				Version: struct {
					Value  string `json:"value"`
					Format string `json:"format"`
				}{
					Value:  mcVersion,
					Format: "RFC2616",
				},
			},
		)
		fatalIf(probe.NewError(e), "Unable to construct version string.")
		console.Println(string(tB))
		return
	}
	msg := console.Colorize("Version", fmt.Sprintf("Version: %s\n", mcVersion))
	msg += console.Colorize("Version", fmt.Sprintf("Release-Tag: %s", mcReleaseTag))
	console.Println(msg)
}
開發者ID:zhujo01,項目名稱:mc,代碼行數:32,代碼來源:version-main.go

示例2: String

// String colorized access message
func (s AccessMessage) String() string {
	if s.Operation == "set" {
		return console.Colorize("Access", "Set access permission ‘"+string(s.Perms)+"’ updated successfully for ‘"+s.Bucket+"’")
	}
	if s.Operation == "get" {
		return console.Colorize("Access", "Access permission for ‘"+s.Bucket+"’"+" is ‘"+string(s.Perms)+"’")
	}
	// nothing to print
	return ""
}
開發者ID:henrylee2cn,項目名稱:mc,代碼行數:11,代碼來源:access-main.go

示例3: String

// String colorized clear session message.
func (c clearSessionMessage) String() string {
	msg := "Session ‘" + c.SessionID + "’"
	var colorizedMsg string
	switch c.Status {
	case "success":
		colorizedMsg = console.Colorize("ClearSession", msg+" cleared successfully.")
	case "forced":
		colorizedMsg = console.Colorize("ClearSession", msg+" cleared forcefully.")
	}
	return colorizedMsg
}
開發者ID:balamurugana,項目名稱:mc,代碼行數:12,代碼來源:session-main.go

示例4: String

func (u watchMessage) String() string {
	msg := console.Colorize("Time", fmt.Sprintf("[%s] ", u.Event.Time))
	if u.Event.Type == EventCreate {
		msg += console.Colorize("Size", fmt.Sprintf("%6s ", humanize.IBytes(uint64(u.Event.Size))))
	} else {
		msg += fmt.Sprintf("%6s ", "")
	}
	msg += console.Colorize("EventType", fmt.Sprintf("%s ", u.Event.Type))
	msg += console.Colorize("ObjectName", fmt.Sprintf("%s", u.Event.Path))
	return msg
}
開發者ID:balamurugana,項目名稱:mc,代碼行數:11,代碼來源:watch-main.go

示例5: String

// String colorized string message
func (c ContentMessage) String() string {
	message := console.Colorize("Time", fmt.Sprintf("[%s] ", c.Time.Format(printDate)))
	message = message + console.Colorize("Size", fmt.Sprintf("%6s ", humanize.IBytes(uint64(c.Size))))
	message = func() string {
		if c.Filetype == "folder" {
			return message + console.Colorize("Dir", fmt.Sprintf("%s", c.Name))
		}
		return message + console.Colorize("File", fmt.Sprintf("%s", c.Name))
	}()
	return message
}
開發者ID:akiradeveloper,項目名稱:mc,代碼行數:12,代碼來源:ls.go

示例6: String

// String colorized access message.
func (s policyMessage) String() string {
	if s.Operation == "set" {
		return console.Colorize("Policy",
			"Access permission for ‘"+s.Bucket+"’ is set to ‘"+string(s.Perms)+"’")
	}
	if s.Operation == "get" {
		return console.Colorize("Policy",
			"Access permission for ‘"+s.Bucket+"’"+" is ‘"+string(s.Perms)+"’")
	}
	// nothing to print
	return ""
}
開發者ID:balamurugana,項目名稱:mc,代碼行數:13,代碼來源:policy-main.go

示例7: String

// String colorized diff message
func (d DiffMessage) String() string {
	msg := ""
	switch d.Diff {
	case "only-in-first":
		msg = console.Colorize("DiffMessage", "‘"+d.FirstURL+"’"+" and "+"‘"+d.SecondURL+"’") + console.Colorize("DiffOnlyInFirst", " - only in first.")
	case "type":
		msg = console.Colorize("DiffMessage", "‘"+d.FirstURL+"’"+" and "+"‘"+d.SecondURL+"’") + console.Colorize("DiffType", " - differ in type.")
	case "size":
		msg = console.Colorize("DiffMessage", "‘"+d.FirstURL+"’"+" and "+"‘"+d.SecondURL+"’") + console.Colorize("DiffSize", " - differ in size.")
	default:
		fatalIf(errDummy().Trace(), "Unhandled difference between ‘"+d.FirstURL+"’ and ‘"+d.SecondURL+"’.")
	}
	return msg

}
開發者ID:henrylee2cn,項目名稱:mc,代碼行數:16,代碼來源:diff.go

示例8: String

// String colorized alias message
func (a AliasMessage) String() string {
	if a.op == "list" {
		message := console.Colorize("Alias", fmt.Sprintf("[%s] <- ", a.Alias))
		message += console.Colorize("URL", fmt.Sprintf("%s", a.URL))
		return message
	}
	if a.op == "remove" {
		return console.Colorize("AliasMessage", "Removed alias ‘"+a.Alias+"’ successfully.")
	}
	if a.op == "add" {
		return console.Colorize("AliasMessage", "Added alias ‘"+a.Alias+"’ successfully.")
	}
	// should never come here
	return ""
}
開發者ID:henrylee2cn,項目名稱:mc,代碼行數:16,代碼來源:config-alias-main.go

示例9: mainDiff

// mainDiff main for 'diff'.
func mainDiff(ctx *cli.Context) {
	checkDiffSyntax(ctx)

	// Additional command speific theme customization.
	console.SetColor("DiffMessage", color.New(color.FgGreen, color.Bold))
	console.SetColor("DiffOnlyInFirst", color.New(color.FgRed, color.Bold))
	console.SetColor("DiffType", color.New(color.FgYellow, color.Bold))
	console.SetColor("DiffSize", color.New(color.FgMagenta, color.Bold))

	config := mustGetMcConfig()
	firstArg := ctx.Args().First()
	secondArg := ctx.Args().Last()

	firstURL := getAliasURL(firstArg, config.Aliases)
	secondURL := getAliasURL(secondArg, config.Aliases)

	newFirstURL := stripRecursiveURL(firstURL)
	for diff := range doDiffMain(newFirstURL, secondURL, isURLRecursive(firstURL)) {
		if diff.Error != nil {
			// Print in new line and adjust to top so that we don't print over the ongoing scan bar
			if !globalQuietFlag && !globalJSONFlag {
				console.Eraseline()
			}
		}
		fatalIf(diff.Error.Trace(newFirstURL, secondURL), "Failed to diff ‘"+firstURL+"’ and ‘"+secondURL+"’.")
		printMsg(diff)
	}
	// Print in new line and adjust to top so that we don't print over the ongoing scan bar
	if !globalQuietFlag && !globalJSONFlag {
		console.Eraseline()
	}
	console.Println(console.Colorize("DiffMessage", "Done."))
}
開發者ID:koolhead17,項目名稱:mc,代碼行數:34,代碼來源:diff-main.go

示例10: newProgressBar

// newProgressBar - instantiate a pbBar.
func newProgressBar() barSend {
	console.SetCustomTheme(map[string]*color.Color{
		"Bar": color.New(color.FgGreen, color.Bold),
	})
	cmdCh := make(chan barMsg)
	finishCh := make(chan bool)
	go func(cmdCh <-chan barMsg, finishCh chan<- bool) {
		var started bool
		var totalBytesRead int64 // total amounts of bytes read
		bar := pb.New64(0)
		bar.SetUnits(pb.U_BYTES)
		bar.SetRefreshRate(time.Millisecond * 125)
		bar.NotPrint = true
		bar.ShowSpeed = true
		bar.Callback = func(s string) {
			console.Print(console.Colorize("Bar", "\r"+s))
		}
		switch runtime.GOOS {
		case "linux":
			bar.Format("┃▓█░┃")
			// bar.Format("█▓▒░█")
		case "darwin":
			bar.Format(" ▓ ░ ")
		default:
			bar.Format("[=> ]")
		}
		for msg := range cmdCh {
			switch msg.Op {
			case pbBarSetCaption:
				bar.Prefix(fixateBarCaption(msg.Arg.(string), getFixedWidth(bar.GetWidth(), 18)))
			case pbBarExtend:
				atomic.AddInt64(&bar.Total, msg.Arg.(int64))
			case pbBarProgress:
				if bar.Total > 0 && !started {
					started = true
					bar.Start()
				}
				if msg.Arg.(int64) > 0 {
					totalBytesRead += msg.Arg.(int64)
					bar.Add64(msg.Arg.(int64))
				}
			case pbBarPutError:
				if totalBytesRead > msg.Arg.(int64) {
					bar.Set64(totalBytesRead - msg.Arg.(int64))
				}
			case pbBarGetError:
				if msg.Arg.(int64) > 0 {
					bar.Add64(msg.Arg.(int64))
				}
			case pbBarFinish:
				if started {
					bar.Finish()
				}
				finishCh <- true
				return
			}
		}
	}(cmdCh, finishCh)
	return barSend{cmdCh, finishCh}
}
開發者ID:akiradeveloper,項目名稱:mc,代碼行數:61,代碼來源:pb.go

示例11: String

func (u eventsListMessage) String() string {
	msg := console.Colorize("ARN", fmt.Sprintf("%s   ", u.Arn))
	for i, event := range u.Events {
		msg += console.Colorize("Events", event)
		if i != len(u.Events)-1 {
			msg += ","
		}
	}
	msg += console.Colorize("Filter", fmt.Sprintf("   Filter: "))
	if u.Prefix != "" {
		msg += console.Colorize("Filter", fmt.Sprintf("prefix=\"%s\"", u.Prefix))
	}
	if u.Suffix != "" {
		msg += console.Colorize("Filter", fmt.Sprintf("suffix=\"%s\"", u.Suffix))
	}
	return msg
}
開發者ID:balamurugana,項目名稱:mc,代碼行數:17,代碼來源:events-list.go

示例12: String

// String string printer for Content metadata.
func (c ContentMessage) String() string {
	if !globalJSONFlag {
		message := console.Colorize("Time", fmt.Sprintf("[%s] ", c.Time.Format(printDate)))
		message = message + console.Colorize("Size", fmt.Sprintf("%6s ", humanize.IBytes(uint64(c.Size))))
		message = func() string {
			if c.Filetype == "folder" {
				return message + console.Colorize("Dir", fmt.Sprintf("%s", c.Name))
			}
			return message + console.Colorize("File", fmt.Sprintf("%s", c.Name))
		}()
		return message
	}
	jsonMessageBytes, e := json.Marshal(c)
	fatalIf(probe.NewError(e), "Unable to marshal into JSON.")

	return string(jsonMessageBytes)
}
開發者ID:axcoto-lab,項目名稱:mc,代碼行數:18,代碼來源:ls.go

示例13: String

// String string printer for copy message
func (c CopyMessage) String() string {
	if !globalJSONFlag {
		return console.Colorize("Copy", fmt.Sprintf("‘%s’ -> ‘%s’", c.Source, c.Target))
	}
	copyMessageBytes, err := json.Marshal(c)
	fatalIf(probe.NewError(err), "Failed to marshal copy message.")

	return string(copyMessageBytes)
}
開發者ID:axcoto-lab,項目名稱:mc,代碼行數:10,代碼來源:cp-main.go

示例14: String

func (s MakeBucketMessage) String() string {
	if !globalJSONFlag {
		return console.Colorize("MakeBucket", "Bucket created successfully  ‘"+s.Bucket+"’")
	}
	makeBucketJSONBytes, err := json.Marshal(s)
	fatalIf(probe.NewError(err), "Unable to marshal into JSON.")

	return string(makeBucketJSONBytes)
}
開發者ID:axcoto-lab,項目名稱:mc,代碼行數:9,代碼來源:mb-main.go

示例15: String

func (s AccessMessage) String() string {
	if !globalJSONFlag {
		return console.Colorize("Access", "Set access permission ‘"+string(s.Perms)+"’ updated successfully for ‘"+s.Bucket+"’")
	}
	accessJSONBytes, err := json.Marshal(s)
	fatalIf(probe.NewError(err), "Unable to marshal into JSON.")

	return string(accessJSONBytes)
}
開發者ID:axcoto-lab,項目名稱:mc,代碼行數:9,代碼來源:access-main.go


注:本文中的github.com/minio/mc/pkg/console.Colorize函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。