• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang color.Printf函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/wsxiaoys/terminal/color.Printf函数的典型用法代码示例。如果您正苦于以下问题:Golang Printf函数的具体用法?Golang Printf怎么用?Golang Printf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Printf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: purge

func (c *client) purge(host string, f gfind.File, k int, id int) {
	var Url *url.URL
	Url, err := url.Parse(host)
	chkErr(err)
	Url.Path += "/purge"
	Url.Path += f.Relpath
	var u string
	u = Url.String()
	if security != "" {
		u += "?" + ParseNgxSecurityLink(security, host, f)
	}
	req, err := http.NewRequest("HEAD", u, nil)
	req.Close = true
	if vhost != "client.com" {
		req.Host = vhost
	}
	resp, err := c.c.Do(req)
	chkErr(err)
	if resp.StatusCode == 200 {
		color.Printf("%6v-%-2d @{g}%[email protected]{|} %v %v\n", k, id, "PURGE:SUCCESS", Url.String(), f.Size())
	} else if resp.StatusCode == 404 {
		color.Printf("%6v-%-2d @{y}%[email protected]{|} %v %v\n", k, id, "PURGE:NOFILE", Url.String(), f.Size())
	}

}
开发者ID:kiyor,项目名称:precache,代码行数:25,代码来源:precache.go


示例2: output

func output(hostname, servicename, v interface{}) {
	// define quick color/graphic view of output
	var s, m, a string
	if state(v) == 0 {
		s = color.Sprintf("@{g}%-10s", "[OK]")
	} else if state(v) == 1 {
		s = color.Sprintf("@{y}%-10s", "[WARNING]")
	} else if state(v) == 2 {
		s = color.Sprintf("@{r}%-10s", "[CRITICAL]")
	}
	if notifications(v) {
		m = color.Sprintf("@{g}  %v  ", ` `)
	} else {
		m = color.Sprintf("@{r}  %v  ", `Ø`)
	}
	if acknowledged(v) {
		a = color.Sprintf("@{g}  %v  ", `√`)
	} else {
		a = color.Sprintf("@{g}  %v  ", ` `)
	}

	// this just incase if change mind use different syntax
	switch v := v.(type) {
	default:
	case *nagiosToJson.Hoststatus:
		// 		color.Printf("%-10s: %v %v %v %v %v\n", hostname, m, s, a, v.Plugin_output, time.Since(str2time(v.Last_check)))
		color.Printf("%-10s: %-10v %v %v %v %v %v\n", hostname, servicename, m, s, a, v.Plugin_output, time.Since(str2time(v.Last_check)))
	case *nagiosToJson.Servicestatus:
		color.Printf("%-10s: %-10v %v %v %v %v %v\n", hostname, servicename, m, s, a, v.Plugin_output, time.Since(str2time(v.Last_check)))
	}
}
开发者ID:kiyor,项目名称:nagtool,代码行数:31,代码来源:main.go


示例3: readWholeNumber

func readWholeNumber(prompt string, bits int, unsigned bool, allowBlank bool, defaultValue int64) (out int64, err error) {
	var iu uint64
	var i int64

loop:
	for {
		fmt.Print(prompt)

		line, err := readLine()

		if strings.TrimSpace(line) == "" && allowBlank {
			if unsigned {
				iu = uint64(defaultValue)
			} else {
				i = defaultValue
			}

			break loop
		}

		if unsigned {
			iu, err = strconv.ParseUint(string(line), 10, bits)
		} else {
			i, err = strconv.ParseInt(string(line), 10, bits)
		}

		if err != nil {
			numError := err.(*strconv.NumError)

			switch numError.Err {
			case strconv.ErrSyntax:
				if unsigned {
					color.Printf("@{r}%s is not a non-negative integer\n", numError.Num)
				} else {
					color.Printf("@{r}%s is not a integer\n", numError.Num)
				}
				continue loop
			case strconv.ErrRange:
				color.Printf("@{r}%s does not fit in %d bits\n", numError.Num, bits)
				continue loop
			default:
				color.Printf("@{r}Unknown error %s\n", numError)
				continue loop
			}
		}

		break loop
	}

	if unsigned {
		out = int64(iu)
	} else {
		out = i
	}

	return
}
开发者ID:ShaneHarro,项目名称:ultima1_save_editor,代码行数:57,代码来源:u1-save-editor.go


