Skip to content

Commit

Permalink
Focus ResTextField
Browse files Browse the repository at this point in the history
  • Loading branch information
hatsu38 committed Aug 24, 2021
1 parent 5a3d908 commit af0664c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
17 changes: 17 additions & 0 deletions gui/gui.go
Expand Up @@ -91,6 +91,7 @@ func (g *Gui) Run(i interface{}) error {
inputUrlField.setFunc(g)
paramsTable.setFunc(g)
bodyTable.setFunc(g)
resTextView.setFunc(g)

httpFlex := tview.NewFlex()
httpFlex.SetDirection(tview.FlexColumn)
Expand Down Expand Up @@ -142,6 +143,7 @@ func (g *Gui) ToHTTPFieldFocus() {
g.ParamsTable.SetBordersColor(tcell.ColorWhite)
g.BodyTable.SetBordersColor(tcell.ColorWhite)
g.UrlField.SetBorderColor(tcell.ColorWhite)
g.ResTextView.SetBorderColor(tcell.ColorWhite)

g.HTTPTextView.SetBorderColor(tcell.ColorGreen)
g.NavTextView.update("http")
Expand All @@ -153,6 +155,7 @@ func (g *Gui) ToParamsTableFocus() {
g.HTTPTextView.SetBorderColor(tcell.ColorWhite)
g.UrlField.SetBorderColor(tcell.ColorWhite)
g.BodyTable.SetBorderColor(tcell.ColorWhite)
g.ResTextView.SetBorderColor(tcell.ColorWhite)

g.ParamsTable.SetBordersColor(tcell.ColorGreen)
g.NavTextView.update("paramsTable")
Expand All @@ -166,16 +169,30 @@ func (g *Gui) ToBodyTable() {
g.ParamsTable.SetBordersColor(tcell.ColorWhite)
g.UrlField.SetBorderColor(tcell.ColorWhite)
g.HTTPTextView.SetBorderColor(tcell.ColorWhite)
g.ResTextView.SetBorderColor(tcell.ColorWhite)

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

func (g *Gui) ToResTextField() {
g.App.SetFocus(g.ResTextView)
g.ParamsTable.SetBordersColor(tcell.ColorWhite)
g.UrlField.SetBorderColor(tcell.ColorWhite)
g.HTTPTextView.SetBorderColor(tcell.ColorWhite)
g.BodyTable.SetBordersColor(tcell.ColorWhite)

g.ResTextView.SetBorderColor(tcell.ColorGreen)
g.NavTextView.update("resField")
}

func (g *Gui) ToFocus() {
primitive := g.App.GetFocus()

switch primitive {
case g.UrlField:
g.ToResTextField()
case g.ResTextView:
g.ToParamsTableFocus()
case g.ParamsTable:
g.ToBodyTable()
Expand Down
3 changes: 2 additions & 1 deletion gui/navigate.go
Expand Up @@ -14,8 +14,9 @@ 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",
"url": " Tab: move Response Field, Enter: http request",
"resField": " Tab: move params table, Enter: set body paramater",
"paramsTable": " Tab: move body table, Enter: set query paramater",
"bodyTable": " Tab: move params table, Enter: set body paramater",
},
Expand Down
9 changes: 9 additions & 0 deletions gui/res_text_view.go
Expand Up @@ -32,3 +32,12 @@ func newResTextView() *resTestView {

return textView
}

func (t *resTestView) setFunc(g *Gui) {
t.SetDoneFunc(func(key tcell.Key) {
switch key {
case tcell.KeyTab:
g.ToFocus()
}
})
}

0 comments on commit af0664c

Please sign in to comment.