-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.go
61 lines (52 loc) · 1.18 KB
/
util.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
package main
import (
"fmt"
"os"
"strings"
"unicode/utf8"
"github.com/fatih/color"
"github.com/kyokomi/emoji"
"github.com/pkg/errors"
"golang.org/x/crypto/ssh/terminal"
)
var (
up = emoji.Sprint(":up_arrow:")
down = emoji.Sprint(":down_arrow:")
left = emoji.Sprint(":left_arrow:")
right = emoji.Sprint(":right_arrow:")
)
func fail(err ...interface{}) {
fmt.Println(err...)
os.Exit(1)
}
func termArea() (area int) {
w, h, _ := terminal.GetSize(int(os.Stdout.Fd()))
return w * h
}
func toColor(txt string, attr color.Attribute, override color.Attribute) string {
c := color.New(color.Reset)
if override == color.Concealed {
attr = override
}
switch attr {
case color.Concealed:
c.Set().Add(color.FgWhite, color.Concealed, color.Faint)
case color.Reset:
c.Set().Add(color.FgHiWhite)
case color.FgRed:
c.Set().Add(color.FgHiRed)
case color.FgGreen:
c.Set().Add(color.FgHiGreen)
default:
c.Set().Add(attr)
}
return c.SprintFunc()(txt)
}
func padding(txt string, val int) string {
l := utf8.RuneCountInString(txt)
if val-l < 0 {
err := errors.Errorf("Negative repeat count (%d) for [%s]", val-l, txt)
panic(err)
}
return strings.Repeat(" ", val-l)
}