/
list.go
93 lines (78 loc) · 1.61 KB
/
list.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
package history
import (
"sync"
// "github.com/u-root/u-root/cmds/core/elvish/eval/vals"
"github.com/u-root/u-root/cmds/core/elvish/util"
)
// List is a list-like value that provides access to history in the API
// backend. It is used in the $edit:history variable.
type List struct {
*sync.RWMutex
}
func (hv List) Kind() string {
return "list"
}
// Equal returns true as long as the rhs is also of type History.
func (hv List) Equal(a interface{}) bool {
_, ok := a.(List)
return ok
}
func (hv List) Hash() uint32 {
// TODO(xiaq): Make a global registry of singleton hashes to avoid
// collision.
return 100
}
func (hv List) Repr(int) string {
return "$edit:history"
}
func (hv List) Len() int {
hv.RLock()
defer hv.RUnlock()
// nextseq, err = -1, nil
maybeThrow(nil)
return -1
}
func (hv List) Iterate(f func(interface{}) bool) {
hv.RLock()
defer hv.RUnlock()
/*
n := hv.Len()
cmds, err := hv.Daemon.Cmds(1, n+1)
maybeThrow(err)
for _, cmd := range cmds {
if !f(string(cmd)) {
break
}
}
*/
}
func (hv List) Index(rawIndex interface{}) (interface{}, error) {
hv.RLock()
defer hv.RUnlock()
return nil, nil
/*
index, err := vals.ConvertListIndex(rawIndex, hv.Len())
if err != nil {
return nil, err
}
return nil, nil
if index.Slice {
cmds, err := hv.Daemon.Cmds(index.Lower+1, index.Upper+1)
if err != nil {
return nil, err
}
l := vals.EmptyList
for _, cmd := range cmds {
l = l.Cons(cmd)
}
return l, nil
}
s, err := hv.Daemon.Cmd(index.Lower + 1)
return string(s), err
*/
}
func maybeThrow(e error) {
if e != nil {
util.Throw(e)
}
}