示例4: dumpResponse

// dump request , body true/false, print true/false
func dumpResponse(r *http.Response, b, p bool, host string) []byte {
	dump, err := httputil.DumpResponse(r, b)
	if err != nil {
		log.Println(err.Error())
	}
	// 	isGzip := false
	// 	if v, ok := r.Header["Accept-Encoding"]; ok {
	// 		if strings.Contains(v[0], "gzip") {
	// 			isGzip = true
	// 			log.Println("is gzip")
	// 		}
	// 	}
	if p {
		index := bytes.Index(dump, []byte("\r\n\r\n"))
		headers := dump[:index]
		body := bytes.TrimLeft(dump[index:], "\r\n\r\n")
		// 		body = bytes.TrimLeft(body, string([]byte{13, 10, 13, 10}))

		// 		if isGzip {
		// 			reader := bytes.NewReader(body)
		// 			g, err := gzip.NewReader(reader)
		// 			if err != nil {
		// 				log.Println(err.Error())
		// 			}
		// 			body, err = ioutil.ReadAll(g)
		// 			if err != nil {
		// 				log.Println(err.Error())
		// 			}
		// 		}
		if *veryverbose {
			now := time.Now()
			dirname := "/tmp/stfdump/" + host
			if _, err := os.Stat(dirname); err != nil {
				if err := os.MkdirAll(dirname, 0755); err != nil {
					log.Fatalln(err.Error())
				}
			}
			filename := fmt.Sprintf("%s/%d<", dirname, now.UnixNano())
			ioutil.WriteFile(filename, body, 0644)
		}
		if *colors {
			// 			color.Printf("@{b}%[email protected]{|}", string(dump))
			color.Printf("@{c}%[email protected]{|}\n", string(headers))
			if *showBody {
				color.Printf("@{g}%[email protected]{|}\n", string(body))
			}
			// 			color.Printf("@{g}%[email protected]{|}\n", ehex.EncodeToString(body))
			// 			color.Printf("@{g}%[email protected]{|}\n", body)
		} else {
			// 			fmt.Print(string(dump))
			fmt.Println(string(headers))
			fmt.Println(string(body))
		}
	}
	return dump
}
开发者ID:kiyor,项目名称:stf,代码行数:57,代码来源:main.go


示例5: reportFailWithDiff

func (self *Case) reportFailWithDiff(lhs, rhs interface{}) {
	if lhs != nil && rhs != nil {
		if s1, ok := lhs.(string); ok {
			s2 := rhs.(string)
			self.printDiff(s1, s2)
			return
		}
	}

	color.Printf("@[email protected]| expected @g%s = %[email protected]|\n", mustTypeName(lhs), lhs)
	color.Printf("@[email protected]|   actual @r%s = %[email protected]|\n", mustTypeName(rhs), rhs)
}
开发者ID:shitfSign,项目名称:akino,代码行数:12,代码来源:testing.go


示例6: query

func query(name, qtype string) {
	start := time.Now()
	qname, err := idna.ToASCII(name)
	if err != nil {
		color.Fprintf(os.Stderr, "Invalid IDN domain name: %s\n", name)
		os.Exit(1)
	}

	rrs, err := resolver.ResolveErr(qname, qtype)

	color.Printf("\n")
	if len(rrs) > 0 {
		color.Printf("@{g};; RESULTS:\n")
	}
	for _, rr := range rrs {
		color.Printf("@{g}%s\n", rr.String())
	}

	if err != nil {
		color.Printf("@{r};; %s\t%s\t%s\n", err, name, qtype)
	} else if rrs == nil {
		color.Printf("@{y};; NIL\t%s\t%s\n", name, qtype)
	} else if len(rrs) > 0 {
		color.Printf("@{g};; TRUE\t%s\t%s\n", name, qtype)
	} else {
		color.Printf("@{r};; FALSE\t%s\t%s\n", name, qtype)
	}

	color.Printf("@{.w};; Elapsed: %s\n", time.Since(start).String())
}
开发者ID:pages-alex-alex2006hw,项目名称:dnsr,代码行数:30,代码来源:main.go


