still tuning the autocomplete code

This commit is contained in:
Jeff Carr 2025-09-18 16:03:40 -05:00
parent e0c508f197
commit 87751f7c72
1 changed files with 25 additions and 15 deletions

View File

@ -253,20 +253,16 @@ func parseArgv(argname string) *Auto {
newauto.Cmd = s newauto.Cmd = s
break break
} }
if newauto.Cmd == "" { if newauto.Partial == "'"+newauto.Cmd+"'" {
newauto.Cmd = strings.Join(newauto.Argv, "BLAH") // not really a command, it's just a partially inputed string from the user
newauto.Cmd = ""
}
// if newauto.Cmd == "" {
// newauto.Cmd = strings.Join(newauto.Argv, "BLAH")
// }
} }
return newauto return newauto
} }
return newauto
}
// MustParse processes command line arguments and exits upon failure
func MustParse(dest ...interface{}) *arg.Parser {
// arg.
// register = append(register, dest...)
return arg.MustParse(dest)
}
// also try to parse/send cur (?) // also try to parse/send cur (?)
func Bash2(argname string, appAutoFunc func(*Auto)) *Auto { func Bash2(argname string, appAutoFunc func(*Auto)) *Auto {
@ -320,12 +316,14 @@ func Bash3(argname string, appAutoFunc func(*Auto), dest any) *Auto {
} }
if pb.IsAuto { if pb.IsAuto {
pb.doHandlePB() pb.doHandlePB() // read in the history protobuf file
if pb.Debug {
// TODO: // turn on debugging if duration < 200 milliseconds
// check here to see if there was any completion text sent dur := pb.Duration.AsDuration()
// if not, send "reset bash newline\n" to cause bash to redraw PS1 for the user if dur < time.Millisecond*200 {
pb.Debug = true
} }
arg.Register(&argBash) arg.Register(&argBash)
flags := []string{} flags := []string{}
for _, s := range pb.Argv { for _, s := range pb.Argv {
@ -334,6 +332,7 @@ func Bash3(argname string, appAutoFunc func(*Auto), dest any) *Auto {
} }
flags = append(flags, s) flags = append(flags, s)
} }
// pb.Debug = true
pb.Debugf("DEBUG: MustParse(%v)", flags) pb.Debugf("DEBUG: MustParse(%v)", flags)
var err error var err error
myAuto.pp, err = arg.ParseFlags(flags, dest) myAuto.pp, err = arg.ParseFlags(flags, dest)
@ -341,7 +340,18 @@ func Bash3(argname string, appAutoFunc func(*Auto), dest any) *Auto {
pb.Debugf("DEBUG: Parse error: %v", err) pb.Debugf("DEBUG: Parse error: %v", err)
} }
if myAuto.pp == nil {
pb.Debugf("DEBUG: myAuto.pp == nil after ParseFlags()")
} else {
pb.Debugf("DEBUG: myAuto.pp is ok after ParseFlags()")
}
appAutoFunc(pb) // run the autocomplete function the user made for their application appAutoFunc(pb) // run the autocomplete function the user made for their application
if pb.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
}
os.Exit(0) os.Exit(0)
} }