Stringify all buckets/keys/values

Resolves Issue #34
This commit is contained in:
Brian Buller 2019-10-16 15:13:38 -05:00
parent a3714bf8e4
commit 1f3880f32e
3 changed files with 15 additions and 6 deletions

2
go.mod
View File

@ -7,3 +7,5 @@ require (
github.com/nsf/termbox-go v0.0.0-20180819125858-b66b20ab708e github.com/nsf/termbox-go v0.0.0-20180819125858-b66b20ab708e
golang.org/x/sys v0.0.0-20191002091554-b397fe3ad8ed // indirect golang.org/x/sys v0.0.0-20191002091554-b397fe3ad8ed // indirect
) )
go 1.13

View File

@ -587,22 +587,22 @@ func (screen *BrowserScreen) drawRightPane(style Style) {
startY := 2 startY := 2
if err == nil { if err == nil {
if b != nil { if b != nil {
pathString := fmt.Sprintf("Path: %s", strings.Join(b.GetPath(), " → ")) pathString := fmt.Sprintf("Path: %s", strings.Join(stringifyPath(b.GetPath()), " → "))
startY += screen.drawMultilineText(pathString, 6, startX, startY, (w/2)-1, style.defaultFg, style.defaultBg) startY += screen.drawMultilineText(pathString, 6, startX, startY, (w/2)-1, style.defaultFg, style.defaultBg)
bucketString := fmt.Sprintf("Buckets: %d", len(b.buckets)) bucketString := fmt.Sprintf("Buckets: %d", len(b.buckets))
startY += screen.drawMultilineText(bucketString, 9, startX, startY, (w/2)-1, style.defaultFg, style.defaultBg) startY += screen.drawMultilineText(bucketString, 9, startX, startY, (w/2)-1, style.defaultFg, style.defaultBg)
pairsString := fmt.Sprintf("Pairs: %d", len(b.pairs)) pairsString := fmt.Sprintf("Pairs: %d", len(b.pairs))
startY += screen.drawMultilineText(pairsString, 7, startX, startY, (w/2)-1, style.defaultFg, style.defaultBg) startY += screen.drawMultilineText(pairsString, 7, startX, startY, (w/2)-1, style.defaultFg, style.defaultBg)
} else if p != nil { } else if p != nil {
pathString := fmt.Sprintf("Path: %s", strings.Join(p.GetPath(), " → ")) pathString := fmt.Sprintf("Path: %s", strings.Join(stringifyPath(p.GetPath()), " → "))
startY += screen.drawMultilineText(pathString, 6, startX, startY, (w/2)-1, style.defaultFg, style.defaultBg) startY += screen.drawMultilineText(pathString, 6, startX, startY, (w/2)-1, style.defaultFg, style.defaultBg)
keyString := fmt.Sprintf("Key: %s", stringify([]byte(p.key))) keyString := fmt.Sprintf("Key: %s", stringify([]byte(p.key)))
startY += screen.drawMultilineText(keyString, 5, startX, startY, (w/2)-1, style.defaultFg, style.defaultBg) startY += screen.drawMultilineText(keyString, 5, startX, startY, (w/2)-1, style.defaultFg, style.defaultBg)
valString := fmt.Sprintf("Value: %s", formatValue([]byte(p.val))) valString := fmt.Sprintf("Value: %s", stringify(formatValue([]byte(p.val))))
startY += screen.drawMultilineText(valString, 7, startX, startY, (w/2)-1, style.defaultFg, style.defaultBg) startY += screen.drawMultilineText(valString, 7, startX, startY, (w/2)-1, style.defaultFg, style.defaultBg)
} }
} else { } else {
pathString := fmt.Sprintf("Path: %s", strings.Join(screen.currentPath, " → ")) pathString := fmt.Sprintf("Path: %s", strings.Join(stringifyPath(screen.currentPath), " → "))
startY += screen.drawMultilineText(pathString, 6, startX, startY, (w/2)-1, style.defaultFg, style.defaultBg) startY += screen.drawMultilineText(pathString, 6, startX, startY, (w/2)-1, style.defaultFg, style.defaultBg)
startY += screen.drawMultilineText(err.Error(), 6, startX, startY, (w/2)-1, style.defaultFg, style.defaultBg) startY += screen.drawMultilineText(err.Error(), 6, startX, startY, (w/2)-1, style.defaultFg, style.defaultBg)
} }
@ -657,7 +657,7 @@ func (screen *BrowserScreen) drawBucket(bkt *BoltBucket, style Style, y int) int
padAmt := (len(bkt.GetPath())*2 + 2) padAmt := (len(bkt.GetPath())*2 + 2)
if bkt.expanded { if bkt.expanded {
bktString = bktString + "- " + bkt.name bktString = bktString + "- " + stringify([]byte(bkt.name))
if len(bktString)+padAmt > w { if len(bktString)+padAmt > w {
bktString = bktString[:w-padAmt-3] + "..." bktString = bktString[:w-padAmt-3] + "..."
} }
@ -670,7 +670,7 @@ func (screen *BrowserScreen) drawBucket(bkt *BoltBucket, style Style, y int) int
usedLines += screen.drawPair(&bkt.pairs[i], style, y+usedLines) usedLines += screen.drawPair(&bkt.pairs[i], style, y+usedLines)
} }
} else { } else {
bktString = bktString + "+ " + bkt.name bktString = bktString + "+ " + stringify([]byte(bkt.name))
if len(bktString)+padAmt > w { if len(bktString)+padAmt > w {
bktString = bktString[:w-padAmt-3] + "..." bktString = bktString[:w-padAmt-3] + "..."
} }

View File

@ -30,3 +30,10 @@ func stringify(v []byte) string {
return fmt.Sprintf("%x", v) return fmt.Sprintf("%x", v)
} }
func stringifyPath(path []string) []string {
for k, v := range path {
path[k] = stringify([]byte(v))
}
return path
}