forked from gcla/termshark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
noroot.go
42 lines (34 loc) · 995 Bytes
/
noroot.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
// Copyright 2019 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 termshark
import (
"github.com/gcla/gowid/widgets/list"
"github.com/gcla/gowid/widgets/tree"
)
//======================================================================
type NoRootWalker struct {
*tree.TreeWalker
}
func NewNoRootWalker(w *tree.TreeWalker) *NoRootWalker {
return &NoRootWalker{
TreeWalker: w,
}
}
// for omitting top level node
func (f *NoRootWalker) Next(pos list.IWalkerPosition) list.IWalkerPosition {
return tree.WalkerNext(f, pos)
}
func (f *NoRootWalker) Previous(pos list.IWalkerPosition) list.IWalkerPosition {
fc := pos.(tree.IPos)
pp := tree.PreviousPosition(fc, f.Tree())
if pp.Equal(tree.NewPos()) {
return nil
}
return tree.WalkerPrevious(f, pos)
}
//======================================================================
// Local Variables:
// mode: Go
// fill-column: 110
// End: