bound textbox input to prevent unbounded memory growth

This commit is contained in:
Username
2026-02-24 09:07:00 +01:00
parent b855103587
commit a99f29794c

View File

@@ -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()
}