-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbanner.go
64 lines (52 loc) · 1.41 KB
/
banner.go
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package procyon
import (
"codnect.io/logy"
"codnect.io/procyon/component"
"codnect.io/procyon/component/filter"
"codnect.io/procyon/runtime"
"errors"
"fmt"
"io"
)
var (
bannerText = []string{
" ___ _______ ______ _____ ___\n",
" / _ \\/ __/ _ / __/ // / _ \\/ _ \\\n",
" / .__/_/ \\___\\__/\\_, /\\___/_//_/\n",
"/_/ /___/\n",
}
)
type bannerPrinter struct {
}
func newBannerPrinter() *bannerPrinter {
return &bannerPrinter{}
}
func (p *bannerPrinter) PrintBanner(w io.Writer) error {
for _, line := range bannerText {
if logy.SupportsColor() {
w.Write([]byte(fmt.Sprintf("\u001B[34;1m%s\u001B[0m", line)))
} else {
w.Write([]byte(line))
}
}
if logy.SupportsColor() {
w.Write([]byte(fmt.Sprintf("\u001B[93m%24s%s)\u001B[0m\n", "(", Version)))
} else {
w.Write([]byte(fmt.Sprintf("%24s%s)\n", "(", Version)))
}
return nil
}
func resolveBanner() (runtime.Banner, error) {
bannerPrinters := component.List(filter.ByTypeOf[runtime.Banner]())
if len(bannerPrinters) > 1 {
return nil, errors.New("banners cannot be distinguished because too many matching found")
} else if len(bannerPrinters) == 1 {
constructor := bannerPrinters[0].Definition().Constructor()
banner, err := constructor.Invoke()
if err != nil {
return nil, fmt.Errorf("banner is not initialized, error: %e", err)
}
return banner[0].(runtime.Banner), nil
}
return newBannerPrinter(), nil
}