From 30428ec3a44f26e6de21f1e4b85c623c72a5106b Mon Sep 17 00:00:00 2001 From: Hossein Mehrabi Date: Tue, 29 May 2018 21:42:19 +0430 Subject: [PATCH 1/7] move checked todos to bottom --- todo/display.go | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/todo/display.go b/todo/display.go index 5d784af5..607173cc 100644 --- a/todo/display.go +++ b/todo/display.go @@ -14,14 +14,28 @@ func (widget *Widget) display() { maxLen := widget.longestLineLen(widget.list.Items) str := "" + checked := []*Item{} + uncheckedLen := 0 + var selected *Item + var newList List for idx, item := range widget.list.Items { foreColor, backColor := "white", "black" - if item.Checked { - foreColor = Config.UString("wtf.mods.todo.colors.checked", "white") + // save the selected one + if idx == widget.list.selected { + selected = item } - if widget.View.HasFocus() && idx == widget.list.selected { + if item.Checked { + checked = append(checked, item) + continue + } + + uncheckedLen++ + + if widget.View.HasFocus() && item == selected { + // set selected item index + newList.selected = idx foreColor = Config.UString("wtf.mods.todo.colors.highlight.fore", "black") backColor = Config.UString("wtf.mods.todo.colors.highlight.back", "white") } @@ -35,7 +49,32 @@ func (widget *Widget) display() { ) str = str + wtf.PadRow((4+len(item.Text)), (4+maxLen)) + "\n" + + newList.Items = append(newList.Items, item) } + for idx, item := range checked { + foreColor, backColor := Config.UString("wtf.mods.todo.colors.checked", "white"), "black" + + if widget.View.HasFocus() && item == selected { + newList.selected = idx + uncheckedLen + foreColor = Config.UString("wtf.mods.todo.colors.highlight.fore", "black") + backColor = Config.UString("wtf.mods.todo.colors.highlight.back", "white") + } + str = str + fmt.Sprintf( + "[%s:%s]|%s| %s[white]", + foreColor, + backColor, + item.CheckMark(), + item.Text, + ) + + str = str + wtf.PadRow((4+len(item.Text)), (4+maxLen)) + "\n" + + newList.Items = append(newList.Items, item) + } + + // update list with new Items and selected item index + widget.list = &newList fmt.Fprintf(widget.View, "%s", str) } From 94b9b57c35b4cdae8027348b3267ea7af573dbf3 Mon Sep 17 00:00:00 2001 From: Grazfather Date: Tue, 29 May 2018 09:32:37 -0700 Subject: [PATCH 2/7] Fix install instructions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4cc90342..7be61e9a 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ package). ```bash go get github.com/senorprogrammer/wtf -cd $GOPATH/github.com/senorprogrammer/wtf +cd $GOPATH/src/github.com/senorprogrammer/wtf make install make run ``` From 673cbe4c16c3e49ba3e424edaf5228b54b707bf0 Mon Sep 17 00:00:00 2001 From: Hossein Mehrabi Date: Tue, 29 May 2018 23:19:25 +0430 Subject: [PATCH 3/7] fixed focus problem after config live-reloading --- wtf.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/wtf.go b/wtf.go index 39e4b04f..68fe08a0 100644 --- a/wtf.go +++ b/wtf.go @@ -189,6 +189,12 @@ func makeWidgets(app *tview.Application, pages *tview.Pages) { todo.NewWidget(app, pages), weather.NewWidget(app, pages), } + + FocusTracker = wtf.FocusTracker{ + App: app, + Idx: -1, + Widgets: Widgets, + } } func loadConfig(configFlag *string) { @@ -236,12 +242,6 @@ func main() { makeWidgets(app, pages) - FocusTracker = wtf.FocusTracker{ - App: app, - Idx: -1, - Widgets: Widgets, - } - grid := buildGrid(Widgets) pages.AddPage("grid", grid, true, true) app.SetInputCapture(keyboardIntercept) From 9bc5d93651dc205dcc3c327ae70459a965e64620 Mon Sep 17 00:00:00 2001 From: Hossein Mehrabi Date: Tue, 29 May 2018 21:22:21 +0430 Subject: [PATCH 4/7] now flags support both short and long names. --- wtf.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/wtf.go b/wtf.go index 68fe08a0..2a80abba 100644 --- a/wtf.go +++ b/wtf.go @@ -1,13 +1,13 @@ package main import ( - "flag" "log" "os" "path/filepath" "time" "github.com/gdamore/tcell" + flags "github.com/jessevdk/go-flags" "github.com/olebedev/config" "github.com/radovskyb/watcher" "github.com/rivo/tview" @@ -214,17 +214,19 @@ func main() { os.Exit(1) } - flagConf := flag.String("config", filepath.Join(homeDir, ".wtf", "config.yml"), "Path to config file") - flagHelp := flag.Bool("help", false, "Show help") - flagVers := flag.Bool("version", false, "Show version info") - - flag.Parse() - - if *flagHelp { - help.DisplayHelpInfo(flag.Args()) + var cmdFlags struct { + Version bool `short:"v" long:"version" description:"Show Version Info"` + Config string `short:"c" long:"config" optional:"yes" description:"Path to config file"` } - if *flagVers { + var parser = flags.NewParser(&cmdFlags, flags.Default) + parser.Parse() + + if len(cmdFlags.Config) == 0 { + cmdFlags.Config = filepath.Join(homeDir, ".wtf", "config.yml") + } + + if cmdFlags.Version { help.DisplayVersionInfo(version) } @@ -235,7 +237,7 @@ func main() { wtf.CreateConfigDir() wtf.WriteConfigFile() - loadConfig(flagConf) + loadConfig(&cmdFlags.Config) app := tview.NewApplication() pages := tview.NewPages() @@ -248,7 +250,7 @@ func main() { // Loop in a routine to redraw the screen go redrawApp(app) - go watchForConfigChanges(app, flagConf, grid, pages) + go watchForConfigChanges(app, &cmdFlags.Config, grid, pages) if err := app.SetRoot(pages, true).Run(); err != nil { os.Exit(1) From 47a077a472d23792898b7b5ac82bb688ac285db6 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Tue, 29 May 2018 16:39:24 -0700 Subject: [PATCH 5/7] Help halts the program execution --- help/help.go | 30 +++++++++++++++--------------- wtf.go | 8 ++++++-- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/help/help.go b/help/help.go index 31f03278..e129b5de 100644 --- a/help/help.go +++ b/help/help.go @@ -11,25 +11,25 @@ import ( "github.com/senorprogrammer/wtf/weather" ) -func DisplayCommandInfo(args []string, version string) { - if len(args) == 0 { - return - } +//func DisplayCommandInfo(args []string, version string) { +//if len(args) == 0 { +//return +//} - cmd := args[0] +//cmd := args[0] - switch cmd { - case "help", "--help": - DisplayHelpInfo(args) - case "version", "--version": - DisplayVersionInfo(version) - } +//switch cmd { +//case "help", "--help": +//DisplayHelpInfo(args) +//case "version", "--version": +//DisplayVersionInfo(version) +//} -} +//} -func DisplayHelpInfo(args []string) { - if len(args) >= 1 { - fmt.Printf("%s\n", helpFor(args[0])) +func DisplayHelpInfo(moduleName string) { + if moduleName != "" { + fmt.Printf("%s\n", helpFor(moduleName)) } else { fmt.Println("\n --help takes a module name as an argument, i.e: '--help github'") } diff --git a/wtf.go b/wtf.go index 2a80abba..c06c84b3 100644 --- a/wtf.go +++ b/wtf.go @@ -215,12 +215,16 @@ func main() { } var cmdFlags struct { - Version bool `short:"v" long:"version" description:"Show Version Info"` Config string `short:"c" long:"config" optional:"yes" description:"Path to config file"` + Version bool `short:"v" long:"version" description:"Show Version Info"` } var parser = flags.NewParser(&cmdFlags, flags.Default) - parser.Parse() + if _, err := parser.Parse(); err != nil { + if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp { + os.Exit(0) + } + } if len(cmdFlags.Config) == 0 { cmdFlags.Config = filepath.Join(homeDir, ".wtf", "config.yml") From ebf900e91b2de7b0f47cb2b45aa0cd8bce8c0a1d Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Tue, 29 May 2018 17:38:56 -0700 Subject: [PATCH 6/7] Pull command flags out of main() and into its own file --- help/help.go | 21 ------------------- wtf.go | 48 ++++++++------------------------------------ wtf/command_flags.go | 45 +++++++++++++++++++++++++++++++++++++++++ wtf/config_files.go | 2 ++ 4 files changed, 55 insertions(+), 61 deletions(-) create mode 100644 wtf/command_flags.go diff --git a/help/help.go b/help/help.go index e129b5de..dec44109 100644 --- a/help/help.go +++ b/help/help.go @@ -11,22 +11,6 @@ import ( "github.com/senorprogrammer/wtf/weather" ) -//func DisplayCommandInfo(args []string, version string) { -//if len(args) == 0 { -//return -//} - -//cmd := args[0] - -//switch cmd { -//case "help", "--help": -//DisplayHelpInfo(args) -//case "version", "--version": -//DisplayVersionInfo(version) -//} - -//} - func DisplayHelpInfo(moduleName string) { if moduleName != "" { fmt.Printf("%s\n", helpFor(moduleName)) @@ -37,11 +21,6 @@ func DisplayHelpInfo(moduleName string) { os.Exit(0) } -func DisplayVersionInfo(version string) { - fmt.Printf("Version: %s\n", version) - os.Exit(0) -} - func helpFor(moduleName string) string { switch moduleName { case "git": diff --git a/wtf.go b/wtf.go index c06c84b3..ab649fc7 100644 --- a/wtf.go +++ b/wtf.go @@ -3,11 +3,9 @@ package main import ( "log" "os" - "path/filepath" "time" "github.com/gdamore/tcell" - flags "github.com/jessevdk/go-flags" "github.com/olebedev/config" "github.com/radovskyb/watcher" "github.com/rivo/tview" @@ -17,7 +15,6 @@ import ( "github.com/senorprogrammer/wtf/gcal" "github.com/senorprogrammer/wtf/git" "github.com/senorprogrammer/wtf/github" - "github.com/senorprogrammer/wtf/help" "github.com/senorprogrammer/wtf/jira" "github.com/senorprogrammer/wtf/newrelic" "github.com/senorprogrammer/wtf/opsgenie" @@ -107,7 +104,7 @@ func refreshAllWidgets() { } } -func watchForConfigChanges(app *tview.Application, configFlag *string, grid *tview.Grid, pages *tview.Pages) { +func watchForConfigChanges(app *tview.Application, configFlag string, grid *tview.Grid, pages *tview.Pages) { watch := watcher.New() // notify write events. @@ -130,7 +127,7 @@ func watchForConfigChanges(app *tview.Application, configFlag *string, grid *tvi }() // Watch config file for changes. - if err := watch.Add(*configFlag); err != nil { + if err := watch.Add(configFlag); err != nil { log.Fatalln(err) } @@ -197,42 +194,13 @@ func makeWidgets(app *tview.Application, pages *tview.Pages) { } } -func loadConfig(configFlag *string) { - Config = wtf.LoadConfigFile(*configFlag) +func loadConfig(configFlag string) { + Config = wtf.LoadConfigFile(configFlag) } func main() { - - /* - This allows the user to pass flags in however they prefer. It supports the likes of: - - wtf -help | --help - wtf -version | --version - */ - homeDir, err := wtf.Home() - if err != nil { - os.Exit(1) - } - - var cmdFlags struct { - Config string `short:"c" long:"config" optional:"yes" description:"Path to config file"` - Version bool `short:"v" long:"version" description:"Show Version Info"` - } - - var parser = flags.NewParser(&cmdFlags, flags.Default) - if _, err := parser.Parse(); err != nil { - if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp { - os.Exit(0) - } - } - - if len(cmdFlags.Config) == 0 { - cmdFlags.Config = filepath.Join(homeDir, ".wtf", "config.yml") - } - - if cmdFlags.Version { - help.DisplayVersionInfo(version) - } + cmdFlags := wtf.NewCommandFlags() + cmdFlags.Parse(version) /* -------------------- end flag parsing and handling -------------------- */ @@ -241,7 +209,7 @@ func main() { wtf.CreateConfigDir() wtf.WriteConfigFile() - loadConfig(&cmdFlags.Config) + loadConfig(cmdFlags.Config) app := tview.NewApplication() pages := tview.NewPages() @@ -254,7 +222,7 @@ func main() { // Loop in a routine to redraw the screen go redrawApp(app) - go watchForConfigChanges(app, &cmdFlags.Config, grid, pages) + go watchForConfigChanges(app, cmdFlags.Config, grid, pages) if err := app.SetRoot(pages, true).Run(); err != nil { os.Exit(1) diff --git a/wtf/command_flags.go b/wtf/command_flags.go new file mode 100644 index 00000000..9163634e --- /dev/null +++ b/wtf/command_flags.go @@ -0,0 +1,45 @@ +package wtf + +import ( + "fmt" + "os" + "path/filepath" + + flags "github.com/jessevdk/go-flags" +) + +type CommandFlags struct { + Config string `short:"c" long:"config" optional:"yes" description:"Path to config file"` + Version bool `short:"v" long:"version" description:"Show Version Info"` +} + +func NewCommandFlags() *CommandFlags { + cmdFlags := CommandFlags{} + return &cmdFlags +} + +/* -------------------- Exported Functions -------------------- */ + +func (cmdFlags *CommandFlags) Parse(version string) { + parser := flags.NewParser(cmdFlags, flags.Default) + if _, err := parser.Parse(); err != nil { + if flagsErr, ok := err.(*flags.Error); ok && flagsErr.Type == flags.ErrHelp { + os.Exit(0) + } + } + + if len(cmdFlags.Config) == 0 { + homeDir, err := Home() + if err != nil { + os.Exit(1) + } + + cmdFlags.Config = filepath.Join(homeDir, ".wtf", "config.yml") + fmt.Printf(">> A: %s\n", cmdFlags.Config) + } + + if cmdFlags.Version { + fmt.Printf("Version: %s\n", version) + os.Exit(0) + } +} diff --git a/wtf/config_files.go b/wtf/config_files.go index ff57654d..1dbf86e5 100644 --- a/wtf/config_files.go +++ b/wtf/config_files.go @@ -59,6 +59,8 @@ func CreateFile(fileName string) (string, error) { // LoadConfigFile loads the config.yml file to configure the app func LoadConfigFile(filePath string) *config.Config { + fmt.Printf(">> B: %s\n", filePath) + absPath, _ := ExpandHomeDir(filePath) cfg, err := config.ParseYamlFile(absPath) From f13abc9ed37471335e9f1e1f02122f596c3ca668 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Tue, 29 May 2018 18:02:11 -0700 Subject: [PATCH 7/7] Closes #72. --info flag displays module help text Usage: wtf -i=todo wtf --info=todo --- wtf.go | 5 +++++ wtf/command_flags.go | 12 ++++++++++-- wtf/config_files.go | 2 -- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/wtf.go b/wtf.go index ab649fc7..8329bcbd 100644 --- a/wtf.go +++ b/wtf.go @@ -15,6 +15,7 @@ import ( "github.com/senorprogrammer/wtf/gcal" "github.com/senorprogrammer/wtf/git" "github.com/senorprogrammer/wtf/github" + "github.com/senorprogrammer/wtf/help" "github.com/senorprogrammer/wtf/jira" "github.com/senorprogrammer/wtf/newrelic" "github.com/senorprogrammer/wtf/opsgenie" @@ -202,6 +203,10 @@ func main() { cmdFlags := wtf.NewCommandFlags() cmdFlags.Parse(version) + if cmdFlags.HasInfo() { + help.DisplayHelpInfo(cmdFlags.Info) + } + /* -------------------- end flag parsing and handling -------------------- */ // Responsible for creating the configuration directory and default diff --git a/wtf/command_flags.go b/wtf/command_flags.go index 9163634e..f876d8de 100644 --- a/wtf/command_flags.go +++ b/wtf/command_flags.go @@ -10,6 +10,7 @@ import ( type CommandFlags struct { Config string `short:"c" long:"config" optional:"yes" description:"Path to config file"` + Info string `short:"i" long:"info" optional:"yes" description:"Display info about the specified module"` Version bool `short:"v" long:"version" description:"Show Version Info"` } @@ -20,6 +21,14 @@ func NewCommandFlags() *CommandFlags { /* -------------------- Exported Functions -------------------- */ +func (cmdFlags *CommandFlags) HasConfig() bool { + return len(cmdFlags.Config) > 0 +} + +func (cmdFlags *CommandFlags) HasInfo() bool { + return len(cmdFlags.Info) > 0 +} + func (cmdFlags *CommandFlags) Parse(version string) { parser := flags.NewParser(cmdFlags, flags.Default) if _, err := parser.Parse(); err != nil { @@ -28,14 +37,13 @@ func (cmdFlags *CommandFlags) Parse(version string) { } } - if len(cmdFlags.Config) == 0 { + if !cmdFlags.HasConfig() { homeDir, err := Home() if err != nil { os.Exit(1) } cmdFlags.Config = filepath.Join(homeDir, ".wtf", "config.yml") - fmt.Printf(">> A: %s\n", cmdFlags.Config) } if cmdFlags.Version { diff --git a/wtf/config_files.go b/wtf/config_files.go index 1dbf86e5..ff57654d 100644 --- a/wtf/config_files.go +++ b/wtf/config_files.go @@ -59,8 +59,6 @@ func CreateFile(fileName string) (string, error) { // LoadConfigFile loads the config.yml file to configure the app func LoadConfigFile(filePath string) *config.Config { - fmt.Printf(">> B: %s\n", filePath) - absPath, _ := ExpandHomeDir(filePath) cfg, err := config.ParseYamlFile(absPath)