Skip to content

Commit cf7d4dc

Browse files
committed
refactor: iTip is iLen
No need to store iTip in the style array. This will make BarStyleComposer struct less in size.
1 parent 9af2c34 commit cf7d4dc

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

bar_filler_bar.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@ const (
1212
iLbound = iota
1313
iRefiller
1414
iFiller
15-
iTip
1615
iPadding
1716
iRbound
1817
iLen
1918
)
2019

21-
var defaultBarStyle = [iLen]string{"[", "+", "=", ">", "-", "]"}
2220
var barStyleComposer = BarStyleComposer{
23-
style: defaultBarStyle,
24-
tipFrames: []string{defaultBarStyle[iTip]},
21+
style: [iLen]string{"[", "+", "=", "-", "]"},
22+
tipFrames: []string{">"},
2523
}
2624

2725
type component struct {
@@ -34,11 +32,11 @@ type barSection struct {
3432
bytes []byte
3533
}
3634

37-
type barSections [iLen]barSection
35+
type barSections [iLen + 1]barSection
3836

3937
type barFiller struct {
4038
components [iLen]component
41-
metas [iLen]func(string) string
39+
metas [iLen + 1]func(string) string
4240
flushOp func(barSections, io.Writer) error
4341
tip struct {
4442
onComplete bool
@@ -51,7 +49,7 @@ type barFiller struct {
5149
// Call BarStyle to construct a new one.
5250
type BarStyleComposer struct {
5351
style [iLen]string
54-
metas [iLen]func(string) string
52+
metas [iLen + 1]func(string) string
5553
tipFrames []string
5654
tipOnComplete bool
5755
rev bool
@@ -121,7 +119,7 @@ func (s BarStyleComposer) Tip(frames ...string) BarStyleComposer {
121119
}
122120

123121
func (s BarStyleComposer) TipMeta(fn func(string) string) BarStyleComposer {
124-
s.metas[iTip] = fn
122+
s.metas[iLen] = fn
125123
return s
126124
}
127125

@@ -220,7 +218,7 @@ func (s *barFiller) Fill(w io.Writer, stat decor.Statistics) error {
220218
{s.metas[iLbound], s.components[iLbound].bytes},
221219
{s.metas[iRefiller], refilling},
222220
{s.metas[iFiller], filling},
223-
{s.metas[iTip], tip.bytes},
221+
{s.metas[iLen], tip.bytes},
224222
{s.metas[iPadding], padding},
225223
{s.metas[iRbound], s.components[iRbound].bytes},
226224
}, w)

0 commit comments

Comments
 (0)