summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--auto.Print.go4
-rw-r--r--history.go41
2 files changed, 21 insertions, 24 deletions
diff --git a/auto.Print.go b/auto.Print.go
index b992e65..6c0d489 100644
--- a/auto.Print.go
+++ b/auto.Print.go
@@ -32,7 +32,7 @@ func (pb *Auto) Debugf(fmts string, parts ...any) {
// print out auto complete debugging info
func (pb *Auto) PrintDebug() {
dur := pb.Duration.AsDuration()
- pb.Debugf("AUTOCOMPLETE: arg0='%s' arg1='%s' partial='%s' cmd='%s' age=%s argv=%v\n", pb.Arg0, pb.Arg1, pb.Partial, pb.Cmd, cobol.FormatDuration(dur), pb.Argv)
+ pb.Debugf("ARGV: 0='%s' 1='%s' p='%s' cmd='%s' age=(%s) argv=%v fast=%v\n", pb.Arg0, pb.Arg1, pb.Partial, pb.Cmd, cobol.FormatDuration(dur), pb.Argv, pb.Fast)
}
func (pb *Autos) PrintHistory() {
@@ -42,7 +42,7 @@ func (pb *Autos) PrintHistory() {
partial := fmt.Sprintf("p='%s'", found.Partial)
dur := time.Since(found.Ctime.AsTime())
age := fmt.Sprintf("age=(%s)", cobol.FormatDuration(dur))
- found.Debugf("AUTO HISTORY: %s %-18.18s %-18.18s %-12.12s argv='%v' goargs='%v'", age, cmd, arglast, partial, found.Argv, found.Goargs)
+ found.Debugf("HIST: %s %-18.18s %-18.18s %-12.12s argv='%v' fast=%v goargs='%v'", age, cmd, arglast, partial, found.Argv, found.Fast, found.Goargs)
}
}
diff --git a/history.go b/history.go
index 74dc823..c048c1c 100644
--- a/history.go
+++ b/history.go
@@ -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
}