diff options
| -rw-r--r-- | argv.Print.go | 52 | ||||
| -rw-r--r-- | argv.parseOsArgs.go | 4 | ||||
| -rw-r--r-- | argv.proto | 9 | ||||
| -rw-r--r-- | theMagicOfAutocomplete.go | 71 |
4 files changed, 76 insertions, 60 deletions
diff --git a/argv.Print.go b/argv.Print.go index 7c89404..db4d590 100644 --- a/argv.Print.go +++ b/argv.Print.go @@ -25,22 +25,16 @@ func Debugf(fmts string, parts ...any) { // print out auto complete debugging info func (pb *Argv) PrintDebug(last string) { - pb.PrintDebugNew("ARGV", last) + pb.PrintDebugNew("ARGV", me.last) } -func (pb *Argv) PrintDebugNew(msg string, last string) { +func (pb *Argv) PrintDebugNew(msg string, last *Argv) { cmd := fmt.Sprintf("cmd='%s'", pb.GetCmd()) - var arglast string - arglast = fmt.Sprintf("last='%s'", last) + // var arglast string + // arglast = fmt.Sprintf("last='%s'", last.GetCmd()) partial := fmt.Sprintf("p='%s'", pb.Partial) age := cobol.Duration(pb.Ctime) dur := cobol.Duration(pb.Duration) - var fast string - if pb.Fast { - fast = "fast=1," + pb.GetCmd() - } else { - fast = "fast=0," + pb.GetCmd() - } var dbg string if me.debug { @@ -49,29 +43,49 @@ func (pb *Argv) PrintDebugNew(msg string, last string) { dbg = "dbg=0" } sargv := fmt.Sprintf("argv(%v)", pb.Real) - top := fmt.Sprintf("%-4.4s age=(%s)dur(%s) %s h%2d %-12.12s %-12.12s", pb.Uuid, age, dur, dbg, pb.HelpCounter, cmd, arglast) - Debugf("%s: %s %-12.12s %s %s real='%v' len(%d)", msg, top, partial, fast, sargv, pb.Real, me.all.Len()) + fast := fmt.Sprintf("F%-2dout%-2derr%-2d", pb.Fast, pb.OutCounter, pb.ErrCounter) + top := fmt.Sprintf("%-4.4s age=(%s)dur(%s) %s %s %-12.12s", pb.Uuid, age, dur, dbg, fast, cmd) + Debugf("%s: %s %-12.12s %s cmd=%s real='%v' len(%d)", msg, top, partial, pb.GetCmd(), sargv, pb.Real, me.all.Len()) } -func (all *Argvs) PrintHistory(last string) { +func (all *Argvs) PrintHistory(msg string) { counter := 0 + var last *Argv + // for pb := range all.Argv[0:10] { for pb := range all.IterAll() { counter += 1 - // hist := fmt.Sprintf("HIST(%d)", counter) - hist := fmt.Sprintf("HIST") - pb.PrintDebugNew(hist, last) - if counter > 100 { + pb.PrintDebugNew(msg, last) + last = pb + if counter > 30 { // sometimes I'm dumb break } } } -func PrintStderr() { +func PrintStddbg() { if !me.debug { return } - lines := strings.Split(strings.TrimSpace(PB.Stderr), "\n") + lines := strings.Split(strings.TrimSpace(PB.Stddbg), "\n") + if len(lines) == 0 { + return + } + fmt.Fprintf(os.Stderr, "\n") + for _, line := range lines { + fmt.Fprintf(os.Stderr, "%s\n", line) + } + fmt.Fprintf(os.Stderr, "\n") +} + +func PrintStderr() { + var lines []string + for _, line := range strings.Split(strings.TrimSpace(PB.Stderr), "\n") { + if strings.TrimSpace(line) == "" { + continue + } + lines = append(lines, line) + } if len(lines) == 0 { return } diff --git a/argv.parseOsArgs.go b/argv.parseOsArgs.go index b82a92a..5df4a8d 100644 --- a/argv.parseOsArgs.go +++ b/argv.parseOsArgs.go @@ -12,10 +12,6 @@ func GetCmd() string { return PB.GetCmd() } -func SetDebug(b bool) { - me.debug = b -} - func mypanic(blah string) { me.debug = true doStdoutStderr() @@ -34,12 +34,13 @@ message Argv { // `autogenpb:marshal repeated string real = 5; // what will really be sent to the application string subcmd = 6; // the subcommand being processed. For "git pull <tab>", cmd would be "pull" string partial = 7; // if the user has only partially inputed something - bool fast = 8; // is autocomplete running quickly? + int32 fast = 8; // is autocomplete running quickly? string stdout = 9; // all output is loaded here before being sent to the shell string stderr = 10; // all output is loaded here before being sent to the shell - int32 helpCounter = 11; // counter to track if the help text has been sent to Stderr - string uuid = 12; // all output is loaded here before being sent to the shell - string stddbg = 13; // all output is loaded here before being sent to the shell + string stddbg = 11; // all output is loaded here before being sent to the shell + int32 outCounter = 12; // counter to track if the help text has been sent to Stderr + int32 errCounter = 13; // counter to track if the help text has been sent to Stderr + string uuid = 14; // all output is loaded here before being sent to the shell } message Argvs { // `autogenpb:marshal` `autogenpb:sort` `autogenpb:nomutex` diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go index 92163cb..c2bbefb 100644 --- a/theMagicOfAutocomplete.go +++ b/theMagicOfAutocomplete.go @@ -64,6 +64,9 @@ func Autocomplete() *Argv { // me.pp = arg.MustParse(dest) me.Err = errors.Join(me.Err, me.mustParseFunc()) fmt.Fprintf(Stddbg, "did mustParseFunc(). heading to forge. err(%v)\n", me.Err) + me.pb.ErrCounter = 0 + me.pb.OutCounter = 0 + savePB() doStdoutStderr() return me.pb } @@ -106,47 +109,48 @@ func prepareStdout() { } } - me.pb.HelpCounter = me.last.HelpCounter - fmt.Fprintf(Stddbg, "got to HelpCounter check err(%v)\n", me.Err) - - if me.pb.Fast { - if me.last.Fast { - me.pb.HelpCounter = me.last.HelpCounter + 1 + me.pb.ErrCounter = me.last.ErrCounter + me.pb.OutCounter = me.last.OutCounter + if me.pb.Fast == 0 { + errors.Join(me.Err, me.autoFunc()) // run the autocomplete function the user made for their application + } else { + if me.last.Fast > 0 { + me.pb.ErrCounter += 1 } else { - me.pb.HelpCounter = 0 + me.pb.ErrCounter = 0 } + } + if me.Err == nil { + fmt.Fprintf(Stddbg, "got to the end of Argv ok\n") } else { - errors.Join(me.Err, me.autoFunc()) // run the autocomplete function the user made for their application + fmt.Fprintf(Stddbg, "got to the end of Argv with err(%v)\n", me.Err) } - fmt.Fprintf(Stddbg, "got to the end err(%v)\n", me.Err) return } func savePB() { // save now. this is near the end probably me.all.Append(me.pb) - npb := new(Argv) + // npb := new(Argv) // npb.Uuid = uuid.New().String() - me.all.Append(npb) + // me.all.Append(npb) errors.Join(me.Err, me.all.Save()) } func doStdoutStderr() { if me.debug { - me.all.PrintHistory(me.last.GetCmd()) - fmt.Fprintf(Stddbg, "debug=true pb.Stdout (%v)\n", PB.Stdout) - } else { - if me.pb.Fast { - if me.pb.HelpCounter < 3 { - fmt.Fprintf(Stddbg, "help counter < 3\n") - } - } + me.all.PrintHistory("HIST") + fmt.Fprintf(Stddbg, "me.debug=true pb.Stdout=(%v)\n", strings.TrimSpace(PB.Stdout)) + PrintStddbg() } PrintStderr() - PrintStdout() + if PB.OutCounter < 9 { + PrintStdout() + } } func saveAndExit() { + PB.OutCounter += 1 savePB() doStdoutStderr() os.Exit(0) @@ -180,9 +184,7 @@ func examineArgvHistory() { maxsize := 17 trim := 10 if me.all.Len() > maxsize { - me.pb.Debugf("DEBUG: trim() history is over 17 len=%d vs new=%d", me.all.Len(), me.all.Len()-trim) - me.pb.Debugf("DEBUG: trim() history is over 17 len=%d vs new=%d", me.all.Len(), me.all.Len()-trim) - me.pb.Debugf("DEBUG: trim() history is over 17 len=%d vs new=%d", me.all.Len(), me.all.Len()-trim) + me.pb.Debugf("DEBUG: trim() history is over %d len=%d vs new=%d", maxsize, me.all.Len(), me.all.Len()-trim) me.all.Argvs = me.all.Argvs[me.all.Len()-trim:] // newall.Autos = me.all.Autos[0:10] } @@ -210,6 +212,7 @@ func examineArgvHistory() { continue } uuidmap[pb.Uuid] = pb + // more early code for debugging if things go really wrong // if me.debug { // hist := fmt.Sprintf("HISTNIL(%d)", counter) // pb.PrintDebugNew(hist, "too soon") @@ -231,16 +234,18 @@ func examineArgvHistory() { dur := time.Since(me.last.Ctime.AsTime()) me.pb.Duration = durationpb.New(dur) - if me.pb.Duration.AsDuration() < time.Millisecond*200 { - me.pb.Fast = true - if me.last.Fast { - // do the smart something here - if me.pb.GetCmd() == me.last.GetCmd() { - // turn on debugging if duration < 200 milliseconds - } else { - // reset help counter - me.pb.HelpCounter = 0 - } + // user keeps hitting tab. trigger help + if me.pb.Duration.AsDuration() < time.Millisecond*300 { + me.pb.Fast = me.last.Fast + 1 + // do the smart something here + if me.pb.GetCmd() == me.last.GetCmd() { + // turn on debugging if duration < 200 milliseconds + } else { + // reset help counter + me.pb.ErrCounter = 0 + me.pb.Fast = 0 } + } else { + me.pb.Fast = 0 } } |
