mirror of
https://github.com/br0xen/termbox-util.git
synced 2024-11-22 21:43:14 +00:00
Merge branch 'master' of gogs.bullercodeworks.com:brian/termbox-util
This commit is contained in:
commit
8435058ea7
@ -1,10 +1,6 @@
|
|||||||
package termboxUtil
|
package termboxUtil
|
||||||
|
|
||||||
import (
|
import "github.com/nsf/termbox-go"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/nsf/termbox-go"
|
|
||||||
)
|
|
||||||
|
|
||||||
// InputField is a field for inputting text
|
// InputField is a field for inputting text
|
||||||
type InputField struct {
|
type InputField struct {
|
||||||
@ -113,10 +109,12 @@ func (i *InputField) HandleKeyPress(event termbox.Event) bool {
|
|||||||
ch = " "
|
ch = " "
|
||||||
case termbox.KeyTab:
|
case termbox.KeyTab:
|
||||||
ch = "\t"
|
ch = "\t"
|
||||||
|
/* Multiline is disabled right now
|
||||||
case termbox.KeyEnter:
|
case termbox.KeyEnter:
|
||||||
if i.multiline {
|
if i.multiline {
|
||||||
ch = "\n"
|
ch = "\n"
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
default:
|
default:
|
||||||
if KeyIsAlphaNumeric(event) || KeyIsSymbol(event) {
|
if KeyIsAlphaNumeric(event) || KeyIsSymbol(event) {
|
||||||
ch = string(event.Ch)
|
ch = string(event.Ch)
|
||||||
@ -153,61 +151,6 @@ func (i *InputField) Draw() {
|
|||||||
startY++
|
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 strPt1, strPt2 string
|
||||||
var cursorRune rune
|
var cursorRune rune
|
||||||
if len(i.value) > 0 {
|
if len(i.value) > 0 {
|
||||||
@ -227,8 +170,12 @@ func (i *InputField) Draw() {
|
|||||||
} else {
|
} else {
|
||||||
strPt1, strPt2, cursorRune = "", "", ' '
|
strPt1, strPt2, cursorRune = "", "", ' '
|
||||||
}
|
}
|
||||||
// strPt1, strPt2 = all of the text before, after the cursor
|
// Original:
|
||||||
// cursorRune is the rune on the cursor
|
/*
|
||||||
|
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 {
|
if i.wrap {
|
||||||
// Split the text into maxWidth chunks
|
// Split the text into maxWidth chunks
|
||||||
for len(strPt1) > maxWidth {
|
for len(strPt1) > maxWidth {
|
||||||
@ -261,7 +208,6 @@ func (i *InputField) Draw() {
|
|||||||
x, y = DrawStringAtPoint(strPt2, x, y, i.fg, i.bg)
|
x, y = DrawStringAtPoint(strPt2, x, y, i.fg, i.bg)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Not wrapping, just adjust the viewport
|
|
||||||
for len(strPt1)+len(strPt2)+1 > maxWidth {
|
for len(strPt1)+len(strPt2)+1 > maxWidth {
|
||||||
if len(strPt1) >= len(strPt2) {
|
if len(strPt1) >= len(strPt2) {
|
||||||
if len(strPt1) == 0 {
|
if len(strPt1) == 0 {
|
||||||
@ -272,9 +218,8 @@ func (i *InputField) Draw() {
|
|||||||
strPt2 = strPt2[:len(strPt2)-1]
|
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)
|
termbox.SetCell(x, y, cursorRune, i.bg, i.fg)
|
||||||
DrawStringAtPoint(strPt2, x+1, y, i.fg, i.bg)
|
DrawStringAtPoint(strPt2, x+1, y, i.fg, i.bg)
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user