bound textbox input to prevent unbounded memory growth
This commit is contained in:
@@ -7,6 +7,8 @@ import (
|
||||
"github.com/nsf/termbox-go"
|
||||
)
|
||||
|
||||
const maxTextboxLen = 2000
|
||||
|
||||
type Textbox struct {
|
||||
Text string
|
||||
Fg, Bg Attribute
|
||||
@@ -71,8 +73,10 @@ func (t *Textbox) uiKeyEvent(mod Modifier, key Key) {
|
||||
t.Text = ""
|
||||
redraw = true
|
||||
case KeySpace:
|
||||
t.Text = t.Text + " "
|
||||
redraw = true
|
||||
if len(t.Text) < maxTextboxLen {
|
||||
t.Text = t.Text + " "
|
||||
redraw = true
|
||||
}
|
||||
case KeyBackspace:
|
||||
case KeyBackspace2:
|
||||
if len(t.Text) > 0 {
|
||||
@@ -88,6 +92,9 @@ func (t *Textbox) uiKeyEvent(mod Modifier, key Key) {
|
||||
}
|
||||
|
||||
func (t *Textbox) uiCharacterEvent(chr rune) {
|
||||
if len(t.Text) >= maxTextboxLen {
|
||||
return
|
||||
}
|
||||
t.Text = t.Text + string(chr)
|
||||
t.uiDraw()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user