本文整理匯總了Golang中github.com/fatih/color.BlueString函數的典型用法代碼示例。如果您正苦於以下問題:Golang BlueString函數的具體用法?Golang BlueString怎麽用?Golang BlueString使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了BlueString函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: showResult
func showResult(commits []*commit, keyword string) {
repoWidth := maxRepoWidth(commits)
repoFmt := fmt.Sprintf("%%-%ds", repoWidth)
urlWidth := maxURLWidth(commits)
urlFmt := fmt.Sprintf("%%-%ds", urlWidth)
msgWidth := maxMessageWidth(commits)
fmt.Printf(" %s | %s | %s | message \n",
color.BlueString(repoFmt, "Repository"),
color.CyanString("%-7s", "sha1"),
fmt.Sprintf(urlFmt, "url"),
)
fmt.Println(strings.Repeat("-", repoWidth+msgWidth+urlWidth+18))
for _, c := range commits {
fmt.Printf(" %s | %7s | %s | %s\n",
color.BlueString(repoFmt, c.Repo),
color.CyanString(c.Sha1),
fmt.Sprintf(urlFmt, c.CommitURL),
highlightWords(c.Message, keyword),
)
}
}
示例2: replacePlaceholders
func (obj *Decorator) replacePlaceholders(
str string,
placeholders map[string]interface{},
) string {
r := regexp.MustCompile(":\\w+")
for _, key := range r.FindAllString(str, -1) {
name := strings.Replace(key, ":", "", -1)
if value, ok := placeholders[name]; ok {
switch reflect.TypeOf(value).String() {
case "string":
value = color.CyanString(fmt.Sprint(value))
break
case "int64":
value = color.BlueString(fmt.Sprintf("%d", value))
case "float64":
if regexp.MustCompile("^[0-9]+(.[0]+)?").MatchString(fmt.Sprintf("%f", value)) {
value = fmt.Sprintf("%d", int64(value.(float64)))
} else {
value = fmt.Sprintf("%f", value)
}
value = color.BlueString(value.(string))
break
default:
value = fmt.Sprint(value)
}
str = strings.Replace(str, key, value.(string), -1)
}
}
return str
}
示例3: isIndexStatic
// isIndexStatic returns true if a block does not have a modify-index Phi.
func (fa *FairnessAnalysis) isIndexStatic(blk *ssa.BasicBlock) bool {
for _, instr := range blk.Instrs {
switch instr := instr.(type) {
case *ssa.DebugRef:
case *ssa.Phi:
if len(instr.Comment) > 0 {
fa.logger.Println(color.BlueString(" note: Index var %s", instr.Comment))
return false
}
}
}
fa.logger.Println(color.BlueString(" note: Index var not found"))
return true
}
示例4: reportHashDiffs
func (f *Fissile) reportHashDiffs(hashDiffs *HashDiffs) {
if len(hashDiffs.DeletedKeys) > 0 {
f.UI.Println(color.RedString("Dropped keys:"))
sort.Strings(hashDiffs.DeletedKeys)
for _, v := range hashDiffs.DeletedKeys {
f.UI.Printf(" %s\n", v)
}
}
if len(hashDiffs.AddedKeys) > 0 {
f.UI.Println(color.GreenString("Added keys:"))
sort.Strings(hashDiffs.AddedKeys)
for _, v := range hashDiffs.AddedKeys {
f.UI.Printf(" %s\n", v)
}
}
if len(hashDiffs.ChangedValues) > 0 {
f.UI.Println(color.BlueString("Changed values:"))
sortedKeys := make([]string, len(hashDiffs.ChangedValues))
i := 0
for k := range hashDiffs.ChangedValues {
sortedKeys[i] = k
i++
}
sort.Strings(sortedKeys)
for _, k := range sortedKeys {
v := hashDiffs.ChangedValues[k]
f.UI.Printf(" %s: %s => %s\n", k, v[0], v[1])
}
}
}
示例5: logCode
func (rl *ResponseLogWriter) logCode(code int, status string) {
var codestr string
switch {
case code >= 200 && code < 300:
codestr = color.GreenString("%d %s", code, status)
case code >= 300 && code < 400:
codestr = color.BlueString("%d %s", code, status)
case code >= 400 && code < 500:
codestr = color.YellowString("%d %s", code, status)
case code >= 500 && code < 600:
codestr = color.RedString("%d %s", code, status)
default:
codestr = fmt.Sprintf("%d %s", code, status)
}
cl := rl.Header().Get("content-length")
if cl != "" {
cli, err := strconv.Atoi(cl)
if err != nil {
cl = "invalid content length header"
} else {
cl = fmt.Sprintf("%s", humanize.Bytes(uint64(cli)))
}
}
rl.Log.Say("<- %s %s", codestr, cl)
}
示例6: main
func main() {
l := termlog.NewLog()
testpatt(l)
g := l.Group()
g.Say("This is a group...")
testpatt(g)
g.Done()
g = l.Group()
g.Say("Here are some composed colours...")
g.Say(
"%s %s %s",
color.RedString("red"),
color.GreenString("green"),
color.BlueString("blue"),
)
g.Done()
l.Enable("demo")
g = l.Group()
g.SayAs("disabled", "These don't show...")
g.SayAs("demo", "Some named log entries...")
g.SayAs("demo", "This is a test")
g.SayAs("disabled", "This is a test")
g.Done()
g = l.Group()
g.Say("Disabled colour output...")
l.NoColor()
testpatt(g)
g.Done()
}
示例7: New
func New(separator string) *tree {
return &tree{
separator,
&node{},
color.BlueString("%%s"),
true,
}
}
示例8: Do
func (a Samidare) Do() error {
fmt.Fprintf(color.Output, "TestName : %s \n", color.GreenString("%s", a.Name))
for idx, testCase := range a.GetTestCases() {
fmt.Fprintf(color.Output, "TestCaseName: [%d] %s\n", idx+1, color.GreenString("%s", testCase.Name))
req, err := testCase.Request.BuildRequest()
if err != nil {
fmt.Fprintf(color.Output, "%s\n", color.RedString("%s", err.Error()))
continue
}
resp, err := a.client.Do(req)
if err != nil {
fmt.Fprintf(color.Output, "%s\n", color.RedString("%s", err.Error()))
continue
}
if resp.StatusCode != testCase.Response.Status {
fmt.Fprintf(color.Output, "NG status: %s\n", color.RedString("%d != %d", resp.StatusCode, testCase.Response.Status))
} else {
fmt.Fprintf(color.Output, "OK status: %s\n", color.BlueString("%d == %d", resp.StatusCode, testCase.Response.Status))
}
for k, v := range testCase.Response.Headers {
if resp.Header[k][0] != fmt.Sprintf("%v", v) {
fmt.Fprintf(color.Output, "OK %s: %s\n", k, color.RedString("%v != %v", resp.Header[k][0], v))
} else {
fmt.Fprintf(color.Output, "OK %s: %s\n", k, color.BlueString("%v == %v", resp.Header[k][0], v))
}
}
data, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
log.Println(err)
} else {
// TODO: Option
// fmt.Println(string(data))
_ = data
}
}
return nil
}
示例9: testFiles
func testFiles(t *testing.T, files []string, loader *Loader) {
var passing, total, schemaErrors int
for _, file := range files {
f, err := os.Open(file)
if err != nil {
t.Fatalf("Failed to open %q: %s", file, err)
}
v, err := json.Parse(f)
f.Close()
if err != nil {
t.Fatalf("Failed to parse %q: %s", file, err)
}
tests, ok := v.(*json.Array)
if !ok {
t.Fatalf("Content of %q is not an array: %T", file, v)
}
for i, tt := range tests.Value {
test, ok := tt.(*json.Object)
if !ok {
t.Fatalf("Test %d in %q is not an object", i, file)
}
t.Logf(color.BlueString("=====> Testing %s, case %d: %s", file, i, test.Find("description")))
schema := test.Find("schema")
err := ValidateDraft04Schema(schema)
if err != nil {
t.Errorf(color.RedString("schema does not pass validation: %s", err))
schemaErrors++
}
v, _ := NewValidator(schema, loader) // not checking the error since schema is already validated
cases := test.Find("tests").(*json.Array)
for _, c := range cases.Value {
total++
case_ := c.(*json.Object)
valid := case_.Find("valid").(*json.Bool).Value
err := v.Validate(case_.Find("data"))
switch {
case err == nil && valid:
passing++
t.Logf("%s %s", color.GreenString("PASSED"), case_.Find("description"))
case err != nil && !valid:
passing++
t.Logf("%s %s: %s", color.GreenString("PASSED"), case_.Find("description"), err)
case err != nil && valid:
t.Errorf("%s %s: %s", color.RedString("FAILED"), case_.Find("description"), err)
case err == nil && !valid:
t.Errorf("%s %s", color.RedString("FAILED"), case_.Find("description"))
}
}
}
}
t.Logf("Passing %d out of %d tests (%g%%)", passing, total, float64(passing)/float64(total)*100)
if schemaErrors > 0 {
t.Logf("%d schemas failed validation", schemaErrors)
}
}
示例10: updateCache
func (c container) updateCache(hash string, body string, backendURL string, async bool) (string, error) {
var response string
var err error
if c.lockUpdate(hash) == false {
if async == true {
log.Debug(fmt.Sprintf("%s %s", hash, color.RedString("LOCKED")))
return response, err
}
}
redisConn := c.pool.Get()
defer redisConn.Close()
log.Debug("%s %s", hash, color.BlueString("UPDATE"))
httpClient := http.Client{Timeout: time.Duration(600 * time.Second)}
resp, httperror := httpClient.Post(backendURL, "application/JSON", strings.NewReader(body))
if httperror == nil {
if resp.StatusCode != 200 {
log.Error(fmt.Sprintf("Backend error code: %v ", resp.StatusCode))
return response, err
}
requestBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Error(fmt.Sprintf("body read failed: %s : %s", hash, err.Error()))
}
response = string(requestBody)
if response != "" {
_, err = redisConn.Do("SET", hash, string(requestBody))
if err != nil {
log.Error(fmt.Sprintf("key set failed: %s : %s", hash, err.Error()))
return response, err
}
log.Debug(fmt.Sprintf("%s %s", hash, color.GreenString("SET")))
_, err = redisConn.Do("EXPIRE", hash, config.expire)
if err != nil {
log.Error(fmt.Sprintf("key expire set failed: %s : %s", hash, err.Error()))
return response, err
}
} else {
log.Error("Empty backend response")
fmt.Println(resp)
}
} else {
log.Error(fmt.Sprintf("Backend request failure: %s", httperror.Error()))
}
c.unlockUpdate(hash)
return response, err
}
示例11: Interactive
func (app *App) Interactive() {
rl, err := readline.NewEx(&readline.Config{
Prompt: color.BlueString("say » "),
HistoryFile: app.Config.HistoryFile,
})
if err != nil {
log.Fatal(err)
}
defer rl.Close()
app.Log.SetOutput(rl.Stderr())
log.SetOutput(rl.Stderr())
color.Output = ansicolor.NewAnsiColorWriter(rl.Stderr())
pings := make(map[string]time.Time)
// Subscribe to all replies and print them to stdout
app.Client.Subscribe("", "self", func(msg sarif.Message) {
text := msg.Text
if text == "" {
text = msg.Action + " from " + msg.Source
}
if msg.IsAction("err") {
text = color.RedString(text)
}
if sent, ok := pings[msg.CorrId]; ok {
text += color.YellowString("[%.1fms]", time.Since(sent).Seconds()*1e3)
}
log.Println(color.GreenString(" « ") + strings.Replace(text, "\n", "\n ", -1))
})
// Interactive mode sends all lines from stdin.
for {
line, err := rl.Readline()
if err != nil {
if err == io.EOF {
return
}
log.Fatal(err)
}
if len(line) == 0 {
continue
}
// Publish natural message
msg := sarif.Message{
Id: sarif.GenerateId(),
Action: "natural/handle",
Text: line,
}
if *profile {
pings[msg.Id] = time.Now()
}
app.Client.Publish(msg)
}
}
示例12: Row
func (e *Entry) Row() []string {
y, m, d := e.Time.Date()
date := color.BlueString("%d/%d/%d", m, d, y)
ip := color.RedString("%s", e.Ip)
attempts := color.GreenString("%d", e.Attempts)
user := color.YellowString("%s", e.User)
auth := color.WhiteString("%s", e.AuthType)
proto := color.CyanString("%s", e.Protocol)
port := e.Port
server := e.Server
return []string{date, ip, attempts, user, auth, proto, port, server}
}
示例13: Logo
// Logo with color
func Logo() string {
var logo string
logo += "\n\n"
logo += color.GreenString(" ██╗ ██╗ ██████╗ ███╗ ███╗ █████╗ ███╗ ██╗██████╗ █████╗\n")
logo += color.MagentaString(" ██║ ██╔╝██╔═══██╗████╗ ████║██╔══██╗████╗ ██║██╔══██╗██╔══██╗\n")
logo += color.YellowString(" █████╔╝ ██║ ██║██╔████╔██║███████║██╔██╗ ██║██║ ██║███████║\n")
logo += color.CyanString(" ██╔═██╗ ██║ ██║██║╚██╔╝██║██╔══██║██║╚██╗██║██║ ██║██╔══██║\n")
logo += color.BlueString(" ██║ ██╗╚██████╔╝██║ ╚═╝ ██║██║ ██║██║ ╚████║██████╔╝██║ ██║\n")
logo += color.RedString(" ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚═════╝ ╚═╝ ╚═╝")
return logo
}
示例14: showResult
func showResult(result QueryResult, url, keyword string, page int) {
commits := result.Commits
if len(commits) == 0 {
fmt.Println("No Results Found.")
fmt.Printf(" url: %s\n\n", url)
return
}
fmt.Printf("Search Result : %s : %d/%s pages\n",
result.ResultCount,
page,
result.TotalPages,
)
fmt.Printf(" url: %s\n\n", url)
repoWidth := maxRepoWidth(commits)
repoFmt := fmt.Sprintf("%%-%ds", repoWidth)
urlWidth := maxURLWidth(commits)
urlFmt := fmt.Sprintf("%%-%ds", urlWidth)
msgWidth := maxMessageWidth(commits)
fmt.Fprintf(color.Output, " %s | %s | %s | message \n",
color.BlueString(repoFmt, "Repository"),
color.CyanString("%-7s", "sha1"),
fmt.Sprintf(urlFmt, "url"),
)
fmt.Println(strings.Repeat("-", repoWidth+msgWidth+urlWidth+18))
for _, c := range commits {
fmt.Fprintf(color.Output, " %s | %7s | %s | %s\n",
color.BlueString(repoFmt, c.Repo),
color.CyanString(c.Sha1),
fmt.Sprintf(urlFmt, c.CommitURL),
highlightWords(c.Message, keyword),
)
}
}
示例15: runListSecretsCommand
// runListSecretsCommand retrieves a listing of the secrets under one or more paths
func runListSecretsCommand(cx *cli.Context, factory *commandFactory) error {
bucket := cx.String("bucket")
suffix := cx.GlobalString("suffix")
longListing := cx.Bool("long")
recursive := cx.Bool("recursive")
paths := cx.Args()
if bucket == "" {
return fmt.Errorf("you have not specified a bucket to list files")
}
if len(paths) <= 0 {
paths = append(paths, "")
}
// step: iterate the paths specified and list the secrets
for _, path := range paths {
path := filterPath(path)
files, err := factory.s3.listObjects(bucket, path, recursive)
if err != nil {
return fmt.Errorf("failed to retrieve a list of files from bucket: %s, path: %s, error: %s", bucket, path, err)
}
fmt.Printf("total: %d\n", len(files))
for _, file := range files {
filename := file.path
if strings.HasSuffix(filename, "/") {
filename = fmt.Sprintf("%s", color.BlueString(filename))
}
if !strings.HasSuffix(filename, suffix) {
filename = fmt.Sprintf("%s", color.RedString(filename))
}
switch longListing {
case true:
lastModified := "dir"
if !file.directory {
lastModified = file.lastModified.Format("Oct 02 15:04")
}
fmt.Printf("%-20s %5d %-15s %s\n", file.owner, file.size, lastModified, filename)
default:
fmt.Printf("%s\n", filename)
}
}
}
return nil
}