/
searchcommon.go
63 lines (51 loc) · 1.38 KB
/
searchcommon.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
// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source
// code is governed by the MIT license that can be found in the LICENSE
// file.
// Package ui contains user-interface functions and helpers for termshark.
package ui
import (
"sync"
"github.com/gcla/gowid"
)
//======================================================================
type commonSearchCallbacks struct {
ticks int
}
func (s *commonSearchCallbacks) OnTick(app gowid.IApp) {
s.ticks += 1
if s.ticks >= 2 {
app.Run(gowid.RunFunction(func(app gowid.IApp) {
SetProgressIndeterminateFor(app, SearchOwns)
SetSearchProgressWidget(app)
loadSpinner.Update()
}))
}
}
func (s *commonSearchCallbacks) OnError(err error, app gowid.IApp) {
app.Run(gowid.RunFunction(func(app gowid.IApp) {
OpenError(err.Error(), app)
}))
}
//======================================================================
type SearchStopper struct {
RequestedMutex sync.Mutex
Requested bool
}
func (s *SearchStopper) RequestStop(app gowid.IApp) {
s.RequestedMutex.Lock()
defer s.RequestedMutex.Unlock()
s.Requested = true
}
func (s *SearchStopper) DoIfStopped(f func()) {
s.RequestedMutex.Lock()
defer s.RequestedMutex.Unlock()
if s.Requested {
f()
s.Requested = false
}
}
//======================================================================
// Local Variables:
// mode: Go
// fill-column: 110
// End: