From a2c9d4fed68598ebab7a174d51a44af43a7ff768 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 12 Oct 2025 06:27:25 -0500 Subject: finally merge these to sort it all out --- theMagicOfAutocomplete.go | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'theMagicOfAutocomplete.go') diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go index 3202af3..fa392a1 100644 --- a/theMagicOfAutocomplete.go +++ b/theMagicOfAutocomplete.go @@ -4,10 +4,13 @@ package prep // lots of the fun magic is in here import ( + "errors" "os" "time" "go.wit.com/dev/alexflint/arg" + "go.wit.com/lib/config" + durationpb "google.golang.org/protobuf/types/known/durationpb" timestamppb "google.golang.org/protobuf/types/known/timestamppb" ) @@ -31,17 +34,53 @@ func Autocomplete(dest any) *Auto { pb.PrintDebug() } - all, err := pb.getHistoryPB() // read in the history protobuf file + // all, err := pb.getHistoryPB() // read in the history protobuf file + // func (newpb *Auto) getHistoryPB() (*Autos, error) { + all := NewAutos() + err := config.LoadCache(all, "argv", pb.Argname) // loads ~/.cache/argv/forge.pb if err != nil { // there is no history } + if all.Len() == 0 { + // first time + all.Clone(pb) + err = all.Save() + } + + // set the duration since the last auto complete + // find the last entry. this is dumb way to do it + var last *Auto + for found := range all.IterAll() { + last = found + } + dur := time.Since(last.Ctime.AsTime()) + pb.Duration = durationpb.New(dur) + + // roll the autocomplete file + if all.Len() > 15 { + pb.Debugf("DEBUG: trim() history is over 100 len=%d vs new=%d", all.Len(), all.Len()-90) + all.Autos = all.Autos[all.Len()-10:] + // newall.Autos = all.Autos[0:10] + // for _, found := range all.Autos[0:10] { + // newall.Append(found) + // } + } + + // save the history + all.Clone(pb) + errors.Join(err, all.Save()) + + pb.Debugf("WRITE DEBUG: write PB='%s' len(pb)=%d config.Save().err=%v", all.Filename, all.Len(), err) + // return all, err + //} + if pb.Debug { all.PrintHistory() } // turn on debugging if duration < 200 milliseconds - dur := pb.Duration.AsDuration() + dur = pb.Duration.AsDuration() if dur < time.Millisecond*200 { pb.Debug = true pb.Fast = true -- cgit v1.2.3