Skip to content

Commit

Permalink
Merge pull request #27 from sachaos/feature/improve-visibility
Browse files Browse the repository at this point in the history
Simplify view
  • Loading branch information
sachaos authored Sep 18, 2021
2 parents 410feb0 + f2dfe41 commit 57ecc47
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 39 deletions.
1 change: 1 addition & 0 deletions .golang-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ linters:
- gochecknoglobals
- maligned
- exhaustive
- gomoddirectives
3 changes: 3 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ func newConfig(v *viper.Viper, args []string) (*config, error) {
conf.general.noTitle, _ = flagSet.GetBool("no-title")
conf.general.pty = v.GetBool("general.pty")

v.SetDefault("color.border", "gray")
v.SetDefault("color.title", "gray")

conf.theme.Theme = tview.Theme{
PrimitiveBackgroundColor: tcell.GetColor(v.GetString("color.background")),
ContrastBackgroundColor: tcell.GetColor(v.GetString("color.contrast_background")),
Expand Down
4 changes: 2 additions & 2 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ func Test_newConfig(t *testing.T) {
PrimitiveBackgroundColor: 0,
ContrastBackgroundColor: 0,
MoreContrastBackgroundColor: 0,
BorderColor: 0,
TitleColor: 0,
BorderColor: tcell.ColorGray,
TitleColor: tcell.ColorGray,
GraphicsColor: 0,
PrimaryTextColor: 0,
SecondaryTextColor: 0,
Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/fatih/color v1.12.0
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/gdamore/encoding v1.0.0 // indirect
github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1
github.com/gdamore/tcell/v2 v2.4.1-0.20210904044819-ae5116d72813
github.com/google/go-github v17.0.0+incompatible // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/hashicorp/go-version v1.3.0 // indirect
Expand All @@ -24,7 +24,7 @@ require (
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6
github.com/pelletier/go-toml v1.9.3 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/tview v0.0.0-20210909154944-f7430b878d17
github.com/rivo/tview v0.0.0-20210624165335-29d673af0ce2
github.com/rivo/uniseg v0.2.0 // indirect
github.com/sergi/go-diff v1.2.0
github.com/spf13/afero v1.6.0 // indirect
Expand All @@ -43,3 +43,5 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)

replace github.com/rivo/tview v0.0.0-20210624165335-29d673af0ce2 => github.com/sachaos/tview v0.0.0-20210909084047-7f6f0b84f61c
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdk
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/tcell/v2 v2.4.1-0.20210904044819-ae5116d72813 h1:uqlt4EHPdtAAXKBq6OKc0auHsQP5zfhdHo/BYe6hz2Q=
github.com/gdamore/tcell/v2 v2.4.1-0.20210904044819-ae5116d72813/go.mod h1:Az6Jt+M5idSED2YPGtwnfJV0kXohgdCBPmHGSYc1r04=
github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1 h1:QqwPZCwh/k1uYqq6uXSb9TRDhTkfQbO80v8zhnIe5zM=
github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1/go.mod h1:Az6Jt+M5idSED2YPGtwnfJV0kXohgdCBPmHGSYc1r04=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
Expand Down Expand Up @@ -235,8 +233,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/rivo/tview v0.0.0-20210909154944-f7430b878d17 h1:Hvt6NxqL7PhMn3SpabVqp8bFkf8xR3tzXYbMFF0z0DI=
github.com/rivo/tview v0.0.0-20210909154944-f7430b878d17/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/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
Expand Down
65 changes: 34 additions & 31 deletions viddy.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ type Viddy struct {

idList []int64

middle *tview.Flex
bodyView *tview.TextView
app *tview.Application
logView *tview.TextView
Expand Down Expand Up @@ -319,9 +318,7 @@ func (v *Viddy) renderSnapshot(id int64) error {
return errCannotCreateSnapshot
}

v.bodyView.Lock()
v.bodyView.Clear()
v.bodyView.Unlock()

if !s.completed {
return errNotCompletedYet
Expand All @@ -331,16 +328,15 @@ func (v *Viddy) renderSnapshot(id int64) error {
}

func (v *Viddy) UpdateStatusView() {
v.statusView.SetText(fmt.Sprintf("Time Machine: %s Suspend: %s Diff: %s",
convertToOnOrOff(v.isTimeMachine), convertToOnOrOff(v.isSuspend), convertToOnOrOff(v.isShowDiff)))
v.statusView.SetText(fmt.Sprintf("Suspend %s Diff %s", convertToOnOrOff(v.isSuspend), convertToOnOrOff(v.isShowDiff)))
}

func convertToOnOrOff(on bool) string {
if on {
return "[green]ON [reset]"
return "[green][reset]"
}

return "[red]OFF[reset]"
return "[red][reset]"
}

func (v *Viddy) arrange() {
Expand All @@ -353,33 +349,40 @@ func (v *Viddy) arrange() {
flex := tview.NewFlex().SetDirection(tview.FlexRow)

if !v.isNoTitle {
flex.AddItem(
tview.NewFlex().SetDirection(tview.FlexColumn).
AddItem(v.intervalView, 10, 1, false).
AddItem(v.commandView, 0, 1, false).
AddItem(v.statusView, 45, 1, false).
AddItem(v.timeView, 21, 1, false),
3, 1, false)
title := tview.NewFlex().SetDirection(tview.FlexColumn).
AddItem(v.intervalView, 10, 1, false).
AddItem(v.commandView, 0, 1, false).
AddItem(v.timeView, 21, 1, false)

flex.AddItem(title, 3, 1, false)
}

body := tview.NewFlex().SetDirection(tview.FlexRow)
body.AddItem(v.bodyView, 0, 1, false)

if v.isEditQuery || v.query != "" {
body.AddItem(v.queryEditor, 1, 1, false)
}

v.middle.Clear()
v.middle.AddItem(body, 0, 1, false)
middle := tview.NewFlex().SetDirection(tview.FlexColumn)
middle.AddItem(body, 0, 1, false)

if v.isTimeMachine {
v.middle.AddItem(v.historyView, 21, 1, true)
middle.AddItem(v.historyView, 21, 1, true)
}

flex.AddItem(
v.middle,
middle,
0, 1, false)

bottom := tview.NewFlex().SetDirection(tview.FlexColumn)

if v.isEditQuery || v.query != "" {
bottom.AddItem(v.queryEditor, 0, 1, false)
} else {
bottom.AddItem(tview.NewBox(), 0, 1, false)
}

bottom.AddItem(v.statusView, 18, 1, false)

flex.AddItem(bottom, 1, 1, false)

if v.showLogView {
flex.AddItem(v.logView, 10, 1, false)
}
Expand All @@ -391,46 +394,48 @@ func (v *Viddy) arrange() {
func (v *Viddy) Run() error {
b := tview.NewTextView()
b.SetDynamicColors(true)
b.SetTitle("body")
b.SetRegions(true)
b.GetInnerRect()
b.SetWrap(false)
v.bodyView = b

t := tview.NewTextView()
t.SetBorder(true).SetTitle("Time")
t.SetTitleAlign(tview.AlignLeft)
v.timeView = t

h := tview.NewTable()
h.SetBorder(true).SetTitle("History")
v.historyView = h
h.SetTitle("History")
h.SetTitleAlign(tview.AlignLeft)
h.SetBorder(true)
h.ScrollToBeginning()
h.SetSelectionChangedFunc(func(row, column int) {
c := h.GetCell(row, column)
c := v.historyView.GetCell(row, column)
id, err := strconv.ParseInt(c.Text, 10, 64)
if err == nil {
_ = v.renderSnapshot(id)
}
})
h.SetSelectedStyle(tcell.StyleDefault.Background(tcell.ColorGray))

v.historyView = h

var cmd []string
cmd = append(cmd, v.cmd)
cmd = append(cmd, v.args...)

c := tview.NewTextView()
c.SetBorder(true).SetTitle("Command")
c.SetTitleAlign(tview.AlignLeft)
c.SetText(strings.Join(cmd, " "))
v.commandView = c

d := tview.NewTextView()
d.SetBorder(true).SetTitle("Every")
d.SetTitleAlign(tview.AlignLeft)
d.SetText(v.duration.String())
v.intervalView = d

s := tview.NewTextView()
s.SetBorder(true).SetTitle("Status")
s.SetDynamicColors(true)
v.statusView = s

Expand All @@ -444,12 +449,10 @@ func (v *Viddy) Run() error {
_, _ = io.WriteString(hv, v.helpPage())
v.helpView = hv

middle := tview.NewFlex().SetDirection(tview.FlexColumn)
v.middle = middle

q := tview.NewInputField().SetLabel("/")
q.SetChangedFunc(func(text string) {
v.query = text
_ = v.renderSnapshot(v.currentID)
})
q.SetDoneFunc(func(key tcell.Key) {
v.isEditQuery = false
Expand Down

0 comments on commit 57ecc47

Please sign in to comment.