Skip to content

Commit

Permalink
Generalize a toml-writing function
Browse files Browse the repository at this point in the history
I might use this in the future to store recent packet searches, if that
turns out to make sense for users.
  • Loading branch information
gcla committed May 30, 2022
1 parent 5acb0df commit 42dec34
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions ui/lastline.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ func (s recentsArg) Completions() []string {
//======================================================================

type filterArg struct {
field string
substr string
}

Expand All @@ -211,7 +212,7 @@ func (s filterArg) OfferCompletion() bool {

func (s filterArg) Completions() []string {
matches := make([]string, 0)
cfiles := termshark.ConfStringSlice("main.recent-filters", []string{})
cfiles := termshark.ConfStringSlice(s.field, []string{})
if cfiles != nil {
for _, sc := range cfiles {
scopy := sc
Expand Down Expand Up @@ -525,7 +526,10 @@ func (d filterCommand) Arguments(toks []string, app gowid.IApp) []minibuffer.IAr
if len(toks) > 0 {
pref = toks[0]
}
res = append(res, filterArg{substr: pref})
res = append(res, filterArg{
field: "main.recent-filters",
substr: pref,
})
return res
}

Expand Down
8 changes: 6 additions & 2 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,13 +694,17 @@ func AddToRecentFiles(pcap string) {
}

func AddToRecentFilters(val string) {
comps := ConfStrings("main.recent-filters")
addToRecent("main.recent-filters", val)
}

func addToRecent(field string, val string) {
comps := ConfStrings(field)
if (len(comps) == 0 || comps[0] != val) && strings.TrimSpace(val) != "" {
comps = RemoveFromStringSlice(val, comps)
if len(comps) > 64 {
comps = comps[0 : 64-1]
}
SetConf("main.recent-filters", comps)
SetConf(field, comps)
}
}

Expand Down

0 comments on commit 42dec34

Please # to comment.