示例7: reportFail

func (self *Case) reportFail(depth int, lhs, rhs interface{}, msg string, op int) {
	self.location(depth + 1)
	color.Printf("@[email protected]| FAIL %s\n", msg)

	switch op {
	case eq:
		fallthrough
	case throw:
		self.reportFailWithDiff(lhs, rhs)
	case ne:
		color.Printf("@[email protected]| expected @g%s = %[email protected]|\n", mustTypeName(lhs), lhs)
		color.Printf("@[email protected]|   but is @[email protected]|\n")
	}
	self.numFail++
}
开发者ID:shitfSign,项目名称:akino,代码行数:15,代码来源:testing.go


示例8: observeChannel

func observeChannel(resultRepository <-chan *github.Repository, networkErr <-chan error) (*github.Repository, error) {
	var repository *github.Repository
	var err error
getLoop:
	for {
		select {
		case repository = <-resultRepository:
			break getLoop
		case getErr := <-networkErr:
			fmt.Printf("\n\n")
			color.Printf("@{r} !!! Error Occuered !!! ")
			fmt.Printf("\n\n")
			fmt.Println(getErr)
			fmt.Printf("\n\n")
			break getLoop
		case <-time.After(time.Minute):
			fmt.Println(" @{r} !!! Timeout !!! ")
			break getLoop
		default:
			time.Sleep(time.Second / 2)
			fmt.Printf(".")
		}
	}
	return repository, err
}
开发者ID:kaz3439,项目名称:ghrepo,代码行数:25,代码来源:command.go


示例9: main

func main() {
	flag.Usage = func() {
		color.Fprintf(os.Stderr, "Usage: %s [arguments] <name> [type]\n\nAvailable arguments:\n", os.Args[0])
		flag.PrintDefaults()
		os.Exit(1)
	}
	flag.Parse()
	qtype := ""
	args := flag.Args()
	if len(args) == 0 {
		flag.Usage()
	} else if _, isType := dns.StringToType[args[len(args)-1]]; len(args) > 1 && isType {
		qtype, args = args[len(args)-1], args[:len(args)-1]
	}
	if verbose {
		dnsr.DebugLogger = os.Stderr
	}
	var wg sync.WaitGroup
	start := time.Now()
	for _, name := range args {
		wg.Add(1)
		go func(name string, qtype string) {
			query(name, qtype)
			wg.Done()
		}(name, qtype)
	}
	wg.Wait()
	if len(args) > 1 {
		color.Printf("\[email protected]{.w};; Total elapsed: %s\n", time.Since(start).String())
	}
}
开发者ID:pages-alex-alex2006hw,项目名称:dnsr,代码行数:31,代码来源:main.go


示例10: Update

// Update project details
// http://docs.gemnasium.apiary.io/#patch-%2Fprojects%2F%7Bslug%7D
func (p *Project) Update(name, desc *string, monitored *bool) error {
	if name == nil && desc == nil && monitored == nil {
		return errors.New("Please specify at least one thing to update (name, desc, or monitored")
	}

	update := make(map[string]interface{})
	if name != nil {
		update["name"] = *name
	}
	if desc != nil {
		update["desc"] = *desc
	}
	if monitored != nil {
		update["monitored"] = *monitored
	}
	opts := &gemnasium.APIRequestOptions{
		Method: "PATCH",
		URI:    fmt.Sprintf("/projects/%s", p.Slug),
		Body:   update,
	}
	err := gemnasium.APIRequest(opts)
	if err != nil {
		return err
	}

	color.Printf("@gProject %s updated succesfully\n", p.Slug)
	return nil
}
开发者ID:lisas1234,项目名称:toolbelt,代码行数:30,代码来源:project.go


