diff options
| author | Nikolaus Gotsche <n@softwarefools.com> | 2018-01-25 03:23:19 +0100 |
|---|---|---|
| committer | Nikolaus Gotsche <n@softwarefools.com> | 2018-01-25 03:23:19 +0100 |
| commit | 2d5c636a16f8b1eeff86e82f1b3c041d9b301796 (patch) | |
| tree | a02a4663439265c70d9c79217225d59f4229e0fa /interact.go | |
| parent | 2b1503c57722a417038d3e2dafa7faa23ef59a5b (diff) | |
Added Interactive Mode
And Colours
Gerneral Debugging
Diffstat (limited to 'interact.go')
| -rw-r--r-- | interact.go | 229 |
1 files changed, 229 insertions, 0 deletions
diff --git a/interact.go b/interact.go new file mode 100644 index 0000000..bbce1bb --- /dev/null +++ b/interact.go @@ -0,0 +1,229 @@ +package main + +import ( + //"os" + "strings" + "strconv" + + "github.com/abiosoft/ishell" + "github.com/fatih/color" +) + + +func interact() { + shell := ishell.New() + + cyan := color.New(color.FgCyan).SprintFunc() + yellow := color.New(color.FgYellow).SprintFunc() + green := color.New(color.FgGreen).SprintFunc() + boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc() + boldRed := color.New(color.FgRed, color.Bold).SprintFunc() + + // display info. + shell.Println("Starting interactive Shell") + + shell.AddCmd(&ishell.Cmd{ + Name: "new", + Help: "Start new Project", + Func: func(c *ishell.Context) { + c.Println(boldGreen("Start New Project")) + newProject() + showLastProject() + }, + }) + + shell.AddCmd(&ishell.Cmd{ + Name: "startnow", + Help: "Start a new Task immediately", + Func: func(c *ishell.Context) { + c.Println(boldGreen("New Task")) + newTask(projectid) + stdOut() + }, + }) + + shell.AddCmd(&ishell.Cmd{ + Name: "stopnow", + Help: "Stop the currently Open Task immediately", + Func: func(c *ishell.Context) { + c.Println(boldGreen("Stoping Task",opentask.id)) + closeTask() + stdOut() + }, + }) + + shell.AddCmd(&ishell.Cmd{ + Name: "project", + Help: "<id> Open a Project of the following id", + Func: func(c *ishell.Context) { + arg := "none" + if len(c.Args) > 0 { + arg = strings.Join(c.Args, " ") + argi,err := strconv.Atoi(arg) + if err == nil{ + c.Println(boldGreen("Opening Project",argi)) + setProject(argi) + stdOut() + }else{ + c.Println(boldRed(arg,"is not a valid id!")) + } + }else{ + c.Println(boldRed("project <id> - Please enter an id")) + allProjects() + } + }, + }) + + shell.AddCmd(&ishell.Cmd{ + Name: "edittask", + Help: "<id> Edit a Task of the following id", + Func: func(c *ishell.Context) { + arg := "none" + if len(c.Args) > 0 { + arg = strings.Join(c.Args, " ") + argi,err := strconv.Atoi(arg) + if err == nil{ + c.Println(boldGreen("Editing Task",argi)) + editTask(argi) + //stdOut() + }else{ + c.Println(boldRed(arg,"is not a valid id!")) + } + }else{ + c.Println(boldRed("edittask <id> - Please enter an id")) + } + }, + }) + + shell.AddCmd(&ishell.Cmd{ + Name: "editproject", + Help: "<id> Edit the Project of the following id", + Func: func(c *ishell.Context) { + arg := "none" + if len(c.Args) > 0 { + arg = strings.Join(c.Args, " ") + argi,err := strconv.Atoi(arg) + if err == nil{ + c.Println(boldGreen("Edit Project",argi)) + editProject(argi) + allProjects() + //stdOut() + }else{ + c.Println(boldRed(arg,"is not a valid id!")) + } + }else{ + c.Println(boldRed("editproject <id> - Please enter an id")) + allProjects() + } + }, + }) + + shell.AddCmd(&ishell.Cmd{ + Name: "start", + Help: "<DateTime> - Start Task at a specific Time 'YYYY-MM-DD HH:MM' Or 'HH:MM'", + Func: func(c *ishell.Context) { + arg := "none" + if len(c.Args) > 0 { + arg = strings.Join(c.Args, " ") + c.Println(boldGreen("Start Project at",arg)) + newTaskTime(projectid,arg) + // editProject(argi) + stdOut() + }else{ + c.Println(boldRed("start <DateTime> - Please enter a Datetime")) + } + }, + }) + + shell.AddCmd(&ishell.Cmd{ + Name: "stop", + Help: "<DateTime> - Stop Open Task at a specific Time 'YYYY-MM-DD HH:MM' Or 'HH:MM'", + Func: func(c *ishell.Context) { + arg := "none" + if len(c.Args) > 0 { + arg = strings.Join(c.Args, " ") + c.Println(boldGreen("Stop Task at",arg)) + closeTaskTime(arg) + stdOut() + }else{ + c.Println(boldRed("stop <DateTime> - Please enter a Datetime")) + } + }, + }) + + shell.AddCmd(&ishell.Cmd{ + Name: "all", + Help: "Show all Projects Project", + Func: func(c *ishell.Context) { + //c.Println(boldGreen("Start New Project")) + allProjects() + stdOut() + }, + }) + + + shell.AddCmd(&ishell.Cmd{ + Name: "color", + Help: "color print", + Func: func(c *ishell.Context) { + c.Print(cyan("cyan\n")) + c.Print(green("greencyan\n")) + c.Println(yellow("yellow")) + c.Printf("%s\n", boldRed("bold red")) + }, + }) + + // multiple choice + shell.AddCmd(&ishell.Cmd{ + Name: "choice", + Help: "multiple choice prompt", + Func: func(c *ishell.Context) { + choice := c.MultiChoice([]string{ + "Golangers", + "Go programmers", + "Gophers", + "Goers", + }, "What are Go programmers called ?") + if choice == 2 { + c.Println("You got it!") + } else { + c.Println("Sorry, you're wrong.") + } + }, + }) + +// multiple choice + shell.AddCmd(&ishell.Cmd{ + Name: "checklist", + Help: "checklist prompt", + Func: func(c *ishell.Context) { + languages := []string{"Python", "Go", "Haskell", "Rust"} + choices := c.Checklist(languages, + "What are your favourite programming languages ?", + nil) + out := func() (c []string) { + for _, v := range choices { + c = append(c, languages[v]) + } + return + } + c.Println("Your choices are", strings.Join(out(), ", ")) + }, + }) + + + shell.Run() + // teardown + shell.Close() +// when started with "exit" as first argument, assume non-interact ive execution + // if len(os.Args) > 1 && os.Args[1] == "exit" { + // shell.Process(os.Args[2:]...) + // } else { + // start shell + // shell.Run() + // teardown + // shell.Close() + //} +} + + |
