本文整理汇总了Golang中github.com/fatih/color.Unset函数的典型用法代码示例。如果您正苦于以下问题:Golang Unset函数的具体用法?Golang Unset怎么用?Golang Unset使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Unset函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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)
}
开发者ID:Skarlso,项目名称:goprogressquest,代码行数:33,代码来源:player.go
示例2: 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
}
}
开发者ID:godwhoa,项目名称:urban,代码行数:27,代码来源:main.go
示例3: 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()
}
开发者ID:cjauvin,项目名称:kamisado-go,代码行数:48,代码来源:cli.go
示例4: 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...)
}
}
开发者ID:kevgathuku,项目名称:frodo,代码行数:28,代码来源:logger.go
示例5: 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
}
开发者ID:re-pe,项目名称:go-phpApps,代码行数:60,代码来源:defs.go
示例6: 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
}
}
开发者ID:FriendzoneTeam,项目名称:Gospel,代码行数:25,代码来源:new.go
示例7: debugResponse
func debugResponse(res *http.Response) {
if debug {
color.Set(color.FgCyan)
doDebug(httputil.DumpResponse(res, true))
color.Unset()
}
}
开发者ID:pilwon,项目名称:go-smugmug,代码行数:7,代码来源:debug.go
示例8: debugRequest
func debugRequest(req *http.Request) {
if debug {
color.Set(color.FgMagenta)
doDebug(httputil.DumpRequestOut(req, true))
color.Unset()
}
}
开发者ID:pilwon,项目名称:go-smugmug,代码行数:7,代码来源:debug.go
示例9: write
// returns a function that will format and writes the line extracted from the logs of a given container
func write(prefix string, color *ansi.Color, timestamps bool) func(dest io.Writer, token []byte) (n int, err error) {
return func(dest io.Writer, token []byte) (n int, err error) {
countingWriter := countingWriter{Writer: dest}
if color != nil {
ansi.Output = &countingWriter
color.Set()
}
_, err = countingWriter.Write([]byte(prefix))
if err == nil {
if !timestamps {
// timestamps are always present in the incoming stream for
// sorting purposes, so we strip them if the user didn't ask
// for them
const timestampPrefixLength = 31
strip := timestampPrefixLength
if string(token[0]) == "[" {
// it seems that timestamps are wrapped in [] for events
// streamed in real time during a `docker logs -f`
strip = strip + 2
}
token = token[strip:]
}
_, err = countingWriter.Write(token)
}
if err == nil {
if color != nil {
ansi.Unset()
}
_, err = dest.Write([]byte("\n"))
}
return countingWriter.written, err
}
}
开发者ID:bcicen,项目名称:crane,代码行数:35,代码来源:containers.go
示例10: printResult
func printResult(message string, c color.Attribute) {
print("[")
color.Set(c)
print(message)
color.Unset()
println("]")
}
开发者ID:yext,项目名称:edward,代码行数:7,代码来源:operation.go
示例11: 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)
}
开发者ID:Skarlso,项目名称:goprogressquest,代码行数:8,代码来源:player.go
示例12: OutputTests
func OutputTests() {
for _, test := range tests {
fmt.Printf("%s: expected ", test.function)
if len(test.attributes) > 0 {
color.Set(test.attributes...)
}
fmt.Print(test.expected)
if len(test.attributes) > 0 {
color.Unset()
}
fmt.Print(", actual ")
switch test.function {
case "Debug":
Debug(test.input...)
case "Log":
Log(test.input...)
fmt.Print("\nFor output, look at file ", logFileName)
case "Print":
Print(test.input...)
case "Out":
Out(test.input...)
fmt.Print("\nFor other output, look at file ", logFileName)
}
fmt.Println()
}
}
开发者ID:re-pe,项目名称:go-output,代码行数:27,代码来源:test.go
示例13: 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()
}
}
}
开发者ID:nakaji-s,项目名称:goyamldiff,代码行数:27,代码来源:main.go
示例14: Write
// Write is used for writing to predefined output using
// foreground color we want.
func (c *context) Write(p []byte) (n int, err error) {
// Set the color that has been registered for this logger.
c.c.Set()
defer color.Unset() // Don't forget to stop using after we're done.
// Write the result to writer.
return c.w.Write(p)
}
开发者ID:gocore,项目名称:goal,代码行数:10,代码来源:log.go
示例15: writeError
func writeError(format string, err error, a ...interface{}) {
color.Set(color.FgRed)
fmt.Fprintf(os.Stderr, format+"\n", a...)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
color.Unset()
}
开发者ID:getcarina,项目名称:dvm,代码行数:8,代码来源:util.go
示例16: askAmount
// Ask the amount of the selected ingredient
func (b *bread) askAmount(starter string) int {
color.Set(color.FgWhite)
fmt.Printf("Enter the amount of %s in grams: ", starter)
color.Unset()
var amount, _ = b.reader.ReadString('\n')
var intAmount, err = strconv.Atoi(strings.TrimSpace(amount))
if err != nil {
color.Set(color.FgRed)
fmt.Println("Wrong amount. Try again!")
color.Unset()
return b.askAmount(starter)
}
return intAmount
}
开发者ID:fadion,项目名称:GoBread,代码行数:18,代码来源:bread.go
示例17: sshKeysHelp
func sshKeysHelp() {
color.Set(color.FgYellow)
print("")
print("a - Add")
print("D - Delete")
print("? - Help")
print("b - Back")
color.Unset()
}
开发者ID:daveadams,项目名称:vaulted,代码行数:9,代码来源:edit.go
示例18: variableMenu
func variableMenu() {
color.Set(color.FgYellow)
print("")
print("a - Add")
print("D - Delete")
print("? - Help")
print("b - Back")
color.Unset()
}
开发者ID:daveadams,项目名称:vaulted,代码行数:9,代码来源:edit.go
示例19: displayRSS
func displayRSS(items []Item) {
for i, item := range items {
index := i + 1
color.Set(color.FgRed)
fmt.Printf("%2d.", index)
color.Unset()
fmt.Printf(" %s\n", item.Title)
}
}
开发者ID:sspencer,项目名称:go-hn,代码行数:9,代码来源:hn.go
示例20: Print
func Print(args ...interface{}) {
formated := Format(args...)
if len(formated.Attributes) > 0 {
color.Set(formated.Attributes...)
}
fmt.Print(formated.Text)
if len(formated.Attributes) > 0 {
color.Unset()
}
}
开发者ID:re-pe,项目名称:go-output,代码行数:10,代码来源:output.go
注:本文中的github.com/fatih/color.Unset函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论