diff options
| author | Jeff Carr <[email protected]> | 2025-10-12 05:52:39 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-12 05:52:39 -0500 |
| commit | ab5017449578fa921cdaad16e6ce94ddd2e8c664 (patch) | |
| tree | b1124867d4c065b08654c1c1ece3aa9c6c61067c | |
| parent | bea3d53daa187b72919571e5b0f0cbb18baf1f11 (diff) | |
more housecleaning
| -rw-r--r-- | auto.Print.go | 52 | ||||
| -rw-r--r-- | structs.go | 29 |
2 files changed, 52 insertions, 29 deletions
diff --git a/auto.Print.go b/auto.Print.go new file mode 100644 index 0000000..b992e65 --- /dev/null +++ b/auto.Print.go @@ -0,0 +1,52 @@ +package prep + +// debug argv protobuf functions +// enable with --autodebug or Setenv( "AUTOCOMPLETE_VERBOSE" ) + +import ( + "fmt" + "os" + "strings" + "time" + + "go.wit.com/lib/cobol" +) + +// decides here to print to STDERR or not +func (pb *Auto) Debugf(fmts string, parts ...any) { + fmts = strings.TrimSpace(fmts) + fmts += "\n" + // NOTE: env doesn't work probably most (all?) the time because bash + // doesn't send all the ENV to autocomplete. so, trap on a "--autodebug" command line arg + if os.Getenv("AUTOCOMPLETE_VERBOSE") == "true" || pb.Debug { + if !pb.Newline { + fmt.Fprintf(os.Stderr, "\n") + pb.Newline = true + } + fmt.Fprintf(os.Stderr, fmts, parts...) + } else { + // fmt.Fprintf(os.Stderr, "NOT DOING ANYTHING\n") + } +} + +// print out auto complete debugging info +func (pb *Auto) PrintDebug() { + dur := pb.Duration.AsDuration() + pb.Debugf("AUTOCOMPLETE: arg0='%s' arg1='%s' partial='%s' cmd='%s' age=%s argv=%v\n", pb.Arg0, pb.Arg1, pb.Partial, pb.Cmd, cobol.FormatDuration(dur), pb.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("AUTO HISTORY: %s %-18.18s %-18.18s %-12.12s argv='%v' goargs='%v'", age, cmd, arglast, partial, found.Argv, found.Goargs) + } +} + +// todo: fix this +func (pb *Auto) WriteHelp() { + myAuto.pp.WriteHelp(os.Stdout) +} @@ -3,12 +3,9 @@ package prep // initializes logging and command line options import ( - "fmt" - "os" "strings" "go.wit.com/dev/alexflint/arg" - "go.wit.com/lib/cobol" ) /* @@ -37,32 +34,6 @@ type AutoArgs struct { autoFunc func(*Auto) // also a function for autocomplete } -// print out auto complete debugging info -func (pb *Auto) PrintDebug() { - dur := pb.Duration.AsDuration() - pb.Debugf("AUTOCOMPLETE: arg0='%s' arg1='%s' partial='%s' cmd='%s' age=%s argv=%v\n", pb.Arg0, pb.Arg1, pb.Partial, pb.Cmd, cobol.FormatDuration(dur), pb.Argv) -} - -func (pb *Auto) WriteHelp() { - myAuto.pp.WriteHelp(os.Stdout) -} - -func (pb *Auto) Debugf(fmts string, parts ...any) { - fmts = strings.TrimSpace(fmts) - fmts += "\n" - // NOTE: env doesn't work probably most (all?) the time because bash - // doesn't send all the ENV to autocomplete. so, trap on a "--autodebug" command line arg - if os.Getenv("AUTOCOMPLETE_VERBOSE") == "true" || pb.Debug { - if !pb.Newline { - fmt.Fprintf(os.Stderr, "\n") - pb.Newline = true - } - fmt.Fprintf(os.Stderr, fmts, parts...) - } else { - // fmt.Fprintf(os.Stderr, "NOT DOING ANYTHING\n") - } -} - // returns the last command (is blank if the current arg is not blank) func GetLast(cur string, argv []string) string { if cur != "''" { |
