Compare commits

..

No commits in common. "master" and "v0.0.8" have entirely different histories.

6 changed files with 39 additions and 93 deletions

View File

@ -21,7 +21,6 @@ message Auto { // `autogenpb:marshal` `
bool setupAuto = 11; // is true if '--bash' is set // setup bash autocomplete here bool setupAuto = 11; // is true if '--bash' is set // setup bash autocomplete here
bool debug = 12; // print debugging info if true bool debug = 12; // print debugging info if true
bool newline = 13; // was a newline was sent to STDERR? bool newline = 13; // was a newline was sent to STDERR?
string last = 14; // the last arg
} }
message Autos { // `autogenpb:marshal` `autogenpb:sort` `autogenpb:nomutex` message Autos { // `autogenpb:marshal` `autogenpb:sort` `autogenpb:nomutex`

View File

@ -73,31 +73,3 @@ func makeBashCompletionText2(argname string) string {
out += fmt.Sprintf("# copy and paste the above into your bash shell should work\n") out += fmt.Sprintf("# copy and paste the above into your bash shell should work\n")
return out return out
} }
// zsh:
/*
#compdef forge
# Zsh completion function for the 'forge' command.
_forge_completions() {
local -a words
local -i CURRENT
# Zsh's equivalent of Bash's COMP_WORDS and COMP_CWORD
words=("${(@)words}")
CURRENT=$CURRENT
# Generate the completion suggestions by calling the forge command.
# The output is split into an array.
local -a suggestions
suggestions=("${(@f)$(forge --auto-complete "'${words[CURRENT]}'" "${words[@]}")}")
# Pass the suggestions to the Zsh completion system.
_describe 'completions' suggestions
}
# Register the function to be called for the 'forge' command.
_forge_completions "$@"
*/

View File

