summaryrefslogtreecommitdiff
path: root/theMagicOfAutocomplete.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-28 12:12:20 -0500
committerJeff Carr <[email protected]>2025-10-28 12:12:20 -0500
commit90489b78a80a1ee2204872c6ff434c476f4970cd (patch)
tree44b9dbaa6362d326c7a26d9e49a3d01f895f0653 /theMagicOfAutocomplete.go
parent0c94928d631ab218dc20f3492b92de2b13aa3c1b (diff)
more argv logic
Diffstat (limited to 'theMagicOfAutocomplete.go')
-rw-r--r--theMagicOfAutocomplete.go71
1 files changed, 38 insertions, 33 deletions
diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go
index 92163cb..c2bbefb 100644
--- a/theMagicOfAutocomplete.go
+++ b/theMagicOfAutocomplete.go
@@ -64,6 +64,9 @@ func Autocomplete() *Argv {
// me.pp = arg.MustParse(dest)
me.Err = errors.Join(me.Err, me.mustParseFunc())
fmt.Fprintf(Stddbg, "did mustParseFunc(). heading to forge. err(%v)\n", me.Err)
+ me.pb.ErrCounter = 0
+ me.pb.OutCounter = 0
+ savePB()
doStdoutStderr()
return me.pb
}
@@ -106,47 +109,48 @@ func prepareStdout() {
}
}
- me.pb.HelpCounter = me.last.HelpCounter
- fmt.Fprintf(Stddbg, "got to HelpCounter check err(%v)\n", me.Err)
-
- if me.pb.Fast {
- if me.last.Fast {
- me.pb.HelpCounter = me.last.HelpCounter + 1
+ me.pb.ErrCounter = me.last.ErrCounter
+ me.pb.OutCounter = me.last.OutCounter
+ if me.pb.Fast == 0 {
+ errors.Join(me.Err, me.autoFunc()) // run the autocomplete function the user made for their application
+ } else {
+ if me.last.Fast > 0 {
+ me.pb.ErrCounter += 1
} else {
- me.pb.HelpCounter = 0
+ me.pb.ErrCounter = 0
}
+ }
+ if me.Err == nil {
+ fmt.Fprintf(Stddbg, "got to the end of Argv ok\n")
} else {
- errors.Join(me.Err, me.autoFunc()) // run the autocomplete function the user made for their application
+ fmt.Fprintf(Stddbg, "got to the end of Argv with err(%v)\n", me.Err)
}
- fmt.Fprintf(Stddbg, "got to the end err(%v)\n", me.Err)
return
}
func savePB() {
// save now. this is near the end probably
me.all.Append(me.pb)
- npb := new(Argv)
+ // npb := new(Argv)
// npb.Uuid = uuid.New().String()
- me.all.Append(npb)
+ // me.all.Append(npb)
errors.Join(me.Err, me.all.Save())
}
func doStdoutStderr() {
if me.debug {
- me.all.PrintHistory(me.last.GetCmd())
- fmt.Fprintf(Stddbg, "debug=true pb.Stdout (%v)\n", PB.Stdout)
- } else {
- if me.pb.Fast {
- if me.pb.HelpCounter < 3 {
- fmt.Fprintf(Stddbg, "help counter < 3\n")
- }
- }
+ me.all.PrintHistory("HIST")
+ fmt.Fprintf(Stddbg, "me.debug=true pb.Stdout=(%v)\n", strings.TrimSpace(PB.Stdout))
+ PrintStddbg()
}
PrintStderr()
- PrintStdout()
+ if PB.OutCounter < 9 {
+ PrintStdout()
+ }
}
func saveAndExit() {
+ PB.OutCounter += 1
savePB()
doStdoutStderr()
os.Exit(0)
@@ -180,9 +184,7 @@ func examineArgvHistory() {
maxsize := 17
trim := 10
if me.all.Len() > maxsize {
- me.pb.Debugf("DEBUG: trim() history is over 17 len=%d vs new=%d", me.all.Len(), me.all.Len()-trim)
- me.pb.Debugf("DEBUG: trim() history is over 17 len=%d vs new=%d", me.all.Len(), me.all.Len()-trim)
- me.pb.Debugf("DEBUG: trim() history is over 17 len=%d vs new=%d", me.all.Len(), me.all.Len()-trim)
+ me.pb.Debugf("DEBUG: trim() history is over %d len=%d vs new=%d", maxsize, me.all.Len(), me.all.Len()-trim)
me.all.Argvs = me.all.Argvs[me.all.Len()-trim:]
// newall.Autos = me.all.Autos[0:10]
}
@@ -210,6 +212,7 @@ func examineArgvHistory() {
continue
}
uuidmap[pb.Uuid] = pb
+ // more early code for debugging if things go really wrong
// if me.debug {
// hist := fmt.Sprintf("HISTNIL(%d)", counter)
// pb.PrintDebugNew(hist, "too soon")
@@ -231,16 +234,18 @@ func examineArgvHistory() {
dur := time.Since(me.last.Ctime.AsTime())
me.pb.Duration = durationpb.New(dur)
- if me.pb.Duration.AsDuration() < time.Millisecond*200 {
- me.pb.Fast = true
- if me.last.Fast {
- // do the smart something here
- if me.pb.GetCmd() == me.last.GetCmd() {
- // turn on debugging if duration < 200 milliseconds
- } else {
- // reset help counter
- me.pb.HelpCounter = 0
- }
+ // user keeps hitting tab. trigger help
+ if me.pb.Duration.AsDuration() < time.Millisecond*300 {
+ me.pb.Fast = me.last.Fast + 1
+ // do the smart something here
+ if me.pb.GetCmd() == me.last.GetCmd() {
+ // turn on debugging if duration < 200 milliseconds
+ } else {
+ // reset help counter
+ me.pb.ErrCounter = 0
+ me.pb.Fast = 0
}
+ } else {
+ me.pb.Fast = 0
}
}