Skip to content

Commit

Permalink
Display keymaps corresponding to focused pane, not page
Browse files Browse the repository at this point in the history
  • Loading branch information
ymtdzzz committed Aug 21, 2024
1 parent 1e1b903 commit 8e597ac
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 173 deletions.
16 changes: 2 additions & 14 deletions tuiexporter/internal/tui/component/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type KeyMaps []*KeyMap
func (m KeyMaps) keyTexts() string {
keytexts := []string{}
for _, v := range m {
keytexts = append(keytexts, fmt.Sprintf("[yellow]%s[white]: %s",
keytexts = append(keytexts, fmt.Sprintf(" [yellow]%s[white]: %s",
keyMapRegex.ReplaceAllString(v.key.Name(), ""),
v.description,
))
Expand All @@ -33,24 +33,12 @@ type Focusable interface {
SetFocusFunc(func()) *tview.Box
}

func attatchCommandList(p tview.Primitive, keys KeyMaps) *tview.Flex {
command := tview.NewTextView().
SetDynamicColors(true).
SetText(keys.keyTexts())

base := tview.NewFlex().SetDirection(tview.FlexRow)
base.AddItem(p, 0, 1, true).
AddItem(command, 1, 1, false)

return base
}

func newCommandList() *tview.TextView {
return tview.NewTextView().
SetDynamicColors(true)
}

func attatchCommandList2(commands *tview.TextView, p tview.Primitive) *tview.Flex {
func attatchCommandList(commands *tview.TextView, p tview.Primitive) *tview.Flex {
base := tview.NewFlex().SetDirection(tview.FlexRow)

if commands == nil {
Expand Down
18 changes: 17 additions & 1 deletion tuiexporter/internal/tui/component/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package component
import (
"fmt"

"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
"github.com/ymtdzzz/otel-tui/tuiexporter/internal/telemetry"
)
Expand Down Expand Up @@ -79,7 +80,7 @@ func getCellFromLog(log *telemetry.LogData, column int) *tview.TableCell {
return tview.NewTableCell(text)
}

func getLogInfoTree(l *telemetry.LogData, tcache *telemetry.TraceCache, drawTimelineFn func(traceID string)) *tview.TreeView {
func getLogInfoTree(commands *tview.TextView, l *telemetry.LogData, tcache *telemetry.TraceCache, drawTimelineFn func(traceID string)) *tview.TreeView {
if l == nil {
return tview.NewTreeView()
}
Expand Down Expand Up @@ -167,5 +168,20 @@ func getLogInfoTree(l *telemetry.LogData, tcache *telemetry.TraceCache, drawTime
node.SetExpanded(!node.IsExpanded())
})

registerCommandList(commands, tree, nil, KeyMaps{
{
key: tcell.NewEventKey(tcell.KeyRune, 'L', tcell.ModCtrl),
description: "Reduce the width",
},
{
key: tcell.NewEventKey(tcell.KeyRune, 'H', tcell.ModCtrl),
description: "Expand the width",
},
{
key: tcell.NewEventKey(tcell.KeyEnter, ' ', tcell.ModNone),
description: "Toggle folding the child nodes",
},
})

return tree
}
2 changes: 1 addition & 1 deletion tuiexporter/internal/tui/component/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func TestGetLogInfoTree(t *testing.T) {
screen.Init()
screen.SetSize(sw, sh)

gottree := getLogInfoTree(logs[0], nil, nil)
gottree := getLogInfoTree(nil, logs[0], nil, nil)
gottree.SetRect(0, 0, sw, sh)
gottree.Draw(screen)
screen.Sync()
Expand Down
21 changes: 19 additions & 2 deletions tuiexporter/internal/tui/component/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func getCellFromMetrics(metric *telemetry.MetricData, column int) *tview.TableCe
return tview.NewTableCell(text)
}

func getMetricInfoTree(m *telemetry.MetricData) *tview.TreeView {
func getMetricInfoTree(commands *tview.TextView, m *telemetry.MetricData) *tview.TreeView {
if m == nil {
return nil
}
Expand Down Expand Up @@ -369,6 +369,21 @@ func getMetricInfoTree(m *telemetry.MetricData) *tview.TreeView {
node.SetExpanded(!node.IsExpanded())
})

registerCommandList(commands, tree, nil, KeyMaps{
{
key: tcell.NewEventKey(tcell.KeyRune, 'L', tcell.ModCtrl),
description: "Reduce the width",
},
{
key: tcell.NewEventKey(tcell.KeyRune, 'H', tcell.ModCtrl),
description: "Expand the width",
},
{
key: tcell.NewEventKey(tcell.KeyEnter, ' ', tcell.ModNone),
description: "Toggle folding the child nodes",
},
})

return tree
}

Expand All @@ -380,7 +395,7 @@ func (a ByTimestamp) Less(i, j int) bool {
return a[i].Timestamp().AsTime().Before(a[j].Timestamp().AsTime())
}

func drawMetricChartByRow(store *telemetry.Store, row int) tview.Primitive {
func drawMetricChartByRow(commands *tview.TextView, store *telemetry.Store, row int) tview.Primitive {
m := store.GetFilteredMetricByIdx(row)
mcache := store.GetMetricCache()
sname := "N/A"
Expand Down Expand Up @@ -542,6 +557,8 @@ func drawMetricChartByRow(store *telemetry.Store, row int) tview.Primitive {

chart.AddItem(ch, 0, 7, true).AddItem(legend, 0, 3, false)

registerCommandList(commands, ch, nil, KeyMaps{})

return chart
}

Expand Down
Loading

0 comments on commit 8e597ac

Please sign in to comment.