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

Improve readability of key maps #96

Merged
merged 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
84 changes: 67 additions & 17 deletions tuiexporter/internal/tui/component/page.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package component

import (
"fmt"
"log"
"regexp"
"strings"
Expand All @@ -20,7 +21,12 @@ const (

var keyMapRegex = regexp.MustCompile(`Rune|\[|\]`)

type KeyMaps map[tcell.EventKey]string
type KeyMap struct {
key *tcell.EventKey
description string
}

type KeyMaps []*KeyMap

type TUIPages struct {
pages *tview.Pages
Expand Down Expand Up @@ -178,11 +184,26 @@ func (p *TUIPages) createTracePage(store *telemetry.Store) *tview.Flex {
return event
})
page = attatchCommandList(page, KeyMaps{
*tcell.NewEventKey(tcell.KeyF12, ' ', tcell.ModNone): "Toggle Log",
*tcell.NewEventKey(tcell.KeyRune, '/', tcell.ModNone): "Search traces",
*tcell.NewEventKey(tcell.KeyEsc, ' ', tcell.ModNone): "(search) Cancel",
*tcell.NewEventKey(tcell.KeyEnter, ' ', tcell.ModNone): "(search) Confirm",
*tcell.NewEventKey(tcell.KeyRune, 'L', tcell.ModCtrl): "Clear all data",
&KeyMap{
key: tcell.NewEventKey(tcell.KeyRune, 'L', tcell.ModCtrl),
description: "Clear all data",
},
&KeyMap{
key: tcell.NewEventKey(tcell.KeyRune, '/', tcell.ModNone),
description: "Search traces",
},
&KeyMap{
key: tcell.NewEventKey(tcell.KeyEsc, ' ', tcell.ModNone),
description: "(search) Cancel",
},
&KeyMap{
key: tcell.NewEventKey(tcell.KeyEnter, ' ', tcell.ModNone),
description: "(search) Confirm",
},
&KeyMap{
key: tcell.NewEventKey(tcell.KeyF12, ' ', tcell.ModNone),
description: "(debug) Toggle Log",
},
})
page = attatchTab(page, PAGE_TRACES)

Expand Down Expand Up @@ -232,8 +253,14 @@ func (p *TUIPages) showTimeline(traceID string, tcache *telemetry.TraceCache, lc
)
timeline.AddItem(tl, 0, 1, true)

keymaps[*tcell.NewEventKey(tcell.KeyF12, ' ', tcell.ModNone)] = "Toggle Log"
keymaps[*tcell.NewEventKey(tcell.KeyEsc, ' ', tcell.ModNone)] = "Back to Traces"
keymaps = append(keymaps, &KeyMap{
key: tcell.NewEventKey(tcell.KeyF12, ' ', tcell.ModNone),
description: "Toggle Log",
})
keymaps = append(keymaps, &KeyMap{
key: tcell.NewEventKey(tcell.KeyEsc, ' ', tcell.ModNone),
description: "Back to Traces",
})
timeline = attatchCommandList(timeline, keymaps)

p.timeline.AddItem(timeline, 0, 1, true)
Expand Down Expand Up @@ -342,12 +369,30 @@ func (p *TUIPages) createLogPage(store *telemetry.Store) *tview.Flex {
})
pageContainer.AddItem(page, 0, 1, true).AddItem(body, 5, 1, false)
pageContainer = attatchCommandList(pageContainer, KeyMaps{
*tcell.NewEventKey(tcell.KeyF12, ' ', tcell.ModNone): "Toggle Log",
*tcell.NewEventKey(tcell.KeyRune, '/', tcell.ModNone): "Search logs",
*tcell.NewEventKey(tcell.KeyEsc, ' ', tcell.ModNone): "(search) Cancel",
*tcell.NewEventKey(tcell.KeyEnter, ' ', tcell.ModNone): "(search) Confirm",
*tcell.NewEventKey(tcell.KeyRune, 'L', tcell.ModCtrl): "Clear all data",
*tcell.NewEventKey(tcell.KeyRune, 'y', tcell.ModNone): "Copy Log to clipboard",
&KeyMap{
key: tcell.NewEventKey(tcell.KeyRune, 'L', tcell.ModCtrl),
description: "Clear all data",
},
&KeyMap{
key: tcell.NewEventKey(tcell.KeyRune, 'y', tcell.ModNone),
description: "Copy Log to clipboard",
},
&KeyMap{
key: tcell.NewEventKey(tcell.KeyRune, '/', tcell.ModNone),
description: "Search Logs",
},
&KeyMap{
key: tcell.NewEventKey(tcell.KeyEsc, ' ', tcell.ModNone),
description: "(search) Cancel",
},
&KeyMap{
key: tcell.NewEventKey(tcell.KeyEnter, ' ', tcell.ModNone),
description: "(search) Confirm",
},
&KeyMap{
key: tcell.NewEventKey(tcell.KeyF12, ' ', tcell.ModNone),
description: "(debug) Toggle Log",
},
})
pageContainer = attatchTab(pageContainer, PAGE_LOGS)

Expand Down Expand Up @@ -391,11 +436,16 @@ func attatchTab(p tview.Primitive, name string) *tview.Flex {

func attatchCommandList(p tview.Primitive, keys KeyMaps) *tview.Flex {
keytexts := []string{}
for k, v := range keys {
keytexts = append(keytexts, keyMapRegex.ReplaceAllString(k.Name(), "")+": "+v)
for _, v := range keys {
keytexts = append(keytexts, fmt.Sprintf("[yellow]%s[white]: %s",
keyMapRegex.ReplaceAllString(v.key.Name(), ""),
v.description,
))
}

command := tview.NewTextView().SetText(strings.Join(keytexts, ", "))
command := tview.NewTextView().
SetDynamicColors(true).
SetText(strings.Join(keytexts, " | "))

base := tview.NewFlex().SetDirection(tview.FlexRow)
base.AddItem(p, 0, 1, true).
Expand Down
20 changes: 16 additions & 4 deletions tuiexporter/internal/tui/component/timeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,22 @@ func DrawTimeline(traceID string, tcache *telemetry.TraceCache, lcache *telemetr
})

return base, KeyMaps{
*tcell.NewEventKey(tcell.KeyUp, ' ', tcell.ModNone): "Move up",
*tcell.NewEventKey(tcell.KeyDown, ' ', tcell.ModNone): "Move down",
*tcell.NewEventKey(tcell.KeyRune, 'L', tcell.ModCtrl): "Widen side col",
*tcell.NewEventKey(tcell.KeyRune, 'H', tcell.ModCtrl): "Narrow side col",
&KeyMap{
key: tcell.NewEventKey(tcell.KeyUp, ' ', tcell.ModNone),
description: "Move up",
},
&KeyMap{
key: tcell.NewEventKey(tcell.KeyDown, ' ', tcell.ModNone),
description: "Move down",
},
&KeyMap{
key: tcell.NewEventKey(tcell.KeyRune, 'L', tcell.ModCtrl),
description: "Widen side col",
},
&KeyMap{
key: tcell.NewEventKey(tcell.KeyRune, 'H', tcell.ModCtrl),
description: "Narrow side col",
},
}
}

Expand Down
Loading