diff options
| -rw-r--r-- | argv.Print.go | 10 | ||||
| -rw-r--r-- | theMagicOfAutocomplete.go | 40 |
2 files changed, 33 insertions, 17 deletions
diff --git a/argv.Print.go b/argv.Print.go index 5f57421..368cf7b 100644 --- a/argv.Print.go +++ b/argv.Print.go @@ -11,11 +11,15 @@ import ( "go.wit.com/lib/cobol" ) -// decides here to print to STDERR or not func (pb *Argv) Debugf(fmts string, parts ...any) { + Debugf(fmts, parts...) +} + +// decides here to print to STDERR or not +func Debugf(fmts string, parts ...any) { fmts = strings.TrimSpace(fmts) fmts += "\n" - pb.Stderr += fmt.Sprintf(fmts, parts...) + me.pb.Stderr += fmt.Sprintf(fmts, parts...) } // print out auto complete debugging info @@ -40,7 +44,7 @@ func (pb *Argv) PrintDebugNew(msg string) { fast = "fast=0," + pb.GetCmd() } sargv := fmt.Sprintf("argv(%v)", pb.Real) - pb.Debugf("%s: age=(%s) %-12.12s %-12.12s %-12.12s %s %s goargs='%v' len(%d)", msg, dur, cmd, arglast, partial, fast, sargv, pb.Goargs, me.all.Len()) + Debugf("%s: age=(%s) %-12.12s %-12.12s %-12.12s %s %s goargs='%v' len(%d)", msg, dur, cmd, arglast, partial, fast, sargv, pb.Goargs, me.all.Len()) } func (all *Argvs) PrintHistory() { diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go index 571c280..9c9010b 100644 --- a/theMagicOfAutocomplete.go +++ b/theMagicOfAutocomplete.go @@ -79,10 +79,11 @@ func Autocomplete(dest any) *Argv { // user is trying to setup bash or zsh autocomplete // --bash or --zsh is the first os.Args if me.setupAuto { + savePB() // --bash or --zsh was passed. try to configure bash-completion MakeAutocompleteFiles(me.pb.AppInfo.APPNAME) - // never forget to run this our you will hate yourself and the choices you have made - os.Exit(0) + // never forget to exit here or you will hate yourself and the choices you have made + saveAndExit() } env.SetGlobal("argv", "real", fmt.Sprintf("%v", me.pb.Real)) @@ -94,8 +95,10 @@ func Autocomplete(dest any) *Argv { if me.isAuto { // do autocomplete and exit + savePB() doAutocomplete() - os.Exit(0) + // todo: this never gets here. fix that + saveAndExit() } // not autocompleting. return to the application @@ -126,6 +129,7 @@ func doAutocomplete() { // dump debug info me.pb.PrintDebug() me.all.PrintHistory() + // me.pb.PrintStderr() } // roll the autocomplete file @@ -182,7 +186,7 @@ func doAutocomplete() { me.pb.Debugf("DEBUG: real=(%v) found --gui", me.pb.Real) me.pb.PrintStderr() me.pb.SendString("andlabs gogui") - os.Exit(0) + saveAndExit() } else { // me.pb.Debugf("DEBUG: NO MATCH last='%s' found key '%s' = %s", me.last, key, val) } @@ -219,6 +223,8 @@ func doAutocomplete() { me.pb.HelpCounter = me.last.HelpCounter + 1 if me.pb.HelpCounter < 3 { me.pb.PrintStderr() + } else { + saveAndExit() } } else { // this means the user is pressing tab. no longer doing stderr @@ -232,21 +238,27 @@ func doAutocomplete() { me.pb.HelpCounter = 0 } } else { + if me.autoFunc == nil { + me.pb.SubCommand(me.pb.Real...) + } else { + me.autoFunc(me.pb) // run the autocomplete function the user made for their application + } + if me.debug { + // TODO: + // check here to see if there was any completion text sent + // if not, send "reset bash newline\n" to cause bash to redraw PS1 for the user + } } + saveAndExit() +} +func savePB() { // save now. this is near the end probably me.all.Clone(me.pb) errors.Join(me.Err, me.all.Save()) +} - if me.autoFunc == nil { - me.pb.SubCommand(me.pb.Real...) - } else { - me.autoFunc(me.pb) // run the autocomplete function the user made for their application - } - if me.debug { - // TODO: - // check here to see if there was any completion text sent - // if not, send "reset bash newline\n" to cause bash to redraw PS1 for the user - } +func saveAndExit() { + savePB() os.Exit(0) } |
