Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/tui poc #1

Merged
merged 18 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rebuilt new ui - more functional
  • Loading branch information
aurc committed May 29, 2022
commit cc2985dfbed56e6e3e969799d232b602ab8f3d0d
119 changes: 44 additions & 75 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,97 +1,66 @@
package main

import (
"os"

"github.com/gdamore/tcell/v2"

"github.com/aurc/loggo/pkg/ui"
"github.com/aurc/loggo/pkg/loggo"
"github.com/rivo/tview"
"os"
)

var (
app *tview.Application
layout *tview.Flex
jsonViewer *ui.JsonViewer
)
//var (
// app *tview.Application
// layout *tview.Flex
// jsonViewer *ui.JsonViewer
//)

func main() {
app = tview.NewApplication()

//newPrimitive := func(text string) tview.Primitive {
// return tview.NewTextView().
// SetTextAlign(tview.AlignCenter).
// SetText(text)
//}
//searchBar := newPrimitive("JSON Viewer")
//textView := ui.NewJsonRenderer().
// SetJsonConfigIndent(ui.OrderSorted, " ")
//grid := tview.NewGrid().
// SetRows(0, 3, 3).
// SetColumns(0).
// SetBorders(true).
// AddItem(textView, 0, 0, 1, 1, 0, 0, true).
// AddItem(searchBar, 1, 0, 1, 1, 3, 0, false).
// AddItem(newPrimitive("Footer"), 2, 0, 1, 1, 0, 0, false)
app := tview.NewApplication()

jsonViewer = ui.MakeJsonViewer(app)
layout = tview.NewFlex().
SetDirection(tview.FlexRow).
AddItem(jsonViewer, 0, 1, true)
jsonViewer := loggo.NewJsonView(app)

b, err := os.ReadFile("testdata/test1.json")
if err != nil {
panic(err)
}

setKeyboardShortcuts()

jsonViewer.SetJson(b)
//textView.SetJson(b).SetChangedFunc(func() {
// app.Draw()
//})
if err := app.
SetRoot(layout, true).
SetFocus(jsonViewer).
SetRoot(jsonViewer, true).
EnableMouse(true).
Run(); err != nil {
panic(err)
}
}

func setKeyboardShortcuts() *tview.Application {
return app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {

//sc := unicode.ToLower(event.Rune())
//fmt.Printf("%v, %s\n", sc, string(sc))
// Global shortcuts
//switch unicode.ToLower(event.Rune()) {
//case 's':
// app.SetFocus(jsonViewer)
// return nil
//case 'q':
//case 't':
//
// os.Exit(0)
// return nil
//}
if e := jsonViewer.HandleShortcuts(event); e == nil {
return nil
}

//// Handle based on current focus. Handlers may modify event
//switch {
//case projectPane.HasFocus():
// event = projectPane.handleShortcuts(event)
//case taskPane.HasFocus():
// event = taskPane.handleShortcuts(event)
// if event != nil && projectDetailPane.isShowing() {
// event = projectDetailPane.handleShortcuts(event)
// }
//case taskDetailPane.HasFocus():
// event = taskDetailPane.handleShortcuts(event)
//}

return event
})
}
//func main() {
// app = tview.NewApplication()
//
// jsonViewer = ui.MakeJsonViewer(app)
// layout = tview.NewFlex().
// SetDirection(tview.FlexRow).
// AddItem(jsonViewer, 0, 1, true)
//
// b, err := os.ReadFile("testdata/test1.json")
// if err != nil {
// panic(err)
// }
//
// setKeyboardShortcuts()
//
// jsonViewer.SetJson(b)
//
// if err := app.
// SetRoot(layout, true).
// SetFocus(jsonViewer).
// EnableMouse(true).
// Run(); err != nil {
// panic(err)
// }
//}
//
//func setKeyboardShortcuts() *tview.Application {
// return app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
// if e := jsonViewer.HandleShortcuts(event); e == nil {
// return nil
// }
// return event
// })
//}
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ module github.com/aurc/loggo
go 1.18

