Skip to content

Commit

Permalink
Merge pull request #18 from hatsu38/feature/add-clipboard
Browse files Browse the repository at this point in the history
Add clipboard
  • Loading branch information
hatsu38 committed Aug 24, 2021
2 parents 5a3d908 + 0d1d0d3 commit c0510ee
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -3,6 +3,7 @@ module github.com/hatsu38/postman-tui
go 1.16

require (
github.com/atotto/clipboard v0.1.4
github.com/gdamore/tcell/v2 v2.4.0
github.com/rivo/tview v0.0.0-20210624165335-29d673af0ce2
)
2 changes: 2 additions & 0 deletions go.sum
@@ -1,3 +1,5 @@
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/tcell/v2 v2.3.3/go.mod h1:cTTuF84Dlj/RqmaCIV5p4w8uG1zWdk0SF6oBpwHp4fU=
Expand Down
19 changes: 18 additions & 1 deletion 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 All @@ -111,7 +112,7 @@ func (g *Gui) Run(i interface{}) error {
appFlex := tview.NewFlex()
appFlex.SetDirection(tview.FlexRow)
appFlex.AddItem(reqResflex, 0, 9, true)
appFlex.AddItem(g.NavTextView, 1, 1, false)
appFlex.AddItem(g.NavTextView, 2, 1, false)

g.ToUrlFieldFocus()

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
10 changes: 6 additions & 4 deletions gui/navigate.go
Expand Up @@ -14,10 +14,12 @@ 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",
"http": " Tab: move url field\n Enter: change http method",
"url": " Tab: move Response Field\n Enter: http request",
"resField": " Tab: move params table\n Enter: Copy response text to clipboard",
"paramsTable": " Tab: move body table, Enter: set query paramater, h/left arrow: Move left by one column, l/right arrow: Move right by one column,\n j/down arrow: Move down by one row, k/up arrow: Move up by one row, g/home: Move to the top, G/end: Move to the bottom",
"bodyTable": " Tab: move params table, Enter: set body paramater, h/left arrow: Move left by one column, l/right arrow: Move right by one column,\n j/down arrow: Move down by one row, k/up arrow: Move up by one row, g/home: Move to the top, G/end: Move to the bottom",
"copied": " Copied response text to clipboard!\n Tab: move params table Enter: Copy response text to clipboard",
},
}
}
Expand Down
14 changes: 14 additions & 0 deletions gui/res_text_view.go
@@ -1,6 +1,7 @@
package gui

import (
"github.com/atotto/clipboard"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
Expand Down Expand Up @@ -32,3 +33,16 @@ func newResTextView() *resTestView {

return textView
}

func (t *resTestView) setFunc(g *Gui) {
t.SetDoneFunc(func(key tcell.Key) {
switch key {
case tcell.KeyEnter:
txt := t.GetText(true)
clipboard.WriteAll(txt)
g.NavTextView.update("copied")
case tcell.KeyTab:
g.ToFocus()
}
})
}

0 comments on commit c0510ee

Please sign in to comment.