From d4619b162fa898f1549695ddb218bd51aabcdd86 Mon Sep 17 00:00:00 2001 From: Miguel Mota Date: Mon, 7 May 2018 18:48:27 -0700 Subject: [PATCH] fix q key press + add quit view action --- Makefile | 4 +++- README.md | 11 ++++++++--- cointop/actions.go | 1 + cointop/cointop.go | 13 ++++++------- cointop/keybindings.go | 9 ++++----- cointop/layout.go | 4 ++++ cointop/shortcuts.go | 4 ++-- 7 files changed, 28 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index cbdda66..d3d014e 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,9 @@ -all: +aul: @echo "no default" run: + go run main.go + debug: DEBUG=1 go run main.go diff --git a/README.md b/README.md index c997cfc..83bec33 100644 --- a/README.md +++ b/README.md @@ -145,7 +145,7 @@ Key|Action Home|Go to first line of page End|Go to last line of page Enter|Toggle [c]hart for highlighted coin -Esc|Quit +Esc|Quit view Space|Toggle coin as favorite Ctrl+c|Alias to quit Ctrl+d|Jump page down (vim inspired) @@ -187,7 +187,7 @@ Key|Action t|Sort table by *[t]otal supply* u|Sort table by *last [u]pdated* v|Sort table by *24 hour [v]olume* -q|[q]uit +q|[q]uit view $|Go to last page (vim inspired) ?|Show help| /|Search (vim inspired)| @@ -261,7 +261,7 @@ You can then configure the actions you want for each key: p = "sort_column_price" pagedown = "page_down" pageup = "page_up" - q = "quit" + q = "quit_view" r = "sort_column_rank" s = "sort_column_symbol" space = "toggle_favorite" @@ -298,6 +298,7 @@ Action|Description `previous_chart_range`|Select previous chart date range (e.g. 7D -> 3D) `previous_page`|Go to previous page `quit`|Quit application +`quit_view`|Quit view `refresh`|Do a manual refresh on the data `save`|Save config `show_currency_convert_menu`|Show currency convert menu @@ -445,6 +446,10 @@ Action|Description - A: The CoinMarketCap API has rate limits, so make sure to keep manual refreshes to a minimum. If you've hit the rate limit then wait about half an hour to be able to fetch the data again. Keep in mind the oinMarketCap updates prices every 5 minutes constant refreshes aren't necessary. +- Q: How do I quit the application? + + - A: Press ctrl+c to quit the application. + ## Development ### Go diff --git a/cointop/actions.go b/cointop/actions.go index fab59a9..23cbcf2 100644 --- a/cointop/actions.go +++ b/cointop/actions.go @@ -20,6 +20,7 @@ func actionsMap() map[string]bool { "page_up": true, "previous_page": true, "quit": true, + "quit_view": true, "refresh": true, "sort_column_1h_change": true, "sort_column_24h_change": true, diff --git a/cointop/cointop.go b/cointop/cointop.go index c085a28..63b33b2 100644 --- a/cointop/cointop.go +++ b/cointop/cointop.go @@ -184,15 +184,14 @@ func Run() { } func (ct *Cointop) quit() error { - if ct.helpvisible || ct.convertmenuvisible || ct.searchfieldvisible { - return nil - } - - return ct.forceQuit() + return gocui.ErrQuit } -func (ct *Cointop) forceQuit() error { - return gocui.ErrQuit +func (ct *Cointop) quitView() error { + if ct.activeViewName() == ct.tableviewname { + return ct.quit() + } + return nil } // Exit safely exit application diff --git a/cointop/keybindings.go b/cointop/keybindings.go index c9acc36..dd465bf 100644 --- a/cointop/keybindings.go +++ b/cointop/keybindings.go @@ -293,6 +293,8 @@ func (ct *Cointop) keybindings(g *gocui.Gui) error { case "quit": fn = ct.keyfn(ct.quit) view = "" + case "quit_view": + fn = ct.keyfn(ct.quitView) case "next_chart_range": fn = ct.keyfn(ct.nextChartRange) case "previous_chart_range": @@ -318,8 +320,8 @@ func (ct *Cointop) keybindings(g *gocui.Gui) error { } // keys to force quit - ct.setKeybindingMod(gocui.KeyCtrlC, gocui.ModNone, ct.keyfn(ct.forceQuit), "") - ct.setKeybindingMod(gocui.KeyCtrlZ, gocui.ModNone, ct.keyfn(ct.forceQuit), "") + ct.setKeybindingMod(gocui.KeyCtrlC, gocui.ModNone, ct.keyfn(ct.quit), "") + ct.setKeybindingMod(gocui.KeyCtrlZ, gocui.ModNone, ct.keyfn(ct.quit), "") // searchfield keys ct.setKeybindingMod(gocui.KeyEnter, gocui.ModNone, ct.keyfn(ct.doSearch), ct.searchfieldviewname) @@ -328,13 +330,10 @@ func (ct *Cointop) keybindings(g *gocui.Gui) error { // keys to quit help when open ct.setKeybindingMod(gocui.KeyEsc, gocui.ModNone, ct.keyfn(ct.hideHelp), ct.helpviewname) ct.setKeybindingMod('q', gocui.ModNone, ct.keyfn(ct.hideHelp), ct.helpviewname) - ct.setKeybindingMod('x', gocui.ModNone, ct.keyfn(ct.hideHelp), ct.helpviewname) - ct.setKeybindingMod('c', gocui.ModNone, ct.keyfn(ct.hideHelp), ct.helpviewname) // keys to quit convert menu when open ct.setKeybindingMod(gocui.KeyEsc, gocui.ModNone, ct.keyfn(ct.hideConvertMenu), ct.convertmenuviewname) ct.setKeybindingMod('q', gocui.ModNone, ct.keyfn(ct.hideConvertMenu), ct.convertmenuviewname) - ct.setKeybindingMod('x', gocui.ModNone, ct.keyfn(ct.hideConvertMenu), ct.convertmenuviewname) // character key press to select option // TODO: use scrolling table diff --git a/cointop/layout.go b/cointop/layout.go index d37afbd..239279b 100644 --- a/cointop/layout.go +++ b/cointop/layout.go @@ -150,6 +150,10 @@ func (ct *Cointop) setActiveView(v string) error { return nil } +func (ct *Cointop) activeViewName() string { + return ct.g.CurrentView().Name() +} + func (ct *Cointop) setViewOnBottom(v string) error { _, err := ct.g.SetViewOnBottom(v) return err diff --git a/cointop/shortcuts.go b/cointop/shortcuts.go index 7993c12..6017dc7 100644 --- a/cointop/shortcuts.go +++ b/cointop/shortcuts.go @@ -11,7 +11,7 @@ func defaultShortcuts() map[string]string { "home": "move_to_page_first_row", "end": "move_to_page_last_row", "enter": "toggle_row_chart", - "esc": "quit", + "esc": "quit_view", "space": "toggle_favorite", "ctrl+c": "quit", "ctrl+d": "page_down", @@ -54,7 +54,7 @@ func defaultShortcuts() map[string]string { "t": "sort_column_total_supply", "u": "sort_column_last_updated", "v": "sort_column_24h_volume", - "q": "quit", + "q": "quit_view", "$": "last_page", "?": "help", "/": "open_search",