require (
github.com/epiclabs-io/winman v0.0.0-20210113192526-493c730b8c71
github.com/gdamore/tcell/v2 v2.5.1
github.com/lithammer/fuzzysearch v1.1.5
github.com/rivo/tview v0.0.0-20220307222120-9994674d60a8
)

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/gdamore/encoding v1.0.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/stretchr/testify v1.7.1 // indirect
golang.org/x/sys v0.0.0-20220318055525-2edf467146b5 // indirect
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
21 changes: 21 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/epiclabs-io/winman v0.0.0-20210113192526-493c730b8c71 h1:6P4e37bQlGweIYBcxtdpd+Sp7Ay1bJsrumylZtx5RXQ=
github.com/epiclabs-io/winman v0.0.0-20210113192526-493c730b8c71/go.mod h1:AVxS652LTBtU9kZhCPbkKAzHVHqZR3uAyIx82si+Q68=
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.0.1-0.20201017141208-acf90d56d591/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA=
github.com/gdamore/tcell/v2 v2.1.0/go.mod h1:vSVL/GV5mCSlPC6thFP5kfOFdM9MGZcalipmpTxTgQA=
github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1/go.mod h1:Az6Jt+M5idSED2YPGtwnfJV0kXohgdCBPmHGSYc1r04=
github.com/gdamore/tcell/v2 v2.5.1 h1:zc3LPdpK184lBW7syF2a5C6MV827KmErk9jGVnmsl/I=
github.com/gdamore/tcell/v2 v2.5.1/go.mod h1:wSkrPaXoiIWZqW/g7Px4xc79di6FTcpB8tvaKJ6uGBo=
github.com/lithammer/fuzzysearch v1.1.5 h1:Ag7aKU08wp0R9QCfF4GoGST9HbmAIeLP7xwMrOBEp1c=
github.com/lithammer/fuzzysearch v1.1.5/go.mod h1:1R1LRNk7yKid1BaQkmuLQaHruxcC4HmAH30Dh61Ih1Q=
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/tview v0.0.0-20210111184519-c818a0c789ee/go.mod h1:0ha5CGekam8ZV1kxkBxSlh7gfQ7YolUj2P/VruwH0QY=
github.com/rivo/tview v0.0.0-20220307222120-9994674d60a8 h1:xe+mmCnDN82KhC010l3NfYlA8ZbOuzbXAzSYBa6wbMc=
github.com/rivo/tview v0.0.0-20220307222120-9994674d60a8/go.mod h1:WIfMkQNY+oq/mWwtsjOYHIZBuwthioY2srOmljJkTnk=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201017003518-b09fb700fbb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220318055525-2edf467146b5 h1:saXMvIOKvRFwbOMicHXr0B1uwoxq9dGmLe5ExMES6c4=
Expand All @@ -21,7 +38,11 @@ golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9sn
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d h1:SZxvLBoTP5yHO3Frd4z4vrF+DBX9vMVanchswa69toE=
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
27 changes: 27 additions & 0 deletions pkg/loggo/colour.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package loggo

import "github.com/gdamore/tcell/v2"

const (
ColourBackgroundField = tcell.Color236
ColourForegroundField = tcell.ColorWhite
ColourSelectedBackground = tcell.Color69
ColourSelectedForeground = tcell.ColorWhite
ColourSecondaryBorder = tcell.Color240
)

var (
FieldStyle = tcell.StyleDefault.
Background(ColourBackgroundField).
Foreground(ColourForegroundField)
SelectStyle = tcell.StyleDefault.
Background(ColourSelectedBackground).
Foreground(ColourSelectedForeground)
)

const (
clField = "[#ffaf00::b]"
clWhite = "[#ffffff::-]"
clNumeric = "[#00afff]"
clString = "[#6A9F59]"
)
Loading