summaryrefslogtreecommitdiff
path: root/theMagicOfAutocomplete.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-12 06:27:25 -0500
committerJeff Carr <[email protected]>2025-10-12 06:27:25 -0500
commita2c9d4fed68598ebab7a174d51a44af43a7ff768 (patch)
tree9240df3ea4cea91409a89e05c3ed2aeb2bbae34b /theMagicOfAutocomplete.go
parentcc600fe686e905a696cbc840decdd8d24b7bb72f (diff)
finally merge these to sort it all out
Diffstat (limited to 'theMagicOfAutocomplete.go')
-rw-r--r--theMagicOfAutocomplete.go43
1 files changed, 41 insertions, 2 deletions
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