From be1d3c3eb2f31053fc52e2e99781bfb827705a77 Mon Sep 17 00:00:00 2001 From: Shodiq Date: Thu, 2 Jan 2020 13:46:44 +0700 Subject: [PATCH] new shortcut clear all tabs --- README.md | 1 + commands.go | 11 +++++++++++ config/config.go | 1 + sample-config.toml | 1 + wuzz.go | 37 +++++++++++++++++++++++++++++-------- 5 files changed, 43 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 68d2ee1..99bd382 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ Keybinding | Description Ctrl+K, Shift+Tab | Previous view Ctlr+J, Tab | Next view Ctlr+T | Toggle context specific search +Ctrl+L | Clear all tabs to default Alt+H | Toggle history Down | Move down one view line Up | Move up one view line diff --git a/commands.go b/commands.go index f312896..f5a798b 100644 --- a/commands.go +++ b/commands.go @@ -119,6 +119,17 @@ var COMMANDS map[string]func(string, *App) CommandFunc = map[string]func(string, return nil } }, + "clearTabs": func(_ string, a *App) CommandFunc { + return func(g *gocui.Gui, _ *gocui.View) error { + if a.currentPopup != "" { + return nil + } + + a.restoreRequest(g, 0, true) + g.SetCurrentView(URL_VIEW) + return nil + } + }, } func scrollView(v *gocui.View, dy int) error { diff --git a/config/config.go b/config/config.go index f0dec95..f1258d1 100644 --- a/config/config.go +++ b/config/config.go @@ -62,6 +62,7 @@ var DefaultKeys = map[string]map[string]string{ "CtrlO": "openEditor", "CtrlT": "toggleContextSpecificSearch", "CtrlX": "clearHistory", + "CtrlL": "clearTabs", "Tab": "nextView", "CtrlJ": "nextView", "CtrlK": "prevView", diff --git a/sample-config.toml b/sample-config.toml index 37376aa..05c82dd 100644 --- a/sample-config.toml +++ b/sample-config.toml @@ -19,6 +19,7 @@ CtrlF = "loadRequest" CtrlE = "saveRequest" CtrlT = "toggleContextSpecificSearch" CtrlX = "clearHistory" +CtrlL = "clearTabs" Tab = "nextView" CtrlJ = "nextView" CtrlK = "prevView" diff --git a/wuzz.go b/wuzz.go index b05e358..68fcbd7 100644 --- a/wuzz.go +++ b/wuzz.go @@ -1102,6 +1102,16 @@ func (a *App) SetKeys(g *gocui.Gui) error { return nil }) + g.SetKeybinding(ALL_VIEWS, gocui.KeyCtrlL, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error { + if a.currentPopup != "" { + return nil + } + + a.restoreRequest(g, 0, true) + g.SetCurrentView(URL_VIEW) + return nil + }) + g.SetKeybinding(REQUEST_METHOD_VIEW, gocui.KeyEnter, gocui.ModNone, a.ToggleMethodList) cursDown := func(g *gocui.Gui, v *gocui.View) error { @@ -1126,7 +1136,7 @@ func (a *App) SetKeys(g *gocui.Gui) error { if len(a.history) <= cy { return nil } - a.restoreRequest(g, cy) + a.restoreRequest(g, cy, false) return nil }) @@ -1445,13 +1455,19 @@ func (a *App) OpenSaveResultView(saveResult string, g *gocui.Gui) (err error) { return err } -func (a *App) restoreRequest(g *gocui.Gui, idx int) { - if idx < 0 || idx >= len(a.history) { +func (a *App) restoreRequest(g *gocui.Gui, idx int, isCleanToggle bool) { + if (idx < 0 || idx >= len(a.history)) && !isCleanToggle { return } - a.closePopup(g, HISTORY_VIEW) - a.historyIndex = idx - r := a.history[idx] + r := &Request{ + Url: fmt.Sprintf("%s://", a.config.General.DefaultURLScheme), + Method: http.MethodGet, + } + if !isCleanToggle { + a.closePopup(g, HISTORY_VIEW) + a.historyIndex = idx + r = a.history[idx] + } v, _ := g.View(URL_VIEW) setViewTextAndCursor(v, r.Url) @@ -1471,8 +1487,13 @@ func (a *App) restoreRequest(g *gocui.Gui, idx int) { v, _ = g.View(RESPONSE_HEADERS_VIEW) setViewTextAndCursor(v, r.ResponseHeaders) - a.PrintBody(g) - + switch isCleanToggle { + case true: + v, _ = g.View(RESPONSE_BODY_VIEW) + setViewTextAndCursor(v, "") + default: + a.PrintBody(g) + } } func (a *App) LoadConfig(configPath string) error {