summaryrefslogtreecommitdiff
path: root/theMagicOfAutocomplete.go
diff options
context:
space:
mode:
Diffstat (limited to 'theMagicOfAutocomplete.go')
-rw-r--r--theMagicOfAutocomplete.go69
1 files changed, 35 insertions, 34 deletions
diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go
index c2bbefb..79154e9 100644
--- a/theMagicOfAutocomplete.go
+++ b/theMagicOfAutocomplete.go
@@ -59,15 +59,12 @@ func Autocomplete() *Argv {
if !me.isAuto {
// not autocompleting. return to the application
- // save the pb & history
- // savePB()
- // 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
+ // save the pb & history. todo: remove this what things work. slow. disk i/o
savePB()
- doStdoutStderr()
return me.pb
}
fmt.Fprintf(Stddbg, "heading to autocomplete. err(%v)\n", me.Err)
@@ -109,17 +106,6 @@ func prepareStdout() {
}
}
- 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.ErrCounter = 0
- }
- }
if me.Err == nil {
fmt.Fprintf(Stddbg, "got to the end of Argv ok\n")
} else {
@@ -134,25 +120,37 @@ func savePB() {
// npb := new(Argv)
// npb.Uuid = uuid.New().String()
// me.all.Append(npb)
- errors.Join(me.Err, me.all.Save())
+ me.all.Save()
}
-func doStdoutStderr() {
+func saveAndExit() {
if me.debug {
me.all.PrintHistory("HIST")
fmt.Fprintf(Stddbg, "me.debug=true pb.Stdout=(%v)\n", strings.TrimSpace(PB.Stdout))
PrintStddbg()
}
- PrintStderr()
- if PB.OutCounter < 9 {
- PrintStdout()
+
+ PB.ErrCounter += 1
+ if PB.ErrCounter < 3 {
+ PrintStderr()
+ } else {
+ if PB.ErrCounter > 10 {
+ PB.ErrCounter = 0
+ }
}
-}
-func saveAndExit() {
PB.OutCounter += 1
+ PrintStdout()
+ if PB.OutCounter < 3 {
+ } else {
+ if PB.OutCounter > 5 {
+ PB.OutCounter = 0
+ }
+ }
+ //if PB.Fast == 0 {
+ // PB.OutCounter = 0
+ //}
savePB()
- doStdoutStderr()
os.Exit(0)
}
@@ -172,13 +170,12 @@ func examineArgvHistory() {
//
me.debug = true
me.pb.Stddbg += fmt.Sprintf("config.CreateCacheDirPB() err(%v)\n", me.Err)
- doStdoutStderr()
+ PrintStderr()
panic("argvpb.Load() history file failed")
}
if me.debug {
// use this if you are having trouble debugging this code
// me.all.PrintHistory("EARLY")
- // doStdoutStderr()
}
// roll the autocomplete file
maxsize := 17
@@ -223,7 +220,6 @@ func examineArgvHistory() {
if me.all.Len() == 0 {
me.debug = true
fmt.Fprintf(Stddbg, "examineArgvHistory() empty file %s\n", me.all.Filename)
- doStdoutStderr()
saveAndExit()
}
@@ -234,18 +230,23 @@ func examineArgvHistory() {
dur := time.Since(me.last.Ctime.AsTime())
me.pb.Duration = durationpb.New(dur)
+ me.pb.ErrCounter = me.last.ErrCounter
+ me.pb.OutCounter = me.last.OutCounter
+
+ // do the smart something here
+ if me.pb.GetCmd() == me.last.GetCmd() {
+ // turn on debugging if duration < 200 milliseconds
+ } else {
+ // reset counters if user types things
+ me.pb.OutCounter = 0
+ me.pb.ErrCounter = 0
+ me.pb.Fast = 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
+ errors.Join(me.Err, me.autoFunc()) // run the autocomplete function the user made for their application
}
}