-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
format.go
96 lines (84 loc) · 3.03 KB
/
format.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package format
import (
"fmt"
"strings"
"github.com/fatih/color"
"github.com/lunixbochs/vtclean"
)
const (
// selectedLeftBracketStr = " "
// selectedRightBracketStr = " "
// selectedFillStr = " "
//
//leftBracketStr = "▏"
//rightBracketStr = "▕"
//fillStr = "─"
// selectedLeftBracketStr = " "
// selectedRightBracketStr = " "
// selectedFillStr = "━"
//
//leftBracketStr = "▏"
//rightBracketStr = "▕"
//fillStr = "─"
selectedLeftBracketStr = "┃"
selectedRightBracketStr = "┣"
selectedFillStr = "━"
leftBracketStr = "│"
rightBracketStr = "├"
fillStr = "─"
selectStr = " ● "
// selectStr = " "
)
var (
Header func(...interface{}) string
Selected func(...interface{}) string
StatusSelected func(...interface{}) string
StatusNormal func(...interface{}) string
StatusControlSelected func(...interface{}) string
StatusControlNormal func(...interface{}) string
CompareTop func(...interface{}) string
CompareBottom func(...interface{}) string
)
func init() {
Selected = color.New(color.ReverseVideo, color.Bold).SprintFunc()
Header = color.New(color.Bold).SprintFunc()
StatusSelected = color.New(color.BgMagenta, color.FgWhite).SprintFunc()
StatusNormal = color.New(color.ReverseVideo).SprintFunc()
StatusControlSelected = color.New(color.BgMagenta, color.FgWhite, color.Bold).SprintFunc()
StatusControlNormal = color.New(color.ReverseVideo, color.Bold).SprintFunc()
CompareTop = color.New(color.BgMagenta).SprintFunc()
CompareBottom = color.New(color.BgGreen).SprintFunc()
}
func RenderNoHeader(width int, selected bool) string {
if selected {
return strings.Repeat(selectedFillStr, width)
}
return strings.Repeat(fillStr, width)
}
func RenderHeader(title string, width int, selected bool) string {
if selected {
body := Header(fmt.Sprintf("%s%s ", selectStr, title))
bodyLen := len(vtclean.Clean(body, false))
repeatCount := width - bodyLen - 2
if repeatCount < 0 {
repeatCount = 0
}
return fmt.Sprintf("%s%s%s%s\n", selectedLeftBracketStr, body, selectedRightBracketStr, strings.Repeat(selectedFillStr, repeatCount))
// return fmt.Sprintf("%s%s%s%s\n", Selected(selectedLeftBracketStr), body, Selected(selectedRightBracketStr), Selected(strings.Repeat(selectedFillStr, width-bodyLen-2)))
// return fmt.Sprintf("%s%s%s%s\n", Selected(selectedLeftBracketStr), body, Selected(selectedRightBracketStr), strings.Repeat(selectedFillStr, width-bodyLen-2))
}
body := Header(fmt.Sprintf(" %s ", title))
bodyLen := len(vtclean.Clean(body, false))
repeatCount := width - bodyLen - 2
if repeatCount < 0 {
repeatCount = 0
}
return fmt.Sprintf("%s%s%s%s\n", leftBracketStr, body, rightBracketStr, strings.Repeat(fillStr, repeatCount))
}
func RenderHelpKey(control, title string, selected bool) string {
if selected {
return StatusSelected("▏") + StatusControlSelected(control) + StatusSelected(" "+title+" ")
} else {
return StatusNormal("▏") + StatusControlNormal(control) + StatusNormal(" "+title+" ")
}
}