From 894260660b7218c023db8ba27bba478bcfffe7c1 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 12 Oct 2025 09:49:06 -0500 Subject: more magic. It's smarter about key repeat now --- sendStrings.go | 37 ++++++++++++++++++++----------------- theMagicOfAutocomplete.go | 16 +++++++++++++++- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/sendStrings.go b/sendStrings.go index 2fe1977..78b7a6c 100644 --- a/sendStrings.go +++ b/sendStrings.go @@ -8,7 +8,6 @@ import ( "fmt" "os" "strings" - "time" "go.wit.com/log" ) @@ -30,25 +29,29 @@ func (pb *Auto) SendString(sendthis string) { // the application must send an array []string{"help", "run", "list"} func (pb *Auto) SendStrings(parts []string) { - dur := pb.Duration.AsDuration() - if dur < time.Millisecond*200 { - pb.Debug = true - /* - pb.Debugf("TODO: show extended help here '%s' '%s' %v dur=%v\n", pb.Arg0, pb.Arg1, pb.Argv, config.FormatDuration(dur)) - pb.PrintDebug() - fmt.Println(" ") - */ - if myAuto.pp == nil { - pb.Debugf("myAuto.pp == nil") - } else { - pb.Debugf("myAuto.pp != nil") - if pb.Cmd == "" { - myAuto.pp.WriteHelp(os.Stderr) + /* + dur := pb.Duration.AsDuration() + if dur < time.Millisecond*200 { + pb.Debug = true + // pb.Debugf("TODO: show extended help here '%s' '%s' %v dur=%v\n", pb.Arg0, pb.Arg1, pb.Argv, config.FormatDuration(dur)) + // pb.PrintDebug() + // fmt.Println(" ") + if myAuto.pp == nil { + pb.Debugf("myAuto.pp == nil") } else { - myAuto.pp.WriteHelpForSubcommand(os.Stderr, pb.Cmd) + pb.Debugf("myAuto.pp != nil") + if pb.Fast { + // this means the user is pressing tab. no longer doing stderr + } else { + if pb.Cmd == "" { + myAuto.pp.WriteHelp(os.Stderr) + } else { + myAuto.pp.WriteHelpForSubcommand(os.Stderr, pb.Cmd) + } + } } } - } + */ // parts := strings.Split(sendthis, " ") var all []string diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go index b1bf044..e1ad4d5 100644 --- a/theMagicOfAutocomplete.go +++ b/theMagicOfAutocomplete.go @@ -107,7 +107,7 @@ func Autocomplete(dest any) *Auto { myAuto.pp, err = arg.ParseFlags(flags, dest) if err != nil { // users has command line arguments that won't parse with go-args - pb.Debugf("DEBUG: Parse error: %v", err) + pb.Debugf("DEBUG: Parse error: %v flags(%v)", err, flags) } if myAuto.pp == nil { @@ -129,6 +129,20 @@ func Autocomplete(dest any) *Auto { // pb.Debugf("DEBUG: NO MATCH last='%s' found key '%s' = %s", pb.Last, key, val) } + if pb.Fast { + if last.Fast { + os.Exit(0) + } else { + // this means the user is pressing tab. no longer doing stderr + if pb.Cmd == "" { + myAuto.pp.WriteHelp(os.Stderr) + } else { + myAuto.pp.WriteHelpForSubcommand(os.Stderr, pb.Cmd) + } + } + } else { + } + if myAuto.autoFunc == nil { pb.SubCommand(pb.Argv...) } else { -- cgit v1.2.3