Skip to content

Commit 8f38744

Browse files
committed
Naming and comments
1 parent a0de329 commit 8f38744

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

i3statusline.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ func (i3sl *i3StatusLine) Run() error {
100100
}
101101

102102
notifiers := i3sl.UpdateNotifiers
103-
mutableStatusItems := i3sl.StatusLineBlocks
103+
mutableBlocks := i3sl.StatusLineBlocks
104104

105105
// tick is only used to notify when the status line must be updated.
106106
tick := make(chan struct{})
107107

108-
for _, source := range notifiers {
109-
_ = source.OnUpdate(func() {
108+
for _, notifier := range notifiers {
109+
_ = notifier.OnUpdate(func() {
110110
tick <- struct{}{}
111111
})
112112
}
@@ -117,13 +117,13 @@ func (i3sl *i3StatusLine) Run() error {
117117

118118
enc := json.NewEncoder(w)
119119

120-
// visibleStatusItems is what will be serialized as JSON and printed to
121-
// standard output.
122-
visibleStatusItems := make([]StatusLineBlock, len(mutableStatusItems))
120+
// visibleBlocks is what will be serialized as JSON and printed to the
121+
// writer.
122+
visibleBlocks := make([]StatusLineBlock, len(mutableBlocks))
123123

124124
// Wait for a refresh to trigger, and update the status line.
125125
for range tick {
126-
for i, itemPtr := range mutableStatusItems {
126+
for i, itemPtr := range mutableBlocks {
127127
if itemPtr == nil {
128128
continue
129129
}
@@ -133,12 +133,12 @@ func (i3sl *i3StatusLine) Run() error {
133133
continue
134134
}
135135

136-
visibleStatusItems[i] = *v
136+
visibleBlocks[i] = *v
137137
}
138138

139139
w.Write([]byte{','})
140140

141-
_ = enc.Encode(visibleStatusItems)
141+
_ = enc.Encode(visibleBlocks)
142142
}
143143

144144
<-ctx.Done()

notifier.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ type Notifier interface {
77
//
88
// It returns a function that, when called, should un-register `callback`
99
// so that it's no longer called on updates.
10-
OnUpdate(callback OnUpdateCallbackFunc) RemoveOnUpdateCallbackFunc
10+
OnUpdate(callback NotifierCallbackFunc) RemoveCallbackFunc
1111
}
1212

13-
type OnUpdateCallbackFunc func()
14-
type RemoveOnUpdateCallbackFunc func()
13+
type NotifierCallbackFunc func()
14+
type RemoveCallbackFunc func()
1515

16-
type NotifierFunc func(callback OnUpdateCallbackFunc) RemoveOnUpdateCallbackFunc
16+
// UpdateNotifier is a wrapper for a function with the same signature as
17+
// `Notifier.OnUpdate`, that implements `Notifier` by using itself as the
18+
// `OnUpdate` method.
19+
type UpdateNotifier func(callback NotifierCallbackFunc) RemoveCallbackFunc
1720

18-
func (fn NotifierFunc) OnUpdate(callback OnUpdateCallbackFunc) RemoveOnUpdateCallbackFunc {
21+
func (fn UpdateNotifier) OnUpdate(callback NotifierCallbackFunc) RemoveCallbackFunc {
1922
return fn(callback)
2023
}

statuslineblockprovider.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type StatusLineBlockProvider func(ctx context.Context, ch chan<- StatusLineBlock
1515
func slbpToNotifier(ctx context.Context, p StatusLineBlockProvider) (Notifier, *atomic.Pointer[StatusLineBlock]) {
1616
statusProvider := &atomic.Pointer[StatusLineBlock]{}
1717

18-
source := NotifierFunc(func(callback OnUpdateCallbackFunc) RemoveOnUpdateCallbackFunc {
18+
source := UpdateNotifier(func(callback NotifierCallbackFunc) RemoveCallbackFunc {
1919
ch := make(chan StatusLineBlock)
2020

2121
ctxProvider, cancel := context.WithCancelCause(ctx)

time/time.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func (tn *Notifier) runCallbacks() {
3131

3232
// We want this to panic if the conversion can't be done, because that
3333
// would mean there's a bug somewhere.
34-
callback := value.(dsts.OnUpdateCallbackFunc)
34+
callback := value.(dsts.NotifierCallbackFunc)
3535

3636
callback()
3737

@@ -92,7 +92,7 @@ func (tn *Notifier) init() {
9292
}
9393
}
9494

95-
func (tn *Notifier) OnUpdate(callback dsts.OnUpdateCallbackFunc) dsts.RemoveOnUpdateCallbackFunc {
95+
func (tn *Notifier) OnUpdate(callback dsts.NotifierCallbackFunc) dsts.RemoveCallbackFunc {
9696
tn.Lock()
9797
defer tn.Unlock()
9898

0 commit comments

Comments
 (0)