diff options
| author | Jeff Carr <[email protected]> | 2025-10-12 06:09:20 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-12 06:09:20 -0500 |
| commit | a21a55ea6679b9e97ed1a51ac80e71c5d9770607 (patch) | |
| tree | 321d208c86b1de0e29fecc0d9cf3802428329ba5 /history.go | |
| parent | ab5017449578fa921cdaad16e6ce94ddd2e8c664 (diff) | |
Fast still isn't being saved
Diffstat (limited to 'history.go')
| -rw-r--r-- | history.go | 41 |
1 files changed, 19 insertions, 22 deletions
@@ -5,41 +5,43 @@ package prep // stores files ./cache/argv/<appname>.pb import ( - "fmt" "time" - "go.wit.com/lib/cobol" "go.wit.com/lib/config" durationpb "google.golang.org/protobuf/types/known/durationpb" ) -func (pb *Auto) getHistoryPB() error { +func (newpb *Auto) getHistoryPB() error { all := NewAutos() - err := config.LoadCache(all, "argv", pb.Argname) // loads ~/.cache/argv/forge.pb + err := config.LoadCache(all, "argv", newpb.Argname) // loads ~/.cache/argv/forge.pb if err != nil { - // pb.History = false + // newpb.History = false return err } + if all.Len() == 0 { + // first time + all.Clone(newpb) + err = all.Save() + } + + if newpb.Debug { + all.PrintHistory() + } + var last *Auto - // find the last entry & print out debugging history + // find the last entry. this is dumb way to do it for found := range all.IterAll() { - cmd := fmt.Sprintf("cmd='%s'", found.Cmd) - arglast := fmt.Sprintf("last='%s'", found.Last) - partial := fmt.Sprintf("p='%s'", found.Partial) - dur := time.Since(found.Ctime.AsTime()) - age := fmt.Sprintf("age=(%s)", cobol.FormatDuration(dur)) - pb.Debugf("AUTO HISTORY: %s %-18.18s %-18.18s %-12.12s argv='%v' goargs='%v'", age, cmd, arglast, partial, found.Argv, found.Goargs) last = found } // set the duration since the last auto complete dur := time.Since(last.Ctime.AsTime()) - pb.Duration = durationpb.New(dur) + newpb.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) + newpb.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] { @@ -47,14 +49,9 @@ func (pb *Auto) getHistoryPB() error { // } } - // need this for the first time the user runs autocomplete - if last == nil { - last = new(Auto) - } - - all.Clone(pb) - + all.Clone(newpb) err = all.Save() - pb.Debugf("WRITE DEBUG: write PB='%s' len(pb)=%d config.Save().err=%v", all.Filename, all.Len(), err) + + newpb.Debugf("WRITE DEBUG: write PB='%s' len(pb)=%d config.Save().err=%v", all.Filename, all.Len(), err) return err } |
