本文整理匯總了Golang中github.com/fatih/color.Set函數的典型用法代碼示例。如果您正苦於以下問題:Golang Set函數的具體用法?Golang Set怎麽用?Golang Set使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Set函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: log
// all logging functions call this `log` function
func (console *Logger) log(d logDetails, colorAttr color.Attribute, isBold bool, format string, args ...interface{}) {
// Only print out, logs that are the selected level or higher
if console.level >= d.level {
newlog := color.Set(colorAttr)
defer color.Unset()
// if the request is to log bold text
if isBold {
newlog.Add(color.Bold)
}
// Check to see if we are to add background color
// Alert and Fatal have background colors
switch d.level {
case 1: // for Fatal
color.Set(color.BgRed)
break
case 2: // for Alerts
color.Set(color.BgMagenta)
break
}
// I want it log both into the file and on the console
console.LogFile.Printf(format, args...)
log.Printf(format, args...)
}
}
示例2: printDiffYaml
func printDiffYaml(m map[interface{}]interface{}, indent string) {
sortedMap := make([]string, len(m))
i := 0
for k, _ := range m {
sortedMap[i] = k.(string)
i++
}
sort.Strings(sortedMap)
for _, v := range sortedMap {
key := v
value := m[key]
if reflect.TypeOf(value).Kind() == reflect.Map {
println(indent + key + ":")
printDiffYaml(m[key].(map[interface{}]interface{}), indent+" ")
} else {
tmp := value.(Comparer)
println(indent + key + ":")
color.Set(color.FgRed)
printValue(tmp.leftValue, indent+" - ")
color.Set(color.FgGreen)
printValue(tmp.rightValue, indent+" + ")
color.Unset()
}
}
}
示例3: print
func (r Results) print(limit int) {
i := 0
if r.ResultType == "exact" {
for _, def := range r.List {
if limit == -1 || i < limit {
// ugly code for windows!
color.Set(color.FgBlue)
fmt.Printf("%d)\n", i+1)
color.Unset()
color.Set(color.FgGreen)
fmt.Printf("%s\n", "Def:")
color.Unset()
fmt.Println(def.Definition)
color.Set(color.FgGreen)
fmt.Printf("%s\n", "Eg:")
color.Unset()
fmt.Printf("%s\n\n", def.Example)
i++
}
}
} else {
color.Red("No definitions.\n")
return
}
}
示例4: showTweets
func showTweets(tweets []Tweet, verbose bool) {
if verbose {
for i := len(tweets) - 1; i >= 0; i-- {
name := tweets[i].User.Name
user := tweets[i].User.ScreenName
text := tweets[i].Text
text = replacer.Replace(text)
color.Set(color.FgHiRed)
fmt.Println(user + ": " + name)
color.Set(color.Reset)
fmt.Println(" " + text)
fmt.Println(" " + tweets[i].Identifier)
fmt.Println(" " + tweets[i].CreatedAt)
fmt.Println()
}
} else {
for i := len(tweets) - 1; i >= 0; i-- {
user := tweets[i].User.ScreenName
text := tweets[i].Text
color.Set(color.FgHiRed)
fmt.Print(user)
color.Set(color.Reset)
fmt.Print(": ")
fmt.Println(text)
}
}
}
示例5: Attack
// Attack an enemy during an encounter.
func (c *Character) Attack(e Enemy) {
// Fight until enemy is dead, or player is below 25%.
red := color.New(color.FgRed, color.Bold).SprintFunc()
log.Printf("Attacking enemy: %s\n", red(e.Name))
playerHpLimit := int(float64(c.Hp) * 0.25)
playerDamage := c.Body.Weapond.Dmg - e.Armor
if playerDamage <= 0 {
playerDamage = 1
}
enemyDamage := e.Damage - (c.Body.Head.Armor + c.Body.Armor.Armor + c.Body.Shield.Armor + c.Body.LRing.Armor + c.Body.RRing.Armor)
if enemyDamage <= 0 {
enemyDamage = 1
}
for c.Hp > playerHpLimit && e.Hp > 0 {
e.Hp -= playerDamage
c.Hp -= enemyDamage
}
if e.Hp <= 0 {
color.Set(color.FgCyan)
log.Println("Player won!")
color.Unset()
c.CurrentXp += e.Xp
displayProgressBar(c.CurrentXp, c.NextLevelXp)
c.awardItems(e)
mdb.Update(*c)
return
}
color.Set(color.FgHiRed)
log.Println("Enemy won. Player has fled with hp: ", c.Hp)
color.Unset()
mdb.Update(*c)
}
示例6: showTweets
func showTweets(tweets []Tweet, verbose bool) {
if *asjson {
for _, tweet := range tweets {
json.NewEncoder(os.Stdout).Encode(tweet)
os.Stdout.Sync()
}
} else if verbose {
for i := len(tweets) - 1; i >= 0; i-- {
name := tweets[i].User.Name
user := tweets[i].User.ScreenName
text := tweets[i].Text
text = replacer.Replace(text)
color.Set(color.FgHiRed)
fmt.Println(user + ": " + name)
color.Set(color.Reset)
fmt.Println(" " + text)
fmt.Println(" " + tweets[i].Identifier)
fmt.Println(" " + tweets[i].CreatedAt)
fmt.Println()
}
} else {
for i := len(tweets) - 1; i >= 0; i-- {
user := tweets[i].User.ScreenName
text := tweets[i].Text
color.Set(color.FgHiRed)
fmt.Print(user)
color.Set(color.Reset)
fmt.Print(": ")
fmt.Println(text)
}
}
}
示例7: sendSMS
func sendSMS(dev *gsmmodem.Device, message string, phoneNumber string) {
defer color.Unset()
log.Printf("Отправка сообщения на номер: %s\n", phoneNumber)
err := dev.SendLongSMS(message, sms.PhoneNumber(phoneNumber))
if err != nil {
color.Set(color.FgHiRed)
log.Printf("Ошибка отправки сообщения: %s\n", err.Error())
} else {
color.Set(color.FgHiGreen)
log.Printf("Сообщение отправлено на номер: " + phoneNumber)
}
}
示例8: printBoard
func (state *state) printBoard() {
board := state.board
fmt.Println()
fmt.Print(" ")
for _, c := range "abcdefgh" {
fmt.Print(fmt.Sprintf("%c ", c))
}
fmt.Println()
for i := 0; i < N; i++ {
for k := 0; k < 3; k++ {
if k == 1 {
fmt.Print(fmt.Sprintf(" %d", N-i))
} else {
fmt.Print(" ")
}
for j := 0; j < N; j++ {
cp := colors[boardColors[i][j]]
color.Set(cp.bg)
fmt.Print(" ")
piece := board[i][j]
if k == 1 && piece != nil {
color.Unset()
color.Set(colors[piece.Color].fg)
if piece.Player == humanPlayer {
fmt.Print("X")
} else {
fmt.Print("O")
}
} else {
fmt.Print(" ")
}
color.Set(cp.bg)
fmt.Print(" ")
}
color.Unset()
if k == 1 {
fmt.Print(N - i)
}
fmt.Println()
}
}
fmt.Print(" ")
for _, c := range "abcdefgh" {
fmt.Print(fmt.Sprintf("%c ", c))
}
fmt.Println()
fmt.Println()
}
示例9: Rest
// Rest will Replenish Health.
func (c *Character) Rest() {
c.Hp = c.MaxHp
color.Set(color.FgBlue)
log.Println("Player is fully rested.")
color.Unset()
mdb.Update(*c)
}
示例10: Select
func (selector *Selector) Select() (err error) {
var choice int
var input string
retValue := selector.ConfKeeper.Get(bConfList)
err = retValue.Error
if err != nil {
return
}
lenConfList := len(retValue.Value.([]interface{}))
err = fmt.Errorf("")
stdin := bufio.NewReader(os.Stdin)
for err != nil {
err = selector.OutputChoices()
if err != nil {
return
}
_, err = fmt.Scanf("%s", &input)
stdin.ReadString('\n')
if err != nil {
Out("Error:", err.Error(), "\n\n")
Out("\n", bigseparator, "\n\n")
continue
}
input = strings.TrimSpace(input)
var outputColor color.Attribute
switch input {
case "q", "--":
choice = -1
err = nil
default:
choice, err = strconv.Atoi(input)
if err != nil {
outputColor = color.FgRed
err = fmt.Errorf("Your input is not integer number or code to exit!")
}
}
if err == nil {
switch {
case choice < -1 || choice >= lenConfList:
outputColor = color.FgMagenta
err = fmt.Errorf("%d is out of range [ -1, %d ]!", choice, lenConfList-1)
default:
outputColor = color.FgCyan
err = nil
}
}
Out("\nYou selected ")
color.Set(outputColor, color.Bold)
Out(input)
color.Unset()
Out(".\n\n")
if err != nil {
Out(err.Error(), "\n")
Out("\n", bigseparator, "\n\n")
}
}
err = selector.ConfKeeper.Set(bSelected, strconv.Itoa(choice)).Error
return
}
示例11: exec
func exec(cmd *cobra.Command, args []string) {
if len(args) == 1 {
color.Green("Creando nueva aplicacion " + args[0])
gopath := os.Getenv("GOPATHs")
if gopath == "" {
color.Set(color.FgRed)
defer color.Unset()
log.Fatalln("GOPATH no found :(")
os.Exit(2)
}
src := fmt.Sprintf("%s\\src", gopath)
appName := args[0]
appDir := fmt.Sprintf("%s\\%s", src, appName)
createAppFolder(appDir, []string{})
fmt.Printf("appDir: %s\n", appDir)
createAppFolder(fmt.Sprintf("%s\\%s", appDir, "public"), []string{"assets"})
createAppFolder(fmt.Sprintf("%s\\%s", appDir, "app"), []string{"controllers", "models"})
createSubFolder(fmt.Sprintf("%s\\%s\\%s", appDir, "public", "assets"), []string{"js", "scss", "img", "fonts"})
// creamos la estructura basica
}
}
示例12: debugResponse
func debugResponse(res *http.Response) {
if debug {
color.Set(color.FgCyan)
doDebug(httputil.DumpResponse(res, true))
color.Unset()
}
}
示例13: debugRequest
func debugRequest(req *http.Request) {
if debug {
color.Set(color.FgMagenta)
doDebug(httputil.DumpRequestOut(req, true))
color.Unset()
}
}
示例14: TestIndentConnects
func TestIndentConnects(t *testing.T) {
source := readFileToSlice("./tests_data/source_indentConnects.cpp")
result := readFileToSlice("./tests_data/result_indentConnects.cpp")
indentConnects(source)
for i, line := range source {
if line != result[i] {
color.Set(color.FgYellow)
fmt.Printf("\nTheses lines are different: \n%s\n%s\n\n", line, result[i])
color.Set(color.FgRed)
t.FailNow()
color.Unset()
}
}
}
示例15: printResult
func printResult(message string, c color.Attribute) {
print("[")
color.Set(c)
print(message)
color.Unset()
println("]")
}