示例11: Fail

func (self *Case) Fail() {
	self.location(2)
	color.Printf("@[email protected]| FAIL %s\n", self.what)
	self.what = ""
	self.numFail++
	panic(self)
}
开发者ID:shitfSign,项目名称:akino,代码行数:7,代码来源:testing.go


示例12: Printf

func (p *Printer) Printf(fmtstr string, args ...interface{}) {
	if p.NoColors {
		fmtstr = removeMeta.ReplaceAllLiteralString(fmtstr, "")
		fmt.Printf(fmtstr, args...)
	} else {
		color.Printf(fmtstr, args...)
	}
}
开发者ID:taliesinb,项目名称:goreplace,代码行数:8,代码来源:utils.go


示例13: SearchFile

func (v *GRVisitor) SearchFile(fn string, content []byte) {
	lines := IntList([]int{})
	binary := false

	if bytes.IndexByte(content, 0) != -1 {
		binary = true
	}

	for _, info := range v.FindAllIndex(content) {
		if lines.Contains(info.num) {
			continue
		}

		if v.prependNewLine {
			fmt.Println("")
			v.prependNewLine = false
		}

		first := len(lines) == 0
		lines = append(lines, info.num)

		if first {
			if binary && !*onlyName {
				fmt.Printf("Binary file %s matches\n", fn)
				break
			} else {
				color.Printf("@g%s\n", fn)
			}
		}

		if *onlyName {
			return
		}

		color.Printf("@[email protected]%d:", info.num)
		coloredLine := v.pattern.ReplaceAllStringFunc(string(info.line),
			func(wrap string) string {
				return color.Sprintf("@Y%s", wrap)
			})
		fmt.Printf("%s\n", coloredLine)
	}

	if len(lines) > 0 {
		v.prependNewLine = true
	}
}
开发者ID:jwhitlark,项目名称:goreplace,代码行数:46,代码来源:goreplace.go


示例14: doCreate

func doCreate(c *cli.Context) {
	name := c.Args().First()
	if len(name) == 0 {
		return
	}

	// check configuration
	configuration, err := OpenConfiguration()
	if err != nil {
		fmt.Println(err)
		return
	}
	if configuration.GithubToken == "" {
		configuration.GithubToken = PromptPersonalGithubToken()
		configuration.Persist()
	}

	// set repository attributes
	newRepository := github.Repository{Name: &name}
	prompt := c.Bool(flagDetail)
	if description := GetRepositryField(flagDesc, c.String(flagDesc), prompt).(string); description != "" {
		newRepository.Description = &description
	}
	if homepage := GetRepositryField(flagHP, c.String(flagHP), prompt).(string); homepage != "" {
		newRepository.Homepage = &homepage
	}
	if teamid := GetRepositryField(flagTeamID, c.Int(flagTeamID), prompt).(int); teamid != 0 {
		newRepository.TeamID = &teamid
	}
	private := GetRepositryField(flagPrivate, c.Bool(flagPrivate), prompt).(bool)
	newRepository.Private = &private
	issue := GetRepositryField(flagIssue, c.Bool(flagIssue), prompt).(bool)
	newRepository.HasIssues = &issue
	wiki := GetRepositryField(flagWiki, c.Bool(flagWiki), prompt).(bool)
	newRepository.HasWiki = &wiki
	download := GetRepositryField(flagDownload, c.Bool(flagDownload), prompt).(bool)
	newRepository.HasDownloads = &download

	// create repository
	org := c.String(flagOrg)
	client := NewClient(configuration)
	repository, _ := observeChannel(client.CreateRepository(org, &newRepository))
	if repository == nil {
		return
	}

	output := "\n\n" +
		"=========================\n" +
		"                         \n" +
		"@{g}* We are sccessful in Creating a repository! Push an existing repository from the command [email protected]{|}\n" +
		"                         \n" +
		"git remote add origin %s \n" +
		"git push -u origin master\n" +
		"                         \n" +
		"=========================\n" +
		"\n\n"
	color.Printf(output, *repository.GitURL)
}
开发者ID:kaz3439,项目名称:ghrepo,代码行数:58,代码来源:command.go


