Merge branch 'master' of gogs.bullercodeworks.com:brian/termbox-util

This commit is contained in:
Brian Buller 2016-01-16 23:04:38 -06:00
commit 8435058ea7
1 changed files with 75 additions and 130 deletions

View File

@ -1,10 +1,6 @@
package termboxUtil
import (
"strings"
"github.com/nsf/termbox-go"
)
import "github.com/nsf/termbox-go"
// InputField is a field for inputting text
type InputField struct {
@ -113,10 +109,12 @@ func (i *InputField) HandleKeyPress(event termbox.Event) bool {
ch = " "
case termbox.KeyTab:
ch = "\t"
/* Multiline is disabled right now
case termbox.KeyEnter:
if i.multiline {
ch = "\n"
}
*/
default:
if KeyIsAlphaNumeric(event) || KeyIsSymbol(event) {
ch = string(event.Ch)
@ -153,61 +151,6 @@ func (i *InputField) Draw() {
startY++
}
var valSplit []string //, cursorLine []string
if i.multiline {
valSplit = strings.Split(i.value, "\n")
} else {
if i.wrap {
var j int
for j < len(i.value) {
l, h := j, j+i.width
//if l >= i.cursor && h <= i.cursor {
// cursorLine = append(cursorLine, i.value[l:i.cursor])
// cursorLine = append(cursorLine, i.value[i.cursor]...)
// cursorLine = append(cursorLine, i.value[i.cursor:h])
//} else {
valSplit = append(valSplit, i.value[l:h])
//}
j = h
}
}
}
for j := range valSplit {
DrawStringAtPoint(valSplit[j], x, y+j, i.fg, i.bg)
}
//var valSplit []string
// if it's not multiline, new lines aren't allowed in the input
/*
multiSplit := strings.Split(i.value, "\n")
var cursCount int
for j := range multiSplit {
for k := range multiSplit[j] {
if cursCount == i.cursor {
termbox.SetCell(x+k, y+j, rune(multiSplit[j][k]), i.fg, i.bg)
} else {
termbox.SetCell(x+k, y+j, rune(multiSplit[j][k]), i.bg, i.fg)
}
cursCount++
}
}
*/
/*
if i.wrap {
// Automatically wrap the text
for j := range multiSplit {
for len(multiSplit[j]) > maxWidth {
valSplit = append(valSplit, multiSplit[j][:maxWidth])
multiSplit[j] = multiSplit[j][maxWidth:]
}
}
} else {
valSplit = multiSplit
}
for j := range valSplit {
DrawStringAtPoint(valSplit[j], x, y+j, i.fg, i.bg)
}
/*
var strPt1, strPt2 string
var cursorRune rune
if len(i.value) > 0 {
@ -227,8 +170,12 @@ func (i *InputField) Draw() {
} else {
strPt1, strPt2, cursorRune = "", "", ' '
}
// strPt1, strPt2 = all of the text before, after the cursor
// cursorRune is the rune on the cursor
// Original:
/*
x, y = DrawStringAtPoint(strPt1, i.x+1, i.y+1, i.fg, i.bg)
termbox.SetCell(x, y, cursorRune, i.bg, i.fg)
DrawStringAtPoint(strPt2, x+1, y, i.fg, i.bg)
*/
if i.wrap {
// Split the text into maxWidth chunks
for len(strPt1) > maxWidth {
@ -261,7 +208,6 @@ func (i *InputField) Draw() {
x, y = DrawStringAtPoint(strPt2, x, y, i.fg, i.bg)
}
} else {
// Not wrapping, just adjust the viewport
for len(strPt1)+len(strPt2)+1 > maxWidth {
if len(strPt1) >= len(strPt2) {
if len(strPt1) == 0 {
@ -272,9 +218,8 @@ func (i *InputField) Draw() {
strPt2 = strPt2[:len(strPt2)-1]
}
}
x, y := DrawStringAtPoint(strPt1, i.x+1, i.y+1, i.fg, i.bg)
x, y = DrawStringAtPoint(strPt1, i.x+1, i.y+1, i.fg, i.bg)
termbox.SetCell(x, y, cursorRune, i.bg, i.fg)
DrawStringAtPoint(strPt2, x+1, y, i.fg, i.bg)
}
*/
}