-
Notifications
You must be signed in to change notification settings - Fork 125
/
Copy pathstyle.go
159 lines (142 loc) · 4.54 KB
/
style.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package progress
import (
"time"
"github.com/jedib0t/go-pretty/text"
)
// Style declares how to render the Progress/Trackers.
type Style struct {
Name string // name of the Style
Chars StyleChars // characters to use on the progress bar
Colors StyleColors // colors to use on the progress bar
Options StyleOptions // misc. options for the progress bar
}
var (
// StyleDefault uses ASCII text to render the Trackers.
StyleDefault = Style{
Name: "StyleDefault",
Chars: StyleCharsDefault,
Colors: StyleColorsDefault,
Options: StyleOptionsDefault,
}
// StyleBlocks uses UNICODE Block Drawing characters to render the Trackers.
StyleBlocks = Style{
Name: "StyleBlocks",
Chars: StyleCharsBlocks,
Colors: StyleColorsDefault,
Options: StyleOptionsDefault,
}
// StyleCircle uses UNICODE Circle runes to render the Trackers.
StyleCircle = Style{
Name: "StyleCircle",
Chars: StyleCharsCircle,
Colors: StyleColorsDefault,
Options: StyleOptionsDefault,
}
// StyleRhombus uses UNICODE Rhombus runes to render the Trackers.
StyleRhombus = Style{
Name: "StyleRhombus",
Chars: StyleCharsRhombus,
Colors: StyleColorsDefault,
Options: StyleOptionsDefault,
}
)
// StyleChars defines the characters/strings to use for rendering the Tracker.
type StyleChars struct {
BoxLeft string // left-border
BoxRight string // right-border
Finished string // finished block
Finished25 string // 25% finished block
Finished50 string // 50% finished block
Finished75 string // 75% finished block
Unfinished string // 0% finished block
}
var (
// StyleCharsDefault uses simple ASCII characters.
StyleCharsDefault = StyleChars{
BoxLeft: "[",
BoxRight: "]",
Finished: "#",
Finished25: ".",
Finished50: ".",
Finished75: ".",
Unfinished: ".",
}
// StyleCharsBlocks uses UNICODE Block Drawing characters.
StyleCharsBlocks = StyleChars{
BoxLeft: "║",
BoxRight: "║",
Finished: "█",
Finished25: "░",
Finished50: "▒",
Finished75: "▓",
Unfinished: "░",
}
// StyleCharsCircle uses UNICODE Circle characters.
StyleCharsCircle = StyleChars{
BoxLeft: "(",
BoxRight: ")",
Finished: "●",
Finished25: "○",
Finished50: "○",
Finished75: "○",
Unfinished: "◌",
}
// StyleCharsRhombus uses UNICODE Rhombus characters.
StyleCharsRhombus = StyleChars{
BoxLeft: "<",
BoxRight: ">",
Finished: "◆",
Finished25: "◈",
Finished50: "◈",
Finished75: "◈",
Unfinished: "◇",
}
)
// StyleColors defines what colors to use for various parts of the Progress and
// Tracker texts.
type StyleColors struct {
Message text.Colors // message text colors
Percent text.Colors // percentage text colors
Stats text.Colors // stats text (time, value) colors
Time text.Colors // time text colors (overrides Stats)
Tracker text.Colors // tracker text colors
Value text.Colors // value text colors (overrides Stats)
}
var (
// StyleColorsDefault defines sane color choices - None.
StyleColorsDefault = StyleColors{}
// StyleColorsExample defines a few choice color options. Use this is just as
// an example to customize the Tracker/text colors.
StyleColorsExample = StyleColors{
Message: text.Colors{text.FgWhite, text.BgBlack},
Percent: text.Colors{text.FgHiRed, text.BgBlack},
Stats: text.Colors{text.FgHiBlack, text.BgBlack},
Time: text.Colors{text.FgGreen, text.BgBlack},
Tracker: text.Colors{text.FgYellow, text.BgBlack},
Value: text.Colors{text.FgCyan, text.BgBlack},
}
)
// StyleOptions defines misc. options to control how the Tracker or its parts
// gets rendered.
type StyleOptions struct {
DoneString string // "done!" string
Separator string // text between message and tracker
SnipIndicator string // text denoting message snipping
PercentFormat string // formatting to use for percentage
TimeDonePrecision time.Duration // precision for time when done
TimeInProgressPrecision time.Duration // precision for time when in progress
TimeOverallPrecision time.Duration // precision for overall time
}
var (
// StyleOptionsDefault defines sane defaults for the Options. Use this as an
// example to customize the Tracker rendering.
StyleOptionsDefault = StyleOptions{
DoneString: "done!",
PercentFormat: "%5.2f%%",
Separator: " ... ",
SnipIndicator: "~",
TimeDonePrecision: time.Millisecond,
TimeInProgressPrecision: time.Microsecond,
TimeOverallPrecision: time.Second,
}
)