diff options
| -rw-r--r-- | auto.Print.go | 30 | ||||
| -rw-r--r-- | theMagicOfAutocomplete.go | 18 |
2 files changed, 33 insertions, 15 deletions
diff --git a/auto.Print.go b/auto.Print.go index 6c0d489..0fcdd8a 100644 --- a/auto.Print.go +++ b/auto.Print.go @@ -7,7 +7,6 @@ import ( "fmt" "os" "strings" - "time" "go.wit.com/lib/cobol" ) @@ -31,18 +30,27 @@ func (pb *Auto) Debugf(fmts string, parts ...any) { // print out auto complete debugging info func (pb *Auto) PrintDebug() { - dur := pb.Duration.AsDuration() - pb.Debugf("ARGV: 0='%s' 1='%s' p='%s' cmd='%s' age=(%s) argv=%v fast=%v\n", pb.Arg0, pb.Arg1, pb.Partial, pb.Cmd, cobol.FormatDuration(dur), pb.Argv, pb.Fast) + pb.PrintDebugNew("ARGV") } -func (pb *Autos) PrintHistory() { - for found := range pb.IterAll() { - cmd := fmt.Sprintf("cmd='%s'", found.Cmd) - arglast := fmt.Sprintf("last='%s'", found.Last) - partial := fmt.Sprintf("p='%s'", found.Partial) - dur := time.Since(found.Ctime.AsTime()) - age := fmt.Sprintf("age=(%s)", cobol.FormatDuration(dur)) - found.Debugf("HIST: %s %-18.18s %-18.18s %-12.12s argv='%v' fast=%v goargs='%v'", age, cmd, arglast, partial, found.Argv, found.Fast, found.Goargs) +func (pb *Auto) PrintDebugNew(msg string) { + cmd := fmt.Sprintf("cmd='%s'", pb.Cmd) + arglast := fmt.Sprintf("last='%s'", pb.Last) + partial := fmt.Sprintf("p='%s'", pb.Partial) + dur := cobol.Duration(pb.Ctime) + var fast string + if pb.Fast { + fast = "fast=1," + pb.Fastcmd + } else { + fast = "fast=0," + pb.Fastcmd + } + sargv := fmt.Sprintf("argv(%v)", pb.Argv) + pb.Debugf("%s: age=(%s) %-12.12s %-12.12s %-12.12s %s %s goargs='%v'", msg, dur, cmd, arglast, partial, fast, sargv, pb.Goargs) +} + +func (all *Autos) PrintHistory() { + for pb := range all.IterAll() { + pb.PrintDebugNew("HIST") } } diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go index 8d78c62..b1bf044 100644 --- a/theMagicOfAutocomplete.go +++ b/theMagicOfAutocomplete.go @@ -26,13 +26,16 @@ func Autocomplete(dest any) *Auto { } pb := parseArgv(myAuto.appName) // parses os.Args into a protobuf + // try to register bash args for go-args + arg.Register(&argBash) + arg.Register(&argGui) + // not autocompleting. return go-arg & the application if !pb.IsAuto { // save the pb & history all.Clone(pb) errors.Join(err, all.Save()) - arg.Register(&argBash) myAuto.pp = arg.MustParse(dest) myAuto.err = err return pb @@ -84,9 +87,14 @@ func Autocomplete(dest any) *Auto { if dur < time.Millisecond*200 { pb.Debug = true pb.Fast = true + pb.Fastcmd = pb.Cmd + if last.Fast { + if pb.Fastcmd == last.Fastcmd { + // do the smart something here + } + } } - arg.Register(&argBash) flags := []string{} for _, s := range pb.Argv { if s == "--autodebug" { @@ -94,10 +102,11 @@ func Autocomplete(dest any) *Auto { } flags = append(flags, s) } - // pb.Debug = true - // pb.Debugf("DEBUG: MustParse(%v)", flags) + + // use go-args to parse the structs so we can use them here 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) } @@ -110,6 +119,7 @@ func Autocomplete(dest any) *Auto { // save now. this is near the end probably all.Clone(pb) errors.Join(err, all.Save()) + // this is a work in progress if pb.Last == "--gui" { pb.Debugf("DEBUG: last=%s found --gui", pb.Last) |
