summaryrefslogtreecommitdiff
path: root/auto.Print.go
blob: 0fcdd8a413fd90996b3a7be96067c60cdb8e61da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package prep

// debug argv protobuf functions
// enable with --autodebug or Setenv( "AUTOCOMPLETE_VERBOSE" )

import (
	"fmt"
	"os"
	"strings"

	"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() {
	pb.PrintDebugNew("ARGV")
}

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")
	}
}

// todo: fix this
func (pb *Auto) WriteHelp() {
	myAuto.pp.WriteHelp(os.Stdout)
}