本文整理匯總了Golang中github.com/fatih/color.Unset函數的典型用法代碼示例。如果您正苦於以下問題:Golang Unset函數的具體用法?Golang Unset怎麽用?Golang Unset使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Unset函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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)
}
示例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
}
}
示例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()
}
示例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...)
}
}
示例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
}
示例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
}
}
示例7: debugResponse
func debugResponse(res *http.Response) {
if debug {
color.Set(color.FgCyan)
doDebug(httputil.DumpResponse(res, true))
color.Unset()
}
}
示例8: debugRequest
func debugRequest(req *http.Request) {
if debug {
color.Set(color.FgMagenta)
doDebug(httputil.DumpRequestOut(req, true))
color.Unset()
}
}
示例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
}
}
示例10: printResult
func printResult(message string, c color.Attribute) {
print("[")
color.Set(c)
print(message)
color.Unset()
println("]")
}
示例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)
}
示例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()
}
}
示例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()
}
}
}
示例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)
}
示例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()
}