Skip to content

Commit

Permalink
Add navigate
Browse files Browse the repository at this point in the history
  • Loading branch information
hatsu38 committed Aug 23, 2021
1 parent 5003413 commit 824354e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 16 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (

func usage() {
format :=
` _ _ _
` _ _ _
_ __ ___ ___| |_ _ __ ___ __ _ _ __ | |_ _ _(_)
| '_ \ / _ \/ __| __| '_ ' _ \ / _' | '_ \ _____| __| | | | |
| |_) | (_) \__ \ |_| | | | | | (_| | | | |_____| |_| |_| | |
Expand Down
27 changes: 27 additions & 0 deletions ui/navigate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ui

import (
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)

type navigate struct {
*tview.TextView
keybindings map[string]string
}

func newNavigate() *navigate {
return &navigate{
TextView: tview.NewTextView().SetTextColor(tcell.ColorYellow),
keybindings: map[string]string{
"url": " Tab: move params table, Enter: http request",
"http": " Tab: move url field, Enter: change http method",
"paramsTable": " Tab: move body table, Enter: set query paramater",
"bodyTable": " Tab: move params table, Enter: set body paramater",
},
}
}

func (n *navigate) update(panel string) {
n.SetText(n.keybindings[panel])
}
44 changes: 29 additions & 15 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Gui struct {
BodyTable *tview.Table
ResTextView *tview.TextView
HTTPTextView *tview.TextView
NavTextView *navigate
}

var (
Expand Down Expand Up @@ -48,6 +49,7 @@ func New() *Gui {
BodyTable: NewTable(),
ResTextView: NewTextView(" Response ", defaultText),
HTTPTextView: NewTextView(" HTTP ", "GET"),
NavTextView: newNavigate(),
}
return g
}
Expand Down Expand Up @@ -190,12 +192,19 @@ func (g *Gui) Run(i interface{}) error {
requestFlex.AddItem(paramsTable, 0, 5, false)
requestFlex.AddItem(bodyTable, 0, 5, false)

flex := tview.NewFlex()
flex.SetDirection(tview.FlexColumn)
flex.AddItem(requestFlex, 0, 5, true)
flex.AddItem(resTextView, 0, 3, false)
reqResflex := tview.NewFlex()
reqResflex.SetDirection(tview.FlexColumn)
reqResflex.AddItem(requestFlex, 0, 5, true)
reqResflex.AddItem(resTextView, 0, 3, false)

g.Pages.AddAndSwitchToPage("main", flex, true)
appFlex := tview.NewFlex()
appFlex.SetDirection(tview.FlexRow)
appFlex.AddItem(reqResflex, 0, 9, true)
appFlex.AddItem(g.NavTextView, 1, 1, false)

g.ToUrlFieldFocus()

g.Pages.AddAndSwitchToPage("main", appFlex, true)

if err := app.SetRoot(g.Pages, true).Run(); err != nil {
log.Println(err)
Expand All @@ -205,16 +214,6 @@ func (g *Gui) Run(i interface{}) error {
return nil
}

func (g *Gui) ToParamsTableFocus() {
g.App.SetFocus(g.ParamsTable)
g.ParamsTable.SetSelectable(true, true)
g.HTTPTextView.SetBorderColor(tcell.ColorWhite)
g.UrlField.SetBorderColor(tcell.ColorWhite)
g.BodyTable.SetBorderColor(tcell.ColorWhite)

g.ParamsTable.SetBordersColor(tcell.ColorGreen)
}

func (g *Gui) ToUrlFieldFocus() {
urlField := g.UrlField
g.App.SetFocus(urlField)
Expand All @@ -223,6 +222,7 @@ func (g *Gui) ToUrlFieldFocus() {
g.BodyTable.SetBorderColor(tcell.ColorWhite)

urlField.SetBorderColor(tcell.ColorGreen)
g.NavTextView.update("url")
}

func (g *Gui) ToHTTPFieldFocus() {
Expand All @@ -233,6 +233,19 @@ func (g *Gui) ToHTTPFieldFocus() {
g.UrlField.SetBorderColor(tcell.ColorWhite)

g.HTTPTextView.SetBorderColor(tcell.ColorGreen)
g.NavTextView.update("http")
}

func (g *Gui) ToParamsTableFocus() {
g.App.SetFocus(g.ParamsTable)
g.ParamsTable.SetSelectable(true, true)
g.HTTPTextView.SetBorderColor(tcell.ColorWhite)
g.UrlField.SetBorderColor(tcell.ColorWhite)
g.BodyTable.SetBorderColor(tcell.ColorWhite)

g.ParamsTable.SetBordersColor(tcell.ColorGreen)
g.NavTextView.update("paramsTable")

}

func (g *Gui) ToBodyTable() {
Expand All @@ -244,6 +257,7 @@ func (g *Gui) ToBodyTable() {
g.HTTPTextView.SetBorderColor(tcell.ColorWhite)

g.BodyTable.SetBordersColor(tcell.ColorGreen)
g.NavTextView.update("bodyTable")
}

func (g *Gui) ToFocus() {
Expand Down

0 comments on commit 824354e

Please sign in to comment.