You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
787 B
Go

package app
import (
"fmt"
"github.com/gdamore/tcell/v2"
"github.com/jordanorelli/astro-domu/internal/math"
)
type textInput struct {
prompt string
entered string
}
func (t *textInput) handleEvent(e tcell.Event) change {
switch v := e.(type) {
case *tcell.EventKey:
key := v.Key()
if key == tcell.KeyBackspace || key == tcell.KeyBackspace2 {
line := []rune(t.entered)
if len(line) > 0 {
line = line[:len(line)-1]
}
t.entered = string(line)
break
}
if key == tcell.KeyRune {
t.entered = fmt.Sprintf("%s%c", t.entered, v.Rune())
}
default:
// ui.Debug("screen saw unhandled event of type %T", e)
}
return nil
}
func (t *textInput) draw(img canvas, _ *state) {
writeString(img, t.prompt+t.entered, math.Vec{0, 0}, tcell.StyleDefault)
}