示例15: Printf

func (p *Printer) Printf(colorfmt, plainfmt string,
	args ...interface{}) {

	if p.NoColors {
		fmt.Printf(plainfmt, args...)
	} else {
		color.Printf(colorfmt, args...)
	}
}
开发者ID:sarum9in,项目名称:goreplace,代码行数:9,代码来源:utils.go


示例16: title

// define output in one place, make it clean
func title() {
	// use HOST as host check servicename
	// 	if *mutehost != "" {
	// 		color.Printf("%-10s: %v %-10v %v %v\n", "hostname", "alert", "state", "acked", "output")
	// 	}
	// 	if *muteservice != "" {
	color.Printf("%-10s: %-10v %v %-10v %v %v\n", "hostname", "srvname", "alert", "state", "acked", "output")
	// 	}
}
开发者ID:kiyor,项目名称:nagtool,代码行数:10,代码来源:main.go


示例17: val

func (self *Batch) val() interface{} {
	if self.index >= len(self.returnVals) {
		self.c.location(1)
		color.Printf("@[email protected]| FAIL: too many check values, max: %v\n", len(self.returnVals))
		self.c.numFail++
		panic(self.c)
	}
	return self.returnVals[self.index]
}
开发者ID:shitfSign,项目名称:akino,代码行数:9,代码来源:batch_check.go


示例18: Run

func (c *BalanceCommand) Run() error {
	user := &models.User{}
	user.Id = db.USERID
	amount, err := user.GetBalance()
	if err != nil {
		return err
	}
	color.Printf("@gBalance: %f\n", amount)
	return nil
}
开发者ID:4gophers,项目名称:karman-cli,代码行数:10,代码来源:balance_command.go


示例19: ReplaceInFile

func (v *GRVisitor) ReplaceInFile(fn string, content []byte) (changed bool, result []byte) {
	changed = false
	binary := false
	changenum := 0

	if *singleline {
		errhandle(
			fmt.Errorf("Can't handle singleline replacements yet"),
			true, "")
	}

	if *plaintext {
		errhandle(
			fmt.Errorf("Can't handle plain text replacements yet"),
			true, "")
	}

	if bytes.IndexByte(content, 0) != -1 {
		binary = true
	}

	result = v.pattern.ReplaceAllFunc(content, func(s []byte) []byte {
		if binary && !*force {
			errhandle(
				fmt.Errorf("supply --force to force change of binary file"),
				false, "")
		}
		if !changed {
			changed = true
			color.Printf("@g%s", fn)
		}

		changenum += 1
		return []byte(*replace)
	})

	if changenum > 0 {
		color.Printf("@[email protected] - %d change%s made\n",
			changenum, getSuffix(changenum))
	}

	return changed, result
}
开发者ID:jwhitlark,项目名称:goreplace,代码行数:43,代码来源:goreplace.go


示例20: smartPrintf

// uses color if availible
func smartPrintf(format string, a ...interface{}) (cnt int, err error) {
	pattern := regexp.MustCompile(`@.`)
	if useColor {
		cnt, err = color.Printf(format, a...)
	} else {
		rawFormat := pattern.ReplaceAll([]byte(format), []byte(""))
		cnt, err = fmt.Printf(string(rawFormat), a...)
	}
	return
}
开发者ID:johntdyer,项目名称:jira,代码行数:11,代码来源:jira.go



注:本文中的github.com/wsxiaoys/terminal/color.Printf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang color.Sprintf函数代码示例发布时间:2022-05-28
下一篇:
Golang color.Print函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap