Wrap display of long bucket names/pairs
This commit is contained in:
parent
c977d2f42e
commit
e27925d5e9
4
.gitignore
vendored
4
.gitignore
vendored
@ -22,7 +22,9 @@ _cgo_export.*
|
|||||||
|
|
||||||
_testmain.go
|
_testmain.go
|
||||||
|
|
||||||
|
# Binaries
|
||||||
*.exe
|
*.exe
|
||||||
|
boltbrowser
|
||||||
|
|
||||||
# Test Database
|
# Test Database
|
||||||
test.db
|
test.db
|
||||||
|
BIN
boltbrowser
BIN
boltbrowser
Binary file not shown.
@ -484,19 +484,27 @@ func (screen *BrowserScreen) drawRightPane(style Style) {
|
|||||||
// Screen is wide enough, split it
|
// Screen is wide enough, split it
|
||||||
termboxUtil.FillWithChar('=', 0, 1, w, 1, style.defaultFg, style.defaultBg)
|
termboxUtil.FillWithChar('=', 0, 1, w, 1, style.defaultFg, style.defaultBg)
|
||||||
termboxUtil.FillWithChar('|', (w / 2), screen.viewPort.firstRow-1, (w / 2), h, style.defaultFg, style.defaultBg)
|
termboxUtil.FillWithChar('|', (w / 2), screen.viewPort.firstRow-1, (w / 2), h, style.defaultFg, style.defaultBg)
|
||||||
|
// Clear the right pane
|
||||||
|
termboxUtil.FillWithChar(' ', (w/2)+1, screen.viewPort.firstRow, w, h, style.defaultFg, style.defaultBg)
|
||||||
|
|
||||||
b, p, err := screen.db.getGenericFromPath(screen.currentPath)
|
b, p, err := screen.db.getGenericFromPath(screen.currentPath)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
startX := (w / 2) + 2
|
startX := (w / 2) + 2
|
||||||
startY := 2
|
startY := 2
|
||||||
if b != nil {
|
if b != nil {
|
||||||
termboxUtil.DrawStringAtPoint(fmt.Sprintf("Path: %s", strings.Join(b.GetPath(), "/")), startX, startY, style.defaultFg, style.defaultBg)
|
pathString := fmt.Sprintf("Path: %s", strings.Join(b.GetPath(), "/"))
|
||||||
termboxUtil.DrawStringAtPoint(fmt.Sprintf("Buckets: %d", len(b.buckets)), startX, startY+1, style.defaultFg, style.defaultBg)
|
startY += screen.drawMultilineText(pathString, 6, startX, startY, (w/2)-1, style.defaultFg, style.defaultBg)
|
||||||
termboxUtil.DrawStringAtPoint(fmt.Sprintf("Pairs: %d", len(b.pairs)), startX, startY+2, style.defaultFg, style.defaultBg)
|
bucketString := fmt.Sprintf("Buckets: %d", len(b.buckets))
|
||||||
|
startY += screen.drawMultilineText(bucketString, 9, startX, startY, (w/2)-1, style.defaultFg, style.defaultBg)
|
||||||
|
pairsString := fmt.Sprintf("Pairs: %d", len(b.pairs))
|
||||||
|
startY += screen.drawMultilineText(pairsString, 7, startX, startY, (w/2)-1, style.defaultFg, style.defaultBg)
|
||||||
} else if p != nil {
|
} else if p != nil {
|
||||||
termboxUtil.DrawStringAtPoint(fmt.Sprintf("Path: %s", strings.Join(p.GetPath(), "/")), startX, startY, style.defaultFg, style.defaultBg)
|
pathString := fmt.Sprintf("Path: %s", strings.Join(p.GetPath(), "/"))
|
||||||
termboxUtil.DrawStringAtPoint(fmt.Sprintf("Key: %s", p.key), startX, startY+1, style.defaultFg, style.defaultBg)
|
startY += screen.drawMultilineText(pathString, 6, startX, startY, (w/2)-1, style.defaultFg, style.defaultBg)
|
||||||
termboxUtil.DrawStringAtPoint(fmt.Sprintf("Value: %s", p.val), startX, startY+2, style.defaultFg, style.defaultBg)
|
keyString := fmt.Sprintf("Key: %s", p.key)
|
||||||
|
startY += screen.drawMultilineText(keyString, 5, startX, startY, (w/2)-1, style.defaultFg, style.defaultBg)
|
||||||
|
valString := fmt.Sprintf("Value: %s", p.val)
|
||||||
|
startY += screen.drawMultilineText(valString, 7, startX, startY, (w/2)-1, style.defaultFg, style.defaultBg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -522,11 +530,22 @@ func (screen *BrowserScreen) drawBucket(bkt *BoltBucket, style Style, y int) int
|
|||||||
bucketBg = style.cursorBg
|
bucketBg = style.cursorBg
|
||||||
}
|
}
|
||||||
|
|
||||||
bktString := strings.Repeat(" ", len(bkt.GetPath())*2) //screen.db.getDepthFromPath(bkt.GetPath())*2)
|
prefixSpaces := strings.Repeat(" ", len(bkt.GetPath())*2)
|
||||||
|
bktString := prefixSpaces
|
||||||
|
prefixSpaces = prefixSpaces + " "
|
||||||
if bkt.expanded {
|
if bkt.expanded {
|
||||||
bktString = bktString + "- " + bkt.name + " "
|
bktString = bktString + "- " + bkt.name
|
||||||
bktString = fmt.Sprintf("%s%s", bktString, strings.Repeat(" ", (w-len(bktString))))
|
if len(bktString) > w {
|
||||||
|
// Long bucket name, wrap it
|
||||||
|
for len(bktString) > w {
|
||||||
|
termboxUtil.DrawStringAtPoint(bktString[:(w-1)], 0, (y + usedLines), bucketFg, bucketBg)
|
||||||
|
bktString = prefixSpaces + bktString[(w-1):]
|
||||||
|
usedLines++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (w - len(bktString)) > 0 {
|
||||||
|
bktString = fmt.Sprintf("%s%s", bktString, strings.Repeat(" ", (w-len(bktString))))
|
||||||
|
}
|
||||||
termboxUtil.DrawStringAtPoint(bktString, 0, (y + usedLines), bucketFg, bucketBg)
|
termboxUtil.DrawStringAtPoint(bktString, 0, (y + usedLines), bucketFg, bucketBg)
|
||||||
usedLines++
|
usedLines++
|
||||||
|
|
||||||
@ -538,7 +557,17 @@ func (screen *BrowserScreen) drawBucket(bkt *BoltBucket, style Style, y int) int
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bktString = bktString + "+ " + bkt.name
|
bktString = bktString + "+ " + bkt.name
|
||||||
bktString = fmt.Sprintf("%s%s", bktString, strings.Repeat(" ", (w-len(bktString))))
|
if len(bktString) > w {
|
||||||
|
// Long bucket name, wrap it
|
||||||
|
for len(bktString) > w {
|
||||||
|
termboxUtil.DrawStringAtPoint(bktString[:(w-1)], 0, (y + usedLines), bucketFg, bucketBg)
|
||||||
|
bktString = prefixSpaces + bktString[(w-1):]
|
||||||
|
usedLines++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (w - len(bktString)) > 0 {
|
||||||
|
bktString = fmt.Sprintf("%s%s", bktString, strings.Repeat(" ", (w-len(bktString))))
|
||||||
|
}
|
||||||
termboxUtil.DrawStringAtPoint(bktString, 0, (y + usedLines), bucketFg, bucketBg)
|
termboxUtil.DrawStringAtPoint(bktString, 0, (y + usedLines), bucketFg, bucketBg)
|
||||||
usedLines++
|
usedLines++
|
||||||
}
|
}
|
||||||
@ -550,6 +579,7 @@ func (screen *BrowserScreen) drawPair(bp *BoltPair, style Style, y int) int {
|
|||||||
if w > 80 {
|
if w > 80 {
|
||||||
w = w / 2
|
w = w / 2
|
||||||
}
|
}
|
||||||
|
usedLines := 0
|
||||||
bucketFg := style.defaultFg
|
bucketFg := style.defaultFg
|
||||||
bucketBg := style.defaultBg
|
bucketBg := style.defaultBg
|
||||||
if comparePaths(screen.currentPath, bp.GetPath()) {
|
if comparePaths(screen.currentPath, bp.GetPath()) {
|
||||||
@ -557,13 +587,46 @@ func (screen *BrowserScreen) drawPair(bp *BoltPair, style Style, y int) int {
|
|||||||
bucketBg = style.cursorBg
|
bucketBg = style.cursorBg
|
||||||
}
|
}
|
||||||
|
|
||||||
pairString := strings.Repeat(" ", len(bp.GetPath())*2) //screen.db.getDepthFromPath(bp.GetPath())*2)
|
prefixSpaces := strings.Repeat(" ", len(bp.GetPath())*2)
|
||||||
|
pairString := prefixSpaces
|
||||||
pairString = fmt.Sprintf("%s%s: %s", pairString, bp.key, bp.val)
|
pairString = fmt.Sprintf("%s%s: %s", pairString, bp.key, bp.val)
|
||||||
if w-len(pairString) > 0 {
|
prefixSpaces = prefixSpaces + " "
|
||||||
pairString = fmt.Sprintf("%s%s", pairString, strings.Repeat(" ", (w-len(pairString))))
|
if len(pairString) > w {
|
||||||
|
// Long pair string, wrap it
|
||||||
|
// We're going to try to wrap it at the :, if we can
|
||||||
|
if len(bp.GetPath())*2+len(bp.key)+1 > w {
|
||||||
|
// We can't... So just wrap it
|
||||||
|
for len(pairString) > w {
|
||||||
|
termboxUtil.DrawStringAtPoint(pairString[:(w-1)], 0, (y + usedLines), bucketFg, bucketBg)
|
||||||
|
pairString = strings.Repeat(" ", len(bp.GetPath())*2) + pairString[(w-1):]
|
||||||
|
usedLines++
|
||||||
|
}
|
||||||
|
termboxUtil.DrawStringAtPoint(pairString, 0, (y + usedLines), bucketFg, bucketBg)
|
||||||
|
usedLines++
|
||||||
|
} else {
|
||||||
|
// That's convenient, wrap at the :
|
||||||
|
pairString := strings.Repeat(" ", len(bp.GetPath())*2)
|
||||||
|
pairString = fmt.Sprintf("%s%s:", pairString, bp.key, bp.val)
|
||||||
|
termboxUtil.DrawStringAtPoint(pairString, 0, y, bucketFg, bucketBg)
|
||||||
|
usedLines++
|
||||||
|
pairString = bp.val
|
||||||
|
for len(pairString) > w {
|
||||||
|
// Gotta chunk it up
|
||||||
|
termboxUtil.DrawStringAtPoint(pairString[:(w-1)], 0, (y + usedLines), bucketFg, bucketBg)
|
||||||
|
pairString = strings.Repeat(" ", len(bp.GetPath())*2) + pairString[(w-1):]
|
||||||
|
usedLines++
|
||||||
|
}
|
||||||
|
termboxUtil.DrawStringAtPoint(pairString, 0, (y + usedLines), bucketFg, bucketBg)
|
||||||
|
usedLines++
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if w-len(pairString) > 0 {
|
||||||
|
pairString = fmt.Sprintf("%s%s", pairString, strings.Repeat(" ", (w-len(pairString))))
|
||||||
|
}
|
||||||
|
termboxUtil.DrawStringAtPoint(pairString, 0, y, bucketFg, bucketBg)
|
||||||
|
usedLines = 1
|
||||||
}
|
}
|
||||||
termboxUtil.DrawStringAtPoint(pairString, 0, y, bucketFg, bucketBg)
|
return usedLines
|
||||||
return 1
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (screen *BrowserScreen) startDeleteItem() bool {
|
func (screen *BrowserScreen) startDeleteItem() bool {
|
||||||
@ -687,6 +750,7 @@ func (screen *BrowserScreen) startInsertItem(tp BoltType) bool {
|
|||||||
}
|
}
|
||||||
inpX, inpY := ((w / 2) - (inpW / 2)), ((h / 2) - inpH)
|
inpX, inpY := ((w / 2) - (inpW / 2)), ((h / 2) - inpH)
|
||||||
mod := termboxUtil.CreateInputModal("", inpX, inpY, inpW, inpH, termbox.ColorWhite, termbox.ColorBlack)
|
mod := termboxUtil.CreateInputModal("", inpX, inpY, inpW, inpH, termbox.ColorWhite, termbox.ColorBlack)
|
||||||
|
//mod.SetInputWrap(true)
|
||||||
screen.inputModal = mod
|
screen.inputModal = mod
|
||||||
var insPath string
|
var insPath string
|
||||||
_, p, e := screen.db.getGenericFromPath(screen.currentPath)
|
_, p, e := screen.db.getGenericFromPath(screen.currentPath)
|
||||||
@ -720,6 +784,27 @@ func (screen *BrowserScreen) startInsertItem(tp BoltType) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Print text on multiple lines, if needed
|
||||||
|
// msg - What to print
|
||||||
|
// mlPadding - number of spaces to pad lines after the first
|
||||||
|
// startX - Starting x
|
||||||
|
// startY - Starting y
|
||||||
|
// maxWidth - Maximum width
|
||||||
|
// fg, bg - Colors
|
||||||
|
// Returns the number of lines used
|
||||||
|
func (screen *BrowserScreen) drawMultilineText(msg string, mlPadding, startX, startY, maxWidth int, fg, bg termbox.Attribute) int {
|
||||||
|
var numLines int
|
||||||
|
spacePadding := strings.Repeat(" ", mlPadding)
|
||||||
|
for len(msg) > maxWidth {
|
||||||
|
termboxUtil.DrawStringAtPoint(msg[:maxWidth-1], startX, (startY + numLines), fg, bg)
|
||||||
|
msg = spacePadding + msg[maxWidth-1:]
|
||||||
|
numLines++
|
||||||
|
}
|
||||||
|
termboxUtil.DrawStringAtPoint(msg, startX, (startY + numLines), fg, bg)
|
||||||
|
numLines++
|
||||||
|
return numLines
|
||||||
|
}
|
||||||
|
|
||||||
func (screen *BrowserScreen) setMessage(msg string) {
|
func (screen *BrowserScreen) setMessage(msg string) {
|
||||||
screen.message = msg
|
screen.message = msg
|
||||||
screen.messageTime = time.Now()
|
screen.messageTime = time.Now()
|
||||||
|
Loading…
Reference in New Issue
Block a user