Updated Termbox Utility Library

This commit is contained in:
Brian Buller 2015-10-21 11:47:34 -05:00
parent 82c42460f6
commit acaf7d088a
2 changed files with 37 additions and 37 deletions

View File

@ -3,8 +3,8 @@ package main
import ( import (
"fmt" "fmt"
"github.com/br0xen/termbox-util"
"github.com/nsf/termbox-go" "github.com/nsf/termbox-go"
"gogs.bullercodeworks.com/brian/termbox-util"
) )
/* /*
@ -23,8 +23,8 @@ type AboutScreen int
func drawCommandsAtPoint(commands []Command, x int, y int, style Style) { func drawCommandsAtPoint(commands []Command, x int, y int, style Style) {
xPos, yPos := x, y xPos, yPos := x, y
for index, cmd := range commands { for index, cmd := range commands {
termbox_util.DrawStringAtPoint(fmt.Sprintf("%6s", cmd.key), xPos, yPos, style.defaultFg, style.defaultBg) termboxUtil.DrawStringAtPoint(fmt.Sprintf("%6s", cmd.key), xPos, yPos, style.defaultFg, style.defaultBg)
termbox_util.DrawStringAtPoint(cmd.description, xPos+8, yPos, style.defaultFg, style.defaultBg) termboxUtil.DrawStringAtPoint(cmd.description, xPos+8, yPos, style.defaultFg, style.defaultBg)
yPos++ yPos++
if index > 2 && index%2 == 1 { if index > 2 && index%2 == 1 {
yPos++ yPos++
@ -72,7 +72,7 @@ func (screen *AboutScreen) drawScreen(style Style) {
title := "BoltBrowser" title := "BoltBrowser"
startY = 0 startY = 0
yPos = 0 yPos = 0
termbox_util.DrawStringAtPoint(title, (width-len(title))/2, startY, style.titleFg, style.titleBg) termboxUtil.DrawStringAtPoint(title, (width-len(title))/2, startY, style.titleFg, style.titleBg)
} else { } else {
if height < 25 { if height < 25 {
startY = 0 startY = 0
@ -122,5 +122,5 @@ func (screen *AboutScreen) drawScreen(style Style) {
drawCommandsAtPoint(commands1[:], xPos, yPos+1, style) drawCommandsAtPoint(commands1[:], xPos, yPos+1, style)
drawCommandsAtPoint(commands2[:], xPos+20, yPos+1, style) drawCommandsAtPoint(commands2[:], xPos+20, yPos+1, style)
exitTxt := "Press any key to return to browser" exitTxt := "Press any key to return to browser"
termbox_util.DrawStringAtPoint(exitTxt, (width-len(exitTxt))/2, height-1, style.titleFg, style.titleBg) termboxUtil.DrawStringAtPoint(exitTxt, (width-len(exitTxt))/2, height-1, style.titleFg, style.titleBg)
} }

View File

@ -29,8 +29,8 @@ type BrowserScreen struct {
currentType int currentType int
message string message string
mode BrowserMode mode BrowserMode
inputModal *termbox_util.InputModal inputModal *termboxUtil.InputModal
confirmModal *termbox_util.ConfirmModal confirmModal *termboxUtil.ConfirmModal
messageTimeout time.Duration messageTimeout time.Duration
messageTime time.Time messageTime time.Time
} }
@ -431,14 +431,14 @@ func (screen *BrowserScreen) drawScreen(style Style) {
func (screen *BrowserScreen) drawHeader(style Style) { func (screen *BrowserScreen) drawHeader(style Style) {
width, _ := termbox.Size() width, _ := termbox.Size()
spaces := strings.Repeat(" ", (width / 2)) spaces := strings.Repeat(" ", (width / 2))
termbox_util.DrawStringAtPoint(fmt.Sprintf("%s%s%s", spaces, ProgramName, spaces), 0, 0, style.titleFg, style.titleBg) termboxUtil.DrawStringAtPoint(fmt.Sprintf("%s%s%s", spaces, ProgramName, spaces), 0, 0, style.titleFg, style.titleBg)
} }
func (screen *BrowserScreen) drawFooter(style Style) { func (screen *BrowserScreen) drawFooter(style Style) {
if screen.messageTimeout > 0 && time.Since(screen.messageTime) > screen.messageTimeout { if screen.messageTimeout > 0 && time.Since(screen.messageTime) > screen.messageTimeout {
screen.clearMessage() screen.clearMessage()
} }
_, height := termbox.Size() _, height := termbox.Size()
termbox_util.DrawStringAtPoint(screen.message, 0, height-1, style.defaultFg, style.defaultBg) termboxUtil.DrawStringAtPoint(screen.message, 0, height-1, style.defaultFg, style.defaultBg)
} }
func (screen *BrowserScreen) drawLeftPane(style Style) { func (screen *BrowserScreen) drawLeftPane(style Style) {
w, h := termbox.Size() w, h := termbox.Size()
@ -447,7 +447,7 @@ func (screen *BrowserScreen) drawLeftPane(style Style) {
} }
screen.viewPort.numberOfRows = h - 2 screen.viewPort.numberOfRows = h - 2
termbox_util.FillWithChar('=', 0, 1, w, 1, style.defaultFg, style.defaultBg) termboxUtil.FillWithChar('=', 0, 1, w, 1, style.defaultFg, style.defaultBg)
y := 2 y := 2
screen.viewPort.firstRow = y screen.viewPort.firstRow = y
if len(screen.currentPath) == 0 { if len(screen.currentPath) == 0 {
@ -482,21 +482,21 @@ func (screen *BrowserScreen) drawRightPane(style Style) {
w, h := termbox.Size() w, h := termbox.Size()
if w > 80 { if w > 80 {
// Screen is wide enough, split it // Screen is wide enough, split it
termbox_util.FillWithChar('=', 0, 1, w, 1, style.defaultFg, style.defaultBg) termboxUtil.FillWithChar('=', 0, 1, w, 1, style.defaultFg, style.defaultBg)
termbox_util.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)
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 {
termbox_util.DrawStringAtPoint(fmt.Sprintf("Path: %s", strings.Join(b.GetPath(), "/")), startX, startY, style.defaultFg, style.defaultBg) termboxUtil.DrawStringAtPoint(fmt.Sprintf("Path: %s", strings.Join(b.GetPath(), "/")), startX, startY, style.defaultFg, style.defaultBg)
termbox_util.DrawStringAtPoint(fmt.Sprintf("Buckets: %d", len(b.buckets)), startX, startY+1, style.defaultFg, style.defaultBg) termboxUtil.DrawStringAtPoint(fmt.Sprintf("Buckets: %d", len(b.buckets)), startX, startY+1, style.defaultFg, style.defaultBg)
termbox_util.DrawStringAtPoint(fmt.Sprintf("Pairs: %d", len(b.pairs)), startX, startY+2, style.defaultFg, style.defaultBg) termboxUtil.DrawStringAtPoint(fmt.Sprintf("Pairs: %d", len(b.pairs)), startX, startY+2, style.defaultFg, style.defaultBg)
} else if p != nil { } else if p != nil {
termbox_util.DrawStringAtPoint(fmt.Sprintf("Path: %s", strings.Join(p.GetPath(), "/")), startX, startY, style.defaultFg, style.defaultBg) termboxUtil.DrawStringAtPoint(fmt.Sprintf("Path: %s", strings.Join(p.GetPath(), "/")), startX, startY, style.defaultFg, style.defaultBg)
termbox_util.DrawStringAtPoint(fmt.Sprintf("Key: %s", p.key), startX, startY+1, style.defaultFg, style.defaultBg) termboxUtil.DrawStringAtPoint(fmt.Sprintf("Key: %s", p.key), startX, startY+1, style.defaultFg, style.defaultBg)
termbox_util.DrawStringAtPoint(fmt.Sprintf("Value: %s", p.val), startX, startY+2, style.defaultFg, style.defaultBg) termboxUtil.DrawStringAtPoint(fmt.Sprintf("Value: %s", p.val), startX, startY+2, style.defaultFg, style.defaultBg)
} }
} }
} }
@ -527,7 +527,7 @@ func (screen *BrowserScreen) drawBucket(bkt *BoltBucket, style Style, y int) int
bktString = bktString + "- " + bkt.name + " " bktString = bktString + "- " + bkt.name + " "
bktString = fmt.Sprintf("%s%s", bktString, strings.Repeat(" ", (w-len(bktString)))) bktString = fmt.Sprintf("%s%s", bktString, strings.Repeat(" ", (w-len(bktString))))
termbox_util.DrawStringAtPoint(bktString, 0, (y + usedLines), bucketFg, bucketBg) termboxUtil.DrawStringAtPoint(bktString, 0, (y + usedLines), bucketFg, bucketBg)
usedLines++ usedLines++
for i := range bkt.buckets { for i := range bkt.buckets {
@ -539,7 +539,7 @@ 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)))) bktString = fmt.Sprintf("%s%s", bktString, strings.Repeat(" ", (w-len(bktString))))
termbox_util.DrawStringAtPoint(bktString, 0, (y + usedLines), bucketFg, bucketBg) termboxUtil.DrawStringAtPoint(bktString, 0, (y + usedLines), bucketFg, bucketBg)
usedLines++ usedLines++
} }
return usedLines return usedLines
@ -562,7 +562,7 @@ func (screen *BrowserScreen) drawPair(bp *BoltPair, style Style, y int) int {
if w-len(pairString) > 0 { if w-len(pairString) > 0 {
pairString = fmt.Sprintf("%s%s", pairString, strings.Repeat(" ", (w-len(pairString)))) pairString = fmt.Sprintf("%s%s", pairString, strings.Repeat(" ", (w-len(pairString))))
} }
termbox_util.DrawStringAtPoint(pairString, 0, y, bucketFg, bucketBg) termboxUtil.DrawStringAtPoint(pairString, 0, y, bucketFg, bucketBg)
return 1 return 1
} }
@ -572,14 +572,14 @@ func (screen *BrowserScreen) startDeleteItem() bool {
w, h := termbox.Size() w, h := termbox.Size()
inpW, inpH := (w / 2), 6 inpW, inpH := (w / 2), 6
inpX, inpY := ((w / 2) - (inpW / 2)), ((h / 2) - inpH) inpX, inpY := ((w / 2) - (inpW / 2)), ((h / 2) - inpH)
mod := termbox_util.CreateConfirmModal("", inpX, inpY, inpW, inpH, termbox.ColorWhite, termbox.ColorBlack) mod := termboxUtil.CreateConfirmModal("", inpX, inpY, inpW, inpH, termbox.ColorWhite, termbox.ColorBlack)
if b != nil { if b != nil {
mod.SetTitle(termbox_util.AlignText(fmt.Sprintf("Delete Bucket '%s'?", b.name), inpW-1, termbox_util.ALIGN_CENTER)) mod.SetTitle(termboxUtil.AlignText(fmt.Sprintf("Delete Bucket '%s'?", b.name), inpW-1, termboxUtil.AlignCenter))
} else if p != nil { } else if p != nil {
mod.SetTitle(termbox_util.AlignText(fmt.Sprintf("Delete Pair '%s'?", p.key), inpW-1, termbox_util.ALIGN_CENTER)) mod.SetTitle(termboxUtil.AlignText(fmt.Sprintf("Delete Pair '%s'?", p.key), inpW-1, termboxUtil.AlignCenter))
} }
mod.Show() mod.Show()
mod.SetText(termbox_util.AlignText("This cannot be undone!", inpW-1, termbox_util.ALIGN_CENTER)) mod.SetText(termboxUtil.AlignText("This cannot be undone!", inpW-1, termboxUtil.AlignCenter))
screen.confirmModal = mod screen.confirmModal = mod
screen.mode = modeDelete screen.mode = modeDelete
return true return true
@ -593,9 +593,9 @@ func (screen *BrowserScreen) startEditItem() bool {
w, h := termbox.Size() w, h := termbox.Size()
inpW, inpH := (w / 2), 6 inpW, inpH := (w / 2), 6
inpX, inpY := ((w / 2) - (inpW / 2)), ((h / 2) - inpH) inpX, inpY := ((w / 2) - (inpW / 2)), ((h / 2) - inpH)
mod := termbox_util.CreateInputModal("", inpX, inpY, inpW, inpH, termbox.ColorWhite, termbox.ColorBlack) mod := termboxUtil.CreateInputModal("", inpX, inpY, inpW, inpH, termbox.ColorWhite, termbox.ColorBlack)
if p != nil { if p != nil {
mod.SetTitle(termbox_util.AlignText(fmt.Sprintf("Input new value for '%s'", p.key), inpW, termbox_util.ALIGN_CENTER)) mod.SetTitle(termboxUtil.AlignText(fmt.Sprintf("Input new value for '%s'", p.key), inpW, termboxUtil.AlignCenter))
mod.SetValue(p.val) mod.SetValue(p.val)
} }
mod.Show() mod.Show()
@ -612,12 +612,12 @@ func (screen *BrowserScreen) startRenameItem() bool {
w, h := termbox.Size() w, h := termbox.Size()
inpW, inpH := (w / 2), 6 inpW, inpH := (w / 2), 6
inpX, inpY := ((w / 2) - (inpW / 2)), ((h / 2) - inpH) inpX, inpY := ((w / 2) - (inpW / 2)), ((h / 2) - inpH)
mod := termbox_util.CreateInputModal("", inpX, inpY, inpW, inpH, termbox.ColorWhite, termbox.ColorBlack) mod := termboxUtil.CreateInputModal("", inpX, inpY, inpW, inpH, termbox.ColorWhite, termbox.ColorBlack)
if b != nil { if b != nil {
mod.SetTitle(termbox_util.AlignText(fmt.Sprintf("Rename Bucket '%s' to:", b.name), inpW, termbox_util.ALIGN_CENTER)) mod.SetTitle(termboxUtil.AlignText(fmt.Sprintf("Rename Bucket '%s' to:", b.name), inpW, termboxUtil.AlignCenter))
mod.SetValue(b.name) mod.SetValue(b.name)
} else if p != nil { } else if p != nil {
mod.SetTitle(termbox_util.AlignText(fmt.Sprintf("Rename Key '%s' to:", p.key), inpW, termbox_util.ALIGN_CENTER)) mod.SetTitle(termboxUtil.AlignText(fmt.Sprintf("Rename Key '%s' to:", p.key), inpW, termboxUtil.AlignCenter))
mod.SetValue(p.key) mod.SetValue(p.key)
} }
mod.Show() mod.Show()
@ -635,12 +635,12 @@ func (screen *BrowserScreen) startInsertItemAtParent(tp BoltType) bool {
inpW, inpH = (w / 2), 7 inpW, inpH = (w / 2), 7
} }
inpX, inpY := ((w / 2) - (inpW / 2)), ((h / 2) - inpH) inpX, inpY := ((w / 2) - (inpW / 2)), ((h / 2) - inpH)
mod := termbox_util.CreateInputModal("", inpX, inpY, inpW, inpH, termbox.ColorWhite, termbox.ColorBlack) mod := termboxUtil.CreateInputModal("", inpX, inpY, inpW, inpH, termbox.ColorWhite, termbox.ColorBlack)
screen.inputModal = mod screen.inputModal = mod
if len(screen.currentPath) <= 0 { if len(screen.currentPath) <= 0 {
// in the root directory // in the root directory
if tp == typeBucket { if tp == typeBucket {
mod.SetTitle(termbox_util.AlignText("Create Root Bucket", inpW, termbox_util.ALIGN_CENTER)) mod.SetTitle(termboxUtil.AlignText("Create Root Bucket", inpW, termboxUtil.AlignCenter))
screen.mode = modeInsertBucket | modeModToParent screen.mode = modeInsertBucket | modeModToParent
mod.Show() mod.Show()
return true return true
@ -665,12 +665,12 @@ func (screen *BrowserScreen) startInsertItemAtParent(tp BoltType) bool {
titleText = titlePrfx + "..." + insPath[truncW+3:] titleText = titlePrfx + "..." + insPath[truncW+3:]
} }
if tp == typeBucket { if tp == typeBucket {
mod.SetTitle(termbox_util.AlignText(titleText, inpW, termbox_util.ALIGN_CENTER)) mod.SetTitle(termboxUtil.AlignText(titleText, inpW, termboxUtil.AlignCenter))
screen.mode = modeInsertBucket | modeModToParent screen.mode = modeInsertBucket | modeModToParent
mod.Show() mod.Show()
return true return true
} else if tp == typePair { } else if tp == typePair {
mod.SetTitle(termbox_util.AlignText(titleText, inpW, termbox_util.ALIGN_CENTER)) mod.SetTitle(termboxUtil.AlignText(titleText, inpW, termboxUtil.AlignCenter))
mod.Show() mod.Show()
screen.mode = modeInsertPair | modeModToParent screen.mode = modeInsertPair | modeModToParent
return true return true
@ -686,7 +686,7 @@ func (screen *BrowserScreen) startInsertItem(tp BoltType) bool {
inpW, inpH = (w / 2), 7 inpW, inpH = (w / 2), 7
} }
inpX, inpY := ((w / 2) - (inpW / 2)), ((h / 2) - inpH) inpX, inpY := ((w / 2) - (inpW / 2)), ((h / 2) - inpH)
mod := termbox_util.CreateInputModal("", inpX, inpY, inpW, inpH, termbox.ColorWhite, termbox.ColorBlack) mod := termboxUtil.CreateInputModal("", inpX, inpY, inpW, inpH, termbox.ColorWhite, termbox.ColorBlack)
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)
@ -707,12 +707,12 @@ func (screen *BrowserScreen) startInsertItem(tp BoltType) bool {
titleText = titlePrfx + "..." + insPath[truncW+3:] titleText = titlePrfx + "..." + insPath[truncW+3:]
} }
if tp == typeBucket { if tp == typeBucket {
mod.SetTitle(termbox_util.AlignText(titleText, inpW, termbox_util.ALIGN_CENTER)) mod.SetTitle(termboxUtil.AlignText(titleText, inpW, termboxUtil.AlignCenter))
screen.mode = modeInsertBucket screen.mode = modeInsertBucket
mod.Show() mod.Show()
return true return true
} else if tp == typePair { } else if tp == typePair {
mod.SetTitle(termbox_util.AlignText(titleText, inpW, termbox_util.ALIGN_CENTER)) mod.SetTitle(termboxUtil.AlignText(titleText, inpW, termboxUtil.AlignCenter))
mod.Show() mod.Show()
screen.mode = modeInsertPair screen.mode = modeInsertPair
return true return true