本文整理汇总了Golang中github.com/wsxiaoys/terminal/color.Sprintf函数的典型用法代码示例。如果您正苦于以下问题:Golang Sprintf函数的具体用法?Golang Sprintf怎么用?Golang Sprintf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Sprintf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: bdd
func bdd(t *testing.T, lead string, args ...interface{}) {
var msg bytes.Buffer
fmt.Fprint(&msg, color.Sprintf("@{g}%s ", lead))
for i, each := range args {
if i%2 == 0 {
fmt.Fprint(&msg, color.Sprintf("@{g}%v ", each))
} else {
fmt.Fprint(&msg, color.Sprintf("@{m}%v ", each))
}
}
t.Log(msg.String())
}
开发者ID:idebruijn,项目名称:talks,代码行数:12,代码来源:bdd.go
示例2: getProjectIssues
func getProjectIssues(gitlab *gogitlab.Gitlab, projectId int) {
events := gitlab.ProjectEvents(projectId)
for _, event := range events {
var iconName string
switch event.TargetType {
case "Issue":
iconName = ":beer:"
default:
iconName = ":punch:"
}
//fmt.Printf("ProjectID[%d] action[%s] targetId[%d] targetType[%s] targetTitle[%s]\n", event.ProductId, event.ActionName,event.TargetId, event.TargetType, event.TargetTitle)
if event.TargetId != 0 {
actionText := color.Sprintf("@y[%s]", event.ActionName)
repositoriesText := color.Sprintf("@c%s(%d)", event.TargetType, event.TargetId)
userText := color.Sprintf("@c%s", event.Data.UserName)
titleText := color.Sprintf("@g%s", event.TargetTitle)
emoji.Println("@{"+iconName+"}", actionText, repositoriesText, userText, titleText)
} else if event.TargetId == 0 {
actionText := color.Sprintf("@y[%s]", event.ActionName)
repositoriesText := color.Sprintf("@c%s", event.Data.Repository.Name)
userText := color.Sprintf("@c%s", event.Data.UserName)
var titleText string
if event.Data.TotalCommitsCount > 0 {
commitMessage := event.Data.Commits[0].Message
commitMessage = strings.Replace(commitMessage, "\n\n", "\t", -1)
titleText = color.Sprintf("@g%s", commitMessage)
} else if event.Data.Before == "0000000000000000000000000000000000000000" {
titleText = color.Sprintf("@g%s %s", emoji.Sprint("@{:fire:}"), "create New branch")
}
emoji.Println("@{"+iconName+"}", actionText, repositoriesText, userText, titleText)
// fmt.Println(" \t user -> ", event.Data.UserName, event.Data.UserId)
// fmt.Println(" \t author -> ", event.Data.AuthorId)
//
// fmt.Println(" \t\t name -> ", event.Data.Repository.Name)
// fmt.Println(" \t\t description -> ", event.Data.Repository.Description)
// fmt.Println(" \t\t gitUrl -> ", event.Data.Repository.GitUrl)
// fmt.Println(" \t\t pageUrl -> ", event.Data.Repository.PageUrl)
//
// fmt.Println(" \t\t totalCount -> ", event.Data.TotalCommitsCount)
//
// if event.Data.TotalCommitsCount > 0 {
// fmt.Println(" \t\t message -> ", event.Data.Commits[0].Message)
// fmt.Println(" \t\t time -> ", event.Data.Commits[0].Timestamp)
// }
}
}
//
// for _, event := range events {
//
// }
}
开发者ID:kyokomi,项目名称:go-gitlab-notifer,代码行数:57,代码来源:go-gitlab-notifer.go
示例3: TODO
func TODO(t *testing.T, comment string, args ...interface{}) {
if PrintColorsEnabled {
t.Log(append(append([]interface{}{}, fmt.Sprintf(" ")+color.Sprintf("@{R}%s", "TODO:"+" "+comment)), args...)...)
} else {
t.Log(append(append([]interface{}{}, "Comment:"+" "+comment), args...)...)
}
}
开发者ID:idebruijn,项目名称:bddl,代码行数:7,代码来源:bddl.go
示例4: ColoredPrintf
// ColoredPrintf does printf in colored way + newline
func (p *Progress) ColoredPrintf(msg string, a ...interface{}) {
if RunningOnTerminal() {
p.queue <- printTask{code: codePrint, message: color.Sprintf(msg, a...) + "\n"}
} else {
// stip color marks
var prev rune
msg = strings.Map(func(r rune) rune {
if prev == '@' {
prev = 0
if r == '@' {
return r
}
return -1
}
prev = r
if r == '@' {
return -1
}
return r
}, msg)
p.Printf(msg+"\n", a...)
}
}
开发者ID:hdonnay,项目名称:aptly,代码行数:27,代码来源:progress.go
示例5: Sprintf
func (p *Printer) Sprintf(fmtstr string, args ...interface{}) string {
if p.NoColors {
fmtstr = removeMeta.ReplaceAllLiteralString(fmtstr, "")
return fmt.Sprintf(fmtstr, args...)
} else {
return color.Sprintf(fmtstr, args...)
}
}
开发者ID:taliesinb,项目名称:goreplace,代码行数:8,代码来源:utils.go
示例6: Scolorf
// Scolorf returns a string colorized for terminal output using the syntaxCode (unless that's empty).
// Requires the syntax defined on https://github.com/wsxiaoys/terminal/blob/master/color/color.go .
func Scolorf(syntaxCode string, format string, args ...interface{}) string {
plainFormatted := fmt.Sprintf(format, args...)
if len(syntaxCode) > 0 && TerminalColorsEnabled {
// cannot pass the code as a string param
return color.Sprintf(syntaxCode+"%s%s", FailMessagePrefix, plainFormatted)
}
return FailMessagePrefix + plainFormatted
}
开发者ID:hackintoshrao,项目名称:forest,代码行数:10,代码来源:error_color.go
示例7: Scolorf
// Scolorf returns a string colorized for terminal output using the syntaxCode (unless that's empty).
// Requires the syntax defined on https://github.com/wsxiaoys/terminal/blob/master/color/color.go .
func Scolorf(syntaxCode string, format string, args ...interface{}) string {
plainFormatted := fmt.Sprintf(format, args...)
if len(syntaxCode) > 0 && AssertColorsEnabled {
// cannot pass the code as a string param
return color.Sprintf(syntaxCode+"%s", plainFormatted)
}
return plainFormatted
}
开发者ID:idebruijn,项目名称:assert,代码行数:10,代码来源:error_color.go
示例8: 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
示例9: Sprintf
func (p *Printer) Sprintf(colorfmt, plainfmt string,
args ...interface{}) string {
if p.NoColors {
return fmt.Sprintf(plainfmt, args...)
} else {
return color.Sprintf(colorfmt, args...)
}
}
开发者ID:sarum9in,项目名称:goreplace,代码行数:9,代码来源:utils.go
示例10: SearchFileName
func (v *GRVisitor) SearchFileName(fn string) {
if !v.pattern.MatchString(fn) {
return
}
colored := v.pattern.ReplaceAllStringFunc(fn,
func(wrap string) string {
return color.Sprintf("@Y%s", wrap)
})
fmt.Println(colored)
}
开发者ID:vigneshsarma,项目名称:goreplace,代码行数:10,代码来源:goreplace.go
示例11: ServeHTTP
func (s *LoggingServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
s.mu.RLock()
defer s.mu.RUnlock()
if i := sort.SearchStrings(s.ExcludePaths, req.URL.Path); i < len(s.ExcludePaths) && req.URL.Path == s.ExcludePaths[i] {
return
}
req.ParseForm()
// Log request
var data string
for key, _ := range req.Form {
data += "\n "
if value := req.Form.Get(key); value != "" {
data += color.Sprintf("@.%[email protected]|@w = @|%s", key, value)
} else {
data += color.Sprintf("%s", key)
}
}
log.Print(color.Sprintf("@c%s @{!y}%s", req.Method, req.RequestURI))
if data != "" {
color.Printf(" @[email protected]|%s\n", data)
}
// Find matcher
matcher := s.findMatcher(req)
if matcher != nil {
matcher.Write(w, req)
// TODO Better response logging
response := matcher.Response
color.Printf(" @[email protected]|\n %+v\n", response)
} else {
color.Print(" @[email protected]|\n")
w.WriteHeader(http.StatusNotFound)
w.Header().Set("Content-Type", "text/html")
io.WriteString(w, "<html><body>Unmatched request, please configure a mock request for path "+req.URL.Path+" and method "+req.Method+"</body></html>\n")
}
}
开发者ID:hlubek,项目名称:logging-server,代码行数:42,代码来源:server.go
示例12: 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
示例13: TestUpdateProject
func TestUpdateProject(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r.Header.Set("Content-Type", "application/json")
jsonOutput :=
`{
"slug": "gemnasium/API_project",
"name: "API_project",
"description": "This is a brief description of a project on Gemnasium"
"origin": "github",
"private": false,
"color": "green",
"monitored": true,
"unmonitored_reason": ""
}`
fmt.Fprintln(w, jsonOutput)
}))
defer ts.Close()
old := os.Stdout // keep backup of the real stdout
r, w, _ := os.Pipe()
os.Stdout = w
config.APIEndpoint = ts.URL
var name, desc *string
var monitored *bool
nameStr := "API_project"
name = &nameStr
descStr := "A desc"
desc = &descStr
monitoredBool := false
monitored = &monitoredBool
p := &Project{Slug: "blah"}
err := p.Update(name, desc, monitored)
if err != nil {
t.Fatal(err)
}
w.Close()
var buf bytes.Buffer
io.Copy(&buf, r)
os.Stdout = old // restoring the real stdout
expectedOutput := color.Sprintf("@gProject %s updated succesfully\n", "blah")
if buf.String() != expectedOutput {
t.Errorf("Expected ouput:\n%s\n\nGot:\n%s", expectedOutput, buf.String())
}
}
开发者ID:lisas1234,项目名称:toolbelt,代码行数:44,代码来源:project_test.go
示例14: createFeedCommentText
// 絵文字付きターミナル用のコメント作成(Activiyベース)
func createFeedCommentText(currentUser *gogitlab.User, feedCommit *gogitlab.FeedCommit) string {
var iconName string
if strings.Contains(feedCommit.Title, "commented") {
iconName = ":speech_balloon:"
} else if strings.Contains(feedCommit.Title, "pushed") {
iconName = ":punch:"
} else if strings.Contains(feedCommit.Title, "closed") {
iconName = ":white_check_mark:"
} else if strings.Contains(feedCommit.Title, "opened") {
iconName = ":fire:"
} else if strings.Contains(feedCommit.Title, "accepted") {
iconName = ":atm:"
} else {
iconName = ":beer:"
}
if currentUser.Name == feedCommit.Author.Name {
return emoji.Sprint("@{"+iconName+"}", color.Sprintf("@y[%s] %s", feedCommit.Updated.Format(time.ANSIC), feedCommit.Title))
} else {
return emoji.Sprint("@{"+iconName+"}", fmt.Sprintf("[%s] %s", feedCommit.Updated.Format(time.ANSIC), feedCommit.Title))
}
}
开发者ID:kyokomi,项目名称:go-gitlab-notifer,代码行数:24,代码来源:go-gitlab-notifer.go
示例15: ColoredPrintf
// ColoredPrintf does printf in colored way + newline
func (p *Progress) ColoredPrintf(msg string, a ...interface{}) {
if RunningOnTerminal() {
p.queue <- printTask{code: codePrint, message: color.Sprintf(msg, a...) + "\n"}
} else {
// stip color marks
var inColorMark, inCurly bool
msg = strings.Map(func(r rune) rune {
if inColorMark {
if inCurly {
if r == '}' {
inCurly = false
inColorMark = false
return -1
}
} else {
if r == '{' {
inCurly = true
} else if r == '@' {
return '@'
} else {
inColorMark = false
}
}
return -1
}
if r == '@' {
inColorMark = true
return -1
}
return r
}, msg)
p.Printf(msg+"\n", a...)
}
}
开发者ID:liftup,项目名称:aptly,代码行数:38,代码来源:progress.go
示例16: Panicf
// Panicf is equivalent to Printf() followed by a call to panic().
func Panicf(format string, v ...interface{}) {
s := color.Sprintf(format, v...)
std.Output(2, s)
panic(s)
}
开发者ID:kdar,项目名称:clog,代码行数:6,代码来源:clog.go
示例17: bluePrint
func bluePrint(text string) string {
return color.Sprintf("@b%s", text)
}
开发者ID:k0kubun,项目名称:rockstar,代码行数:3,代码来源:color.go
示例18: yellowPrint
func yellowPrint(text string) string {
return color.Sprintf("@y%s", text)
}
开发者ID:k0kubun,项目名称:rockstar,代码行数:3,代码来源:color.go
示例19: greenPrint
func greenPrint(text string) string {
return color.Sprintf("@g%s", text)
}
开发者ID:k0kubun,项目名称:rockstar,代码行数:3,代码来源:color.go
示例20: redPrint
func redPrint(text string) string {
return color.Sprintf("@r%s", text)
}
开发者ID:k0kubun,项目名称:rockstar,代码行数:3,代码来源:color.go
注:本文中的github.com/wsxiaoys/terminal/color.Sprintf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论