@ -82,9 +82,7 @@ func (pb *Auto) doHandlePB() error {
dur := time.Since(found.Ctime.AsTime()) dur := time.Since(found.Ctime.AsTime())
pb.Duration = durationpb.New(dur) pb.Duration = durationpb.New(dur)
// found.PrintDebug() // found.PrintDebug()
cmd := fmt.Sprintf("cmd='%s'", found.Cmd) pb.Debugf("AUTO HISTORY: age=%s cmd='%s' partial='%s' argv='%v'", shell.FormatDuration(dur), found.Cmd, found.Partial, found.Argv)
arglast := fmt.Sprintf("last='%s'", found.Last)
pb.Debugf("AUTO HISTORY: age=%-6.6s %-18.18s %-18.18s partial='%s' argv='%v'", shell.FormatDuration(dur), cmd, arglast, found.Partial, found.Argv)
last = found last = found
} }
} }
@ -210,71 +208,60 @@ func (pb *Auto) Autocomplete2(sendthis string) {
} }
func parseArgv(argname string) *Auto { func parseArgv(argname string) *Auto {
pb := new(Auto) newauto := new(Auto)
pb.Argname = argname newauto.Argname = argname
if len(os.Args) == 0 { if len(os.Args) == 0 {
return pb return newauto
} }
if len(os.Args) > 1 && os.Args[1] == "--bash" { if len(os.Args) > 1 && os.Args[1] == "--bash" {
pb.SetupAuto = true newauto.SetupAuto = true
return pb return newauto
} }
// HACK: set debug flag if --autodebug is passed // HACK: set debug flag if --autodebug is passed
for _, s := range os.Args { for _, s := range os.Args {
if s == "--autodebug" { if s == "--autodebug" {
pb.Debug = true newauto.Debug = true
} }
} }
// should we do auto complete here? // should we do auto complete here?
if len(os.Args) > 1 && os.Args[1] == "--auto-complete" { if len(os.Args) > 1 && os.Args[1] == "--auto-complete" {
pb.IsAuto = true newauto.IsAuto = true
pb.Arg0 = os.Args[0] newauto.Arg0 = os.Args[0]
pb.Arg1 = os.Args[1] newauto.Arg1 = os.Args[1]
pb.Partial = os.Args[2] newauto.Partial = os.Args[2]
pb.Arg3 = os.Args[3] newauto.Arg3 = os.Args[3]
if len(os.Args) < 5 { if len(os.Args) < 5 {
// the user is doing autocomplete on the command itself // the user is doing autocomplete on the command itself
pb.Partial = "" newauto.Partial = ""
pb.Cmd = "" newauto.Cmd = ""
pb.Argv = []string{""} newauto.Argv = []string{""}
return pb return newauto
} }
pb.Argv = os.Args[4:] newauto.Argv = os.Args[4:]
if pb.Partial == "''" { if newauto.Partial == "''" {
pb.Partial = "" newauto.Partial = ""
pb.Cmd = "todo:findme" newauto.Cmd = "todo:findme"
} }
// set pb.Cmd to the first thing that doesn't have a '-' arg // set pb.Cmd to the first thing that doesn't have a '-' arg
for _, s := range pb.Argv { for _, s := range newauto.Argv {
if strings.HasPrefix(s, "-") { if strings.HasPrefix(s, "-") {
continue continue
} }
pb.Cmd = s newauto.Cmd = s
break break
} }
if pb.Partial == "'"+pb.Cmd+"'" { if newauto.Partial == "'"+newauto.Cmd+"'" {
// not really a command, it's just a partially inputed string from the user // not really a command, it's just a partially inputed string from the user
pb.Cmd = "" newauto.Cmd = ""
} }
// try to figure out what the last argv is // if newauto.Cmd == "" {
for _, s := range pb.Argv { // newauto.Cmd = strings.Join(newauto.Argv, "BLAH")
p := fmt.Sprintf("'%s'", s)
if pb.Partial == p {
pb.Debugf("DEBUG: MATCH Partial %s %s", s, p)
continue
} else {
pb.Debugf("DEBUG: NO MATCH Partial %s %s", s, p)
}
pb.Last = s
}
// if pb.Cmd == "" {
// pb.Cmd = strings.Join(pb.Argv, "BLAH")
// } // }
} }
return pb return newauto
} }
// also try to parse/send cur (?) // also try to parse/send cur (?)
@ -314,7 +301,9 @@ func Bash2(argname string, appAutoFunc func(*Auto)) *Auto {
// func Bash3(appAutoFunc func(*Auto), dest any) *Auto { // func Bash3(appAutoFunc func(*Auto), dest any) *Auto {
func Bash3(dest any) *Auto { func Bash3(dest any) *Auto {
myAuto = new(AutoArgs) myAuto = new(AutoArgs)
findAppInfo(dest) // parses back to main() for argv info // myAuto.appName = argname
// myAuto.autoFunc = appAutoFunc
newTest(dest)
pb := parseArgv(myAuto.appName) pb := parseArgv(myAuto.appName)
if pb.SetupAuto { if pb.SetupAuto {
@ -323,9 +312,6 @@ func Bash3(dest any) *Auto {
os.Exit(0) os.Exit(0)
} }
myAuto.match = make(map[string]string)
myAuto.match["--gui"] = "andlabs gocui"
if pb.Debug { if pb.Debug {
// dump debug info // dump debug info
pb.PrintDebug() pb.PrintDebug()
@ -339,8 +325,6 @@ func Bash3(dest any) *Auto {
pb.Debug = true pb.Debug = true
} }
// prepart["--gui"] = "andlabs gocui"
arg.Register(&argBash) arg.Register(&argBash)
flags := []string{} flags := []string{}
for _, s := range pb.Argv { for _, s := range pb.Argv {
@ -364,15 +348,6 @@ func Bash3(dest any) *Auto {
} }
if pb.IsAuto { if pb.IsAuto {
for key, val := range myAuto.match {
if pb.Last == key {
pb.Debugf("DEBUG: last=%s found key %s = %s", pb.Last, key, val)
pb.Autocomplete2(val)
os.Exit(0)
} else {
pb.Debugf("DEBUG: NO MATCH last='%s' found key '%s' = %s", pb.Last, key, val)
}
}
myAuto.autoFunc(pb) // run the autocomplete function the user made for their application myAuto.autoFunc(pb) // run the autocomplete function the user made for their application
if pb.Debug { if pb.Debug {
// TODO: // TODO:

View File

@ -26,15 +26,13 @@ type ArgsBash struct {
// try this struct out (?) // try this struct out (?)
var myAuto *AutoArgs var myAuto *AutoArgs
// this is a work in progress
type AutoArgs struct { type AutoArgs struct {
id int // should be unique id int // should be unique
hidden bool // don't update the toolkits when it's hidden hidden bool // don't update the toolkits when it's hidden
Auto func([]string) // the function for shell autocomplete Auto func([]string)
appName string // a good way to track the name of the binary ? appName string // a good way to track the name of the binary ?
pp *arg.Parser // for parsing the command line args. Yay to alexf lint! pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
autoFunc func(*Auto) // also a function for autocomplete autoFunc func(*Auto)
match map[string]string // maps for strings
} }
// argname is the name of the executable // argname is the name of the executable
@ -62,6 +60,7 @@ func Bash(argname string, autocomplete func([]string)) *AutoArgs {
func (pb *Auto) PrintDebug() { func (pb *Auto) PrintDebug() {
dur := pb.Duration.AsDuration() 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, shell.FormatDuration(dur), pb.Argv) pb.Debugf("AUTOCOMPLETE: arg0='%s' arg1='%s' partial='%s' cmd='%s' age=%s argv=%v\n", pb.Arg0, pb.Arg1, pb.Partial, pb.Cmd, shell.FormatDuration(dur), pb.Argv)
// fmt.Println("--all --gui --verbose --force")
} }
// returns the last command (is blank if the current arg is not blank) // returns the last command (is blank if the current arg is not blank)

View File

@ -56,7 +56,7 @@ type AutoFuncd interface {
} }
// Described is the interface that the destination struct should implement to // Described is the interface that the destination struct should implement to
func findAppInfo(tmp interface{}) { func newTest(tmp interface{}) {
if tmp, ok := tmp.(Appnamed); ok { if tmp, ok := tmp.(Appnamed); ok {
myAuto.appName = tmp.Appname() myAuto.appName = tmp.Appname()
} else { } else {

1
gui.go
View File

@ -86,6 +86,7 @@ func Gui() *GuiPrep {
prepGui = new(GuiPrep) prepGui = new(GuiPrep)
prepGui.rootn = gui.PreInit(postMustParse) prepGui.rootn = gui.PreInit(postMustParse)
return prepGui return prepGui
} }