Skip to content

Commit

Permalink
This should also be moved from the top-level
Browse files Browse the repository at this point in the history
It's a simple type wrapped around a tree-walker, and this lets me
shorten the name I use to refer to it, too.
  • Loading branch information
gcla committed Jul 9, 2022
1 parent 8add110 commit c37544a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 6 additions & 6 deletions noroot.go → pkg/noroot/noroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// code is governed by the MIT license that can be found in the LICENSE
// file.

package termshark
package noroot

import (
"github.com/gcla/gowid/widgets/list"
Expand All @@ -11,22 +11,22 @@ import (

//======================================================================

type NoRootWalker struct {
type Walker struct {
*tree.TreeWalker
}

func NewNoRootWalker(w *tree.TreeWalker) *NoRootWalker {
return &NoRootWalker{
func NewWalker(w *tree.TreeWalker) *Walker {
return &Walker{
TreeWalker: w,
}
}

// for omitting top level node
func (f *NoRootWalker) Next(pos list.IWalkerPosition) list.IWalkerPosition {
func (f *Walker) Next(pos list.IWalkerPosition) list.IWalkerPosition {
return tree.WalkerNext(f, pos)
}

func (f *NoRootWalker) Previous(pos list.IWalkerPosition) list.IWalkerPosition {
func (f *Walker) Previous(pos list.IWalkerPosition) list.IWalkerPosition {
fc := pos.(tree.IPos)
pp := tree.PreviousPosition(fc, f.Tree())
if pp.Equal(tree.NewPos()) {
Expand Down
5 changes: 3 additions & 2 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
"github.com/gcla/termshark/v2"
"github.com/gcla/termshark/v2/configs/profiles"
"github.com/gcla/termshark/v2/pkg/fields"
"github.com/gcla/termshark/v2/pkg/noroot"
"github.com/gcla/termshark/v2/pkg/pcap"
"github.com/gcla/termshark/v2/pkg/pdmltree"
"github.com/gcla/termshark/v2/pkg/psmlmodel"
Expand Down Expand Up @@ -2630,7 +2631,7 @@ func setPacketListWidgets(psml iPsmlInfo, app gowid.IApp) {

func expandStructWidgetAtPosition(row int, pos int, app gowid.IApp) {
if curPacketStructWidget != nil {
walker := curPacketStructWidget.Walker().(*termshark.NoRootWalker)
walker := curPacketStructWidget.Walker().(*noroot.Walker)
curTree := walker.Tree().(*pdmltree.Model)

finalPos := make([]int, 0)
Expand Down Expand Up @@ -2812,7 +2813,7 @@ func getStructWidgetToDisplay(row int, app gowid.IApp) gowid.IWidget {
tree.NewCachingMaker(tree.WidgetMakerFunction(makeStructNodeWidget)),
tree.NewCachingDecorator(tree.DecoratorFunction(makeStructNodeDecoration)))
// Without the caching layer, clicking on a button has no effect
walker := termshark.NewNoRootWalker(rwalker)
walker := noroot.NewWalker(rwalker)

// Send the layers represents the tree expansion to hex.
// This could be the user clicking inside the tree. Or it might be the position changing
Expand Down

0 comments on commit c37544a

Please # to comment.