summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-28 14:54:50 -0500
committerJeff Carr <[email protected]>2025-10-28 14:54:50 -0500
commit69a8ae0bdc33e898bee5046bfee73692879f5297 (patch)
tree63ad1caa8ac41d80394e6357dceb69715a6303b9
parent90489b78a80a1ee2204872c6ff434c476f4970cd (diff)
more work on organizing this
-rw-r--r--argv.Print.go11
-rw-r--r--argv.parseOsArgs.go4
-rw-r--r--init.go1
-rw-r--r--theMagicOfAutocomplete.go69
4 files changed, 46 insertions, 39 deletions
diff --git a/argv.Print.go b/argv.Print.go
index db4d590..f57cbd5 100644
--- a/argv.Print.go
+++ b/argv.Print.go
@@ -67,15 +67,20 @@ func PrintStddbg() {
if !me.debug {
return
}
+ f, err := os.OpenFile("/tmp/argv.debug", os.O_APPEND|os.O_RDWR|os.O_CREATE, 0644)
+ if err != nil {
+ panic("WTF openfile")
+ }
+ defer f.Close()
lines := strings.Split(strings.TrimSpace(PB.Stddbg), "\n")
if len(lines) == 0 {
return
}
- fmt.Fprintf(os.Stderr, "\n")
+ fmt.Fprintf(f, "\n")
for _, line := range lines {
- fmt.Fprintf(os.Stderr, "%s\n", line)
+ fmt.Fprintf(f, "%s\n", line)
}
- fmt.Fprintf(os.Stderr, "\n")
+ fmt.Fprintf(f, "\n")
}
func PrintStderr() {
diff --git a/argv.parseOsArgs.go b/argv.parseOsArgs.go
index 5df4a8d..37a477d 100644
--- a/argv.parseOsArgs.go
+++ b/argv.parseOsArgs.go
@@ -13,8 +13,8 @@ func GetCmd() string {
}
func mypanic(blah string) {
- me.debug = true
- doStdoutStderr()
+ // me.debug = true
+ // doStdoutStderr()
panic(blah)
}
diff --git a/init.go b/init.go
index a5b6c35..1c056d1 100644
--- a/init.go
+++ b/init.go
@@ -13,6 +13,7 @@ func Init(dest any, APPNAME string, anyString string, VERSION string) {
me = new(AutoType)
me.pb = new(Argv)
PB = me.pb
+ me.debug = true
// needed by bash for autocomplete, help & debugging
Stdout = NewStringWriter(&PB.Stdout) // bash uses this to match strings
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
}
}