diff --git a/Utils/Common.go b/Utils/Common.go index 785f5e0..0f29129 100644 --- a/Utils/Common.go +++ b/Utils/Common.go @@ -3,6 +3,7 @@ package Utils import ( "encoding/json" "fmt" + "github.com/tidwall/pretty" "net" "net/http" "net/url" @@ -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 diff --git a/go.mod b/go.mod index 497a04b..195abb1 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 6168e50..4b2ccad 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/main.go b/main.go index 7c1d2fa..8baeef4 100644 --- a/main.go +++ b/main.go @@ -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 @@ -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)) @@ -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) { @@ -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 {