Skip to content

Commit

Permalink
Merge pull request #139 from ymtdzzz/feature/resizable_details_pane
Browse files Browse the repository at this point in the history
Make all the details panes resizable by Ctrl+H and Ctrl+L
  • Loading branch information
ymtdzzz authored Aug 19, 2024
2 parents ff553f9 + c311e25 commit f8c1073
Show file tree
Hide file tree
Showing 3 changed files with 211 additions and 40 deletions.
2 changes: 2 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0
go.uber.org/automaxprocs v1.5.3/go.mod h1:eRbA25aqJrxAbsLO0xy5jVwPt7FQnRgjW+efnwa1WM0=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/exp/shiny v0.0.0-20230817173708-d852ddb80c63/go.mod h1:UH99kUObWAZkDnWqppdQe5ZhPYESUw8I0zVV1uWBR+0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
Expand All @@ -281,6 +282,7 @@ golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbht
golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
Expand Down
191 changes: 161 additions & 30 deletions tuiexporter/internal/tui/component/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ const (
PAGE_LOGS = "Logs"
PAGE_DEBUG_LOG = "DebugLog"
PAGE_METRICS = "Metrics"

DEFAULT_PROPORTION_TRACE_DETAILS = 20
DEFAULT_PROPORTION_TRACE_TABLE = 30
DEFAULT_PROPORTION_METRIC_SIDE = 25
DEFAULT_PROPORTION_METRIC_TABLE = 25
DEFAULT_PROPORTION_LOG_DETAILS = 20
DEFAULT_PROPORTION_LOG_TABLE = 30
)

var keyMapRegex = regexp.MustCompile(`Rune|\[|\]`)
Expand Down Expand Up @@ -112,12 +119,43 @@ func (p *TUIPages) registerPages(store *telemetry.Store) {
}

func (p *TUIPages) createTracePage(store *telemetry.Store) *tview.Flex {
page := tview.NewFlex().SetDirection(tview.FlexColumn)
basePage := tview.NewFlex().SetDirection(tview.FlexColumn)

tableContainer := tview.NewFlex().SetDirection(tview.FlexRow)

details := tview.NewFlex().SetDirection(tview.FlexRow)
details.SetTitle("Details (d)").SetBorder(true)
detailspro := DEFAULT_PROPORTION_TRACE_DETAILS
tablepro := DEFAULT_PROPORTION_TRACE_TABLE

details.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
switch event.Key() {
case tcell.KeyCtrlL:
if detailspro <= 1 {
return nil
}
tablepro++
detailspro--
tableFocus := tableContainer.HasFocus()
detailsFocus := details.HasFocus()
basePage.Clear().AddItem(tableContainer, 0, tablepro, tableFocus).
AddItem(details, 0, detailspro, detailsFocus)
return nil
case tcell.KeyCtrlH:
if tablepro <= 1 {
return nil
}
tablepro--
detailspro++
tableFocus := tableContainer.HasFocus()
detailsFocus := details.HasFocus()
basePage.Clear().AddItem(tableContainer, 0, tablepro, tableFocus).
AddItem(details, 0, detailspro, detailsFocus)
return nil
}
return event
})

tableContainer := tview.NewFlex().SetDirection(tview.FlexRow)
tableContainer.SetTitle("Traces (t)").SetBorder(true)
table := tview.NewTable().
SetBorders(false).
Expand All @@ -126,6 +164,13 @@ func (p *TUIPages) createTracePage(store *telemetry.Store) *tview.Flex {
SetSelectedFunc(func(row, _ int) {
p.showTimelineByRow(store, row)
})
table.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Key() == tcell.KeyCtrlL {
store.Flush()
return nil
}
return event
})

input := ""
inputConfirmed := ""
Expand Down Expand Up @@ -171,8 +216,8 @@ func (p *TUIPages) createTracePage(store *telemetry.Store) *tview.Flex {
return event
})

