Skip to content

Commit

Permalink
added PrettyJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsunne committed Dec 22, 2022
1 parent d639e06 commit b26cb41
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Utils/Common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package Utils
import (
"encoding/json"
"fmt"
"github.com/tidwall/pretty"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -66,6 +67,10 @@ func ParseEsUrl(u string) string {
return fmt.Sprintf("%s://%s:%s", schema, domain, port)
}

func PrettyJson(s string) string {
return string(pretty.Pretty([]byte(s)))
}

func ColorizeJson(s string) string {
var r string
open := false
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/rivo/uniseg v0.4.3 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/term v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ github.com/rivo/uniseg v0.4.2 h1:YwD0ulJSJytLpiaWua0sBDusfsCZohxjxzVTYjwxfV8=
github.com/rivo/uniseg v0.4.2/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2 h1:46ULzRKLh1CwgRq2dC5SlBzEqqNCi8rreOZnNrbqcIY=
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func init() {
case tcell.KeyCtrlBackslash:
r, _ := tvIndices.GetSelection()
name := tvIndices.GetCell(r, 0)
tvInfo.SetTitle(fmt.Sprintf(" Index [%s] Documents ", name.Text))
GetDocsFromIndex(name.Text)
pages.SwitchToPage("docs")
return nil
Expand Down Expand Up @@ -228,6 +229,7 @@ func GetDocsFromIndex(idxName string) {
b := []byte(`{"query": { "match_all": {} }, "size": 100}`)
Utils.PostJson(fmt.Sprintf("%s/%s/_search", EsUrl, idxName), string(b), &docs)
tvDocsTable.Clear()
tvDocsTable.SetTitle(fmt.Sprintf(" Index [%s] Documents ", idxName))
tvDocsTable.SetBorder(true)
tvDocsTable.SetCell(0, 0, tview.NewTableCell("_id").
SetTextColor(tcell.ColorYellow).SetAlign(tview.AlignCenter))
Expand All @@ -243,7 +245,7 @@ func GetDocsFromIndex(idxName string) {
tvDocsTable.SetSelectedFunc(func(row, column int) {
r, _ := tvDocsTable.GetSelection()
name := tvDocsTable.GetCell(r, 1)
tvInfo.SetText(Utils.ColorizeJson(name.Text))
tvInfo.SetText(Utils.PrettyJson(name.Text))
pages.SwitchToPage("info")
})
tvInfo.SetDoneFunc(func(k tcell.Key) {
Expand Down Expand Up @@ -522,7 +524,7 @@ func selectedIndexFunc(row int, _ int, tbl *tview.Table) {

tvInfo.SetTitle(fmt.Sprintf(" Index [%s] Settings ", selectedIndexName))
body, _ := io.ReadAll(r.Body)
tvInfo.SetText(Utils.ColorizeJson(string(body)))
tvInfo.SetText(Utils.PrettyJson(string(body)))
pages.SwitchToPage("info")
tvInfo.SetDoneFunc(func(k tcell.Key) {
if k == tcell.KeyEscape {
Expand Down

0 comments on commit b26cb41

Please sign in to comment.