Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add requests popup view in current directory #136

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Keybinding | Description
<kbd>Ctlr+J</kbd>, <kbd>Tab</kbd> | Next view
<kbd>Ctlr+T</kbd> | Toggle context specific search
<kbd>Alt+H</kbd> | Toggle history
<kbd>Ctrl+Q</kbd> | Toggle requests view
<kbd>Down</kbd> | Move down one view line
<kbd>Up</kbd> | Move up one view line
<kbd>Page down</kbd> | Move down one view page
Expand Down
3 changes: 3 additions & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ var COMMANDS map[string]func(string, *App) CommandFunc = map[string]func(string,
return nil
}
},
"requests": func(_ string, a *App) CommandFunc {
return a.ToggleRequests
},
}

func scrollView(v *gocui.View, dy int) error {
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ var DefaultKeys = map[string]map[string]string{
"CtrlJ": "nextView",
"CtrlK": "prevView",
"AltH": "history",
"CtrlQ": "requests",
"F2": "focus url",
"F3": "focus get",
"F4": "focus method",
Expand Down
1 change: 1 addition & 0 deletions sample-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Tab = "nextView"
CtrlJ = "nextView"
CtrlK = "prevView"
AltH = "history"
CtrlQ = "requests"
F2 = "focus url"
F3 = "focus get"
F4 = "focus method"
Expand Down
48 changes: 48 additions & 0 deletions wuzz.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const (
SAVE_RESULT_VIEW = "save-result"
METHOD_LIST_VIEW = "method-list"
HELP_VIEW = "help"
REQUESTS_VIEW = "requests"
)

var VIEW_TITLES = map[string]string{
Expand Down Expand Up @@ -341,6 +342,7 @@ type App struct {
history []*Request
config *config.Config
statusLine *StatusLine
Requests []os.FileInfo
}

type ViewEditor struct {
Expand Down Expand Up @@ -1172,6 +1174,19 @@ func (a *App) SetKeys(g *gocui.Gui) error {
a.closePopup(g, SAVE_RESULT_VIEW)
return nil
})

g.SetKeybinding(REQUESTS_VIEW, gocui.KeyArrowDown, gocui.ModNone, cursDown)
g.SetKeybinding(REQUESTS_VIEW, gocui.KeyArrowUp, gocui.ModNone, cursUp)
g.SetKeybinding(REQUESTS_VIEW, gocui.KeyEnter, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {
_, cy := v.Cursor()
// TODO error
if len(a.Requests) <= cy {
return nil
}
a.LoadRequest(g, a.Requests[cy].Name())
a.closePopup(g, REQUESTS_VIEW)
return nil
})
return nil
}

Expand Down Expand Up @@ -1398,6 +1413,39 @@ func (a *App) ToggleMethodList(g *gocui.Gui, _ *gocui.View) (err error) {
return
}

func (a *App) ToggleRequests(g *gocui.Gui, _ *gocui.View) (err error) {
// Destroy if present
if a.currentPopup == REQUESTS_VIEW {
a.closePopup(g, REQUESTS_VIEW)
return
}

dir, err := os.Getwd()
if err != nil {
return
}
files, err := ioutil.ReadDir(dir)
a.Requests = files
if err != nil {
return
}

requestsView, err := a.CreatePopupView(REQUESTS_VIEW, 100, len(files), g)
if err != nil {
return
}
requestsView.Title = VIEW_TITLES[REQUESTS_VIEW]
for _, r := range files {
if r.IsDir() {
continue
}
fmt.Fprintln(requestsView, r.Name())
}
g.SetViewOnTop(REQUESTS_VIEW)
g.SetCurrentView(REQUESTS_VIEW)
return
}

func (a *App) OpenSaveDialog(title string, g *gocui.Gui, save func(g *gocui.Gui, v *gocui.View) error) error {
dialog, err := a.CreatePopupView(SAVE_DIALOG_VIEW, 60, 1, g)
if err != nil {
Expand Down