page.AddItem(tableContainer, 0, 6, true).AddItem(details, 0, 4, false)
page.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
basePage.AddItem(tableContainer, 0, DEFAULT_PROPORTION_TRACE_TABLE, true).AddItem(details, 0, DEFAULT_PROPORTION_TRACE_DETAILS, false)
basePage.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if !search.HasFocus() {
switch event.Rune() {
case 'd':
Expand All @@ -184,17 +229,12 @@ func (p *TUIPages) createTracePage(store *telemetry.Store) *tview.Flex {
}
}

if event.Key() == tcell.KeyCtrlL {
store.Flush()
return nil
}

return event
})
page = attatchCommandList(page, KeyMaps{
page := attatchCommandList(basePage, KeyMaps{
&KeyMap{
key: tcell.NewEventKey(tcell.KeyRune, 'L', tcell.ModCtrl),
description: "Clear all data",
description: "(traces) Clear all data",
},
&KeyMap{
key: tcell.NewEventKey(tcell.KeyRune, '/', tcell.ModNone),
Expand All @@ -208,6 +248,14 @@ func (p *TUIPages) createTracePage(store *telemetry.Store) *tview.Flex {
key: tcell.NewEventKey(tcell.KeyEnter, ' ', tcell.ModNone),
description: "(search) Confirm",
},
&KeyMap{
key: tcell.NewEventKey(tcell.KeyRune, 'L', tcell.ModCtrl),
description: "(detail) Resize side col",
},
&KeyMap{
key: tcell.NewEventKey(tcell.KeyRune, 'H', tcell.ModCtrl),
description: "(detail) Resize side col",
},
&KeyMap{
key: tcell.NewEventKey(tcell.KeyF12, ' ', tcell.ModNone),
description: "(debug) Toggle Log",
Expand Down Expand Up @@ -276,24 +324,62 @@ func (p *TUIPages) showTimeline(traceID string, tcache *telemetry.TraceCache, lc
}

func (p *TUIPages) createMetricsPage(store *telemetry.Store) *tview.Flex {
page := tview.NewFlex().SetDirection(tview.FlexColumn)
basePage := tview.NewFlex().SetDirection(tview.FlexColumn)

tableContainer := tview.NewFlex().SetDirection(tview.FlexRow)

side := tview.NewFlex().SetDirection(tview.FlexRow)
details := tview.NewFlex().SetDirection(tview.FlexRow)
details.SetTitle("Details (d)").SetBorder(true)
sidepro := DEFAULT_PROPORTION_METRIC_SIDE
tablepro := DEFAULT_PROPORTION_METRIC_TABLE

details.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
switch event.Key() {
case tcell.KeyCtrlL:
if sidepro <= 1 {
return nil
}
tablepro++
sidepro--
tableFocus := tableContainer.HasFocus()
sideFocus := side.HasFocus()
basePage.Clear().AddItem(tableContainer, 0, tablepro, tableFocus).
AddItem(side, 0, sidepro, sideFocus)
return nil
case tcell.KeyCtrlH:
if tablepro <= 1 {
return nil
}
tablepro--
sidepro++
tableFocus := tableContainer.HasFocus()
sideFocus := side.HasFocus()
basePage.Clear().AddItem(tableContainer, 0, tablepro, tableFocus).
AddItem(side, 0, sidepro, sideFocus)
return nil
}
return event
})

chart := tview.NewFlex().SetDirection(tview.FlexRow)
chart.SetTitle("Chart (c)").SetBorder(true)

side.AddItem(details, 0, 5, false).
AddItem(chart, 0, 5, false)

tableContainer := tview.NewFlex().SetDirection(tview.FlexRow)
tableContainer.SetTitle("Metrics (m)").SetBorder(true)
table := tview.NewTable().
SetBorders(false).
SetSelectable(true, false).
SetContent(NewMetricDataForTable(store.GetFilteredMetrics()))
table.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Key() == tcell.KeyCtrlL {
store.Flush()
return nil
}
return event
})

input := ""
inputConfirmed := ""
Expand Down Expand Up @@ -342,8 +428,8 @@ func (p *TUIPages) createMetricsPage(store *telemetry.Store) *tview.Flex {
return event
})

page.AddItem(tableContainer, 0, 5, true).AddItem(side, 0, 5, false)
page.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
basePage.AddItem(tableContainer, 0, DEFAULT_PROPORTION_METRIC_TABLE, true).AddItem(side, 0, DEFAULT_PROPORTION_METRIC_SIDE, false)
basePage.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if !search.HasFocus() {
switch event.Rune() {
case 'd':
Expand All @@ -358,17 +444,12 @@ func (p *TUIPages) createMetricsPage(store *telemetry.Store) *tview.Flex {
}
}

if event.Key() == tcell.KeyCtrlL {
store.Flush()
return nil
}

return event
})
page = attatchCommandList(page, KeyMaps{
page := attatchCommandList(basePage, KeyMaps{
&KeyMap{
key: tcell.NewEventKey(tcell.KeyRune, 'L', tcell.ModCtrl),
description: "Clear all data",
description: "(metrics) Clear all data",
},
&KeyMap{
key: tcell.NewEventKey(tcell.KeyRune, '/', tcell.ModNone),
Expand All @@ -382,6 +463,14 @@ func (p *TUIPages) createMetricsPage(store *telemetry.Store) *tview.Flex {
key: tcell.NewEventKey(tcell.KeyEnter, ' ', tcell.ModNone),
description: "(search) Confirm",
},
&KeyMap{
key: tcell.NewEventKey(tcell.KeyRune, 'L', tcell.ModCtrl),
description: "(detail) Resize side col",
},
&KeyMap{
key: tcell.NewEventKey(tcell.KeyRune, 'H', tcell.ModCtrl),
description: "(detail) Resize side col",
},
&KeyMap{
key: tcell.NewEventKey(tcell.KeyF12, ' ', tcell.ModNone),
description: "(debug) Toggle Log",
Expand All @@ -396,18 +485,57 @@ func (p *TUIPages) createLogPage(store *telemetry.Store) *tview.Flex {
pageContainer := tview.NewFlex().SetDirection(tview.FlexRow)
page := tview.NewFlex().SetDirection(tview.FlexColumn)

tableContainer := tview.NewFlex().SetDirection(tview.FlexRow)

details := tview.NewFlex().SetDirection(tview.FlexRow)
details.SetTitle("Details (d)").SetBorder(true)
detailspro := DEFAULT_PROPORTION_LOG_DETAILS
tablepro := DEFAULT_PROPORTION_LOG_TABLE

details.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
switch event.Key() {
case tcell.KeyCtrlL:
if detailspro <= 1 {
return nil
}
tablepro++
detailspro--
tableFocus := tableContainer.HasFocus()
detailsFocus := details.HasFocus()
page.Clear().AddItem(tableContainer, 0, tablepro, tableFocus).
AddItem(details, 0, detailspro, detailsFocus)
return nil
case tcell.KeyCtrlH:
if tablepro <= 1 {
return nil
}
tablepro--
detailspro++
tableFocus := tableContainer.HasFocus()
detailsFocus := details.HasFocus()
page.Clear().AddItem(tableContainer, 0, tablepro, tableFocus).
AddItem(details, 0, detailspro, detailsFocus)
return nil
}
return event
})

body := tview.NewTextView()
body.SetBorder(true).SetTitle("Body (b)")

tableContainer := tview.NewFlex().SetDirection(tview.FlexRow)
tableContainer.SetTitle("Logs (o)").SetBorder(true)
table := tview.NewTable().
SetBorders(false).
SetSelectable(true, false).
SetContent(NewLogDataForTable(store.GetFilteredLogs()))
table.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Key() == tcell.KeyCtrlL {
store.Flush()
return nil
}

return event
})

input := ""
inputConfirmed := ""
Expand Down Expand Up @@ -465,7 +593,7 @@ func (p *TUIPages) createLogPage(store *telemetry.Store) *tview.Flex {
return event
})

page.AddItem(tableContainer, 0, 6, true).AddItem(details, 0, 4, false)
page.AddItem(tableContainer, 0, DEFAULT_PROPORTION_LOG_TABLE, true).AddItem(details, 0, DEFAULT_PROPORTION_LOG_DETAILS, false)
pageContainer.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if !search.HasFocus() {
switch event.Rune() {
Expand All @@ -485,18 +613,13 @@ func (p *TUIPages) createLogPage(store *telemetry.Store) *tview.Flex {
}
}

if event.Key() == tcell.KeyCtrlL {
store.Flush()
return nil
}

return event
})
pageContainer.AddItem(page, 0, 1, true).AddItem(body, 5, 1, false)
pageContainer = attatchCommandList(pageContainer, KeyMaps{
&KeyMap{
key: tcell.NewEventKey(tcell.KeyRune, 'L', tcell.ModCtrl),
description: "Clear all data",
description: "(logs) Clear all data",
},
&KeyMap{
key: tcell.NewEventKey(tcell.KeyRune, 'y', tcell.ModNone),
Expand All @@ -514,6 +637,14 @@ func (p *TUIPages) createLogPage(store *telemetry.Store) *tview.Flex {
key: tcell.NewEventKey(tcell.KeyEnter, ' ', tcell.ModNone),
description: "(search) Confirm",
},
&KeyMap{
key: tcell.NewEventKey(tcell.KeyRune, 'L', tcell.ModCtrl),
description: "(detail) Resize side col",
},
&KeyMap{
key: tcell.NewEventKey(tcell.KeyRune, 'H', tcell.ModCtrl),
description: "(detail) Resize side col",
},
&KeyMap{
key: tcell.NewEventKey(tcell.KeyF12, ' ', tcell.ModNone),
description: "(debug) Toggle Log",
Expand Down
Loading

0 comments on commit f8c1073

Please sign in to comment.