summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-29 01:45:59 -0500
committerJeff Carr <[email protected]>2025-10-29 01:45:59 -0500
commit9266a4798e43c989002602980431b0ea8e23cc60 (patch)
tree118ad5f79b5c9ecb6c6b9f68ff845845473cb256
parent2d5174830aead2aa4e8dcbbb4de78a122d38835d (diff)
better logic & stops doing things when nothing changesv0.0.49
-rw-r--r--argv.parseOsArgs.go4
-rw-r--r--theMagicOfAutocomplete.go63
2 files changed, 39 insertions, 28 deletions
diff --git a/argv.parseOsArgs.go b/argv.parseOsArgs.go
index 002630a..654ab0a 100644
--- a/argv.parseOsArgs.go
+++ b/argv.parseOsArgs.go
@@ -86,6 +86,10 @@ func (pb *Argv) parseOsArgs() {
if os.Args[1] != "--auto-complete" {
// if the first arg is not --auto-complete, then don't go any farther
for _, s := range os.Args[1:] {
+ if s == "--argvdebug" {
+ me.debug = true
+ continue
+ }
pb.Real = append(pb.Real, s)
}
// found the subcommand
diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go
index 4bb56b8..d273700 100644
--- a/theMagicOfAutocomplete.go
+++ b/theMagicOfAutocomplete.go
@@ -118,7 +118,6 @@ func savePB() {
// save now. this is near the end probably
dur := time.Since(PB.Ctime.AsTime())
PB.ArgvDuration = durationpb.New(dur) // track how long autocomplete took
- me.all.Append(PB)
// npb := new(Argv)
// npb.Uuid = uuid.New().String()
// me.all.Append(npb)
@@ -132,26 +131,22 @@ func saveAndExit() {
printStddbg()
}
- PB.ErrCounter += 1
- if PB.ErrCounter < 3 {
- printStderr()
+ if PB.Fast > 4 {
+ // if user holds down the tab key, stop doing anything
} else {
- if PB.ErrCounter > 10 {
- PB.ErrCounter = 0
+ PB.ErrCounter += 1
+ if PB.ErrCounter == 3 {
+ // only print the Stderr (Help text) on the third <TAB>
+ printStderr()
+ PB.OutCounter = 0
}
- }
- PB.OutCounter += 1
- printStdout()
- if PB.OutCounter < 3 {
- } else {
- if PB.OutCounter > 5 {
- PB.OutCounter = 0
+ PB.OutCounter += 1
+ if PB.OutCounter < 3 {
+ // print the matching text twice, then stop
+ printStdout()
}
}
- //if PB.Fast == 0 {
- // PB.OutCounter = 0
- //}
savePB()
os.Exit(0)
}
@@ -162,20 +157,15 @@ func examineArgvHistory() {
// loads the argv autocomplete history file
me.Err = config.ForceCreateCacheDirPB(me.all, "argv", PB.AppInfo.APPNAME)
if me.Err != nil {
- //
- // debug this
- //
+ // todo: figure out what this happens
me.debug = true
PB.Stddbg += fmt.Sprintf("config.CreateCacheDirPB() err(%v)\n", me.Err)
PB.Stddbg += fmt.Sprintf("argvpb.Load() history file failed")
printStderr()
printStddbg()
- return
- }
- if me.debug {
- // use this if you are having trouble debugging this code
- // me.all.printHistory("EARLY")
+ me.all = NewArgvs()
}
+
// roll the autocomplete file
maxsize := 17
trim := 10
@@ -229,6 +219,9 @@ func examineArgvHistory() {
me.last = me.all.Argvs[me.all.Len()-1]
}
+ // last is chosen. append the current PB
+ me.all.Append(PB)
+
// compute the duration since the last time
dur := time.Since(me.last.Ctime.AsTime())
PB.Duration = durationpb.New(dur)
@@ -237,9 +230,13 @@ func examineArgvHistory() {
PB.OutCounter = me.last.OutCounter
// do the smart something here
- if PB.GetCmd() == me.last.GetCmd() {
- // turn on debugging if duration < 200 milliseconds
- } else {
+ if PB.GetCmd() != me.last.GetCmd() {
+ // reset counters if user types things
+ PB.OutCounter = 0
+ PB.ErrCounter = 0
+ PB.Fast = 0
+ }
+ if PB.Partial != me.last.Partial {
// reset counters if user types things
PB.OutCounter = 0
PB.ErrCounter = 0
@@ -249,7 +246,17 @@ func examineArgvHistory() {
if dur < time.Millisecond*300 {
PB.Fast = me.last.Fast + 1
} else {
+ curreal := strings.Join(PB.Real, " ")
+ lastreal := strings.Join(me.last.Real, " ")
+ if curreal == lastreal {
+ // user is just wasting time or thinking. don't change anything
+ } else {
+ if me.last.Fast > 5 {
+ PB.OutCounter = 0
+ PB.ErrCounter = 0
+ }
+ }
PB.Fast = 0
- errors.Join(me.Err, me.autoFunc()) // run the autocomplete function the user made for their application
}
+ errors.Join(me.Err, me.autoFunc()) // run the autocomplete function the user made for their application
}