-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathout_terminal.go
More file actions
37 lines (33 loc) · 849 Bytes
/
out_terminal.go
File metadata and controls
37 lines (33 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"github.com/fatih/color"
"fmt"
"log"
"text/template"
"bytes"
)
func OutputToTerminal(pokemon PokemonMeta, config Config) {
if config.Format != "" {
formatTemplate := template.New("format")
_, err := formatTemplate.Parse(config.Format)
if err != nil {
log.Fatalln(err)
}
var output bytes.Buffer
err = formatTemplate.Execute(&output, pokemon)
if err != nil {
log.Fatalln(err)
}
fmt.Println(output.String())
} else {
// Ignore the ugliness :)
color.New(color.Bold).Print(pokemon.Name)
color.New().Print(" (")
color.New(color.FgBlue, color.Underline).Printf("%v", pokemon.URL)
color.New().Print(")")
fmt.Println()
color.New().Printf("%vm away from %v\n", pokemon.Distance, pokemon.Location)
color.New().Printf("Expires in %v\n", HumanTime(pokemon.ExpiresAt))
fmt.Println()
}
}