bug fix and Run all components

This commit is contained in:
2024-09-23 16:42:40 +02:00
parent f216e04b15
commit 7546933e81
2 changed files with 14 additions and 8 deletions
+8 -8
View File
@@ -21,22 +21,22 @@ func (t ComponentText) Run(cw *osui.ComponentWrapper) error {
type ComponentInputBox struct {
max_size uint
data string
Data string
}
func (s ComponentInputBox) Render(cw *osui.ComponentWrapper) string {
return fmt.Sprintf(
" %s\n|%s%s|\n %s",
strings.Repeat("_", int(s.max_size)),
s.data,
strings.Repeat(" ", int(s.max_size)-len(s.data)),
s.Data,
strings.Repeat(" ", int(s.max_size)-len(s.Data)),
strings.Repeat("‾", int(s.max_size)),
)
}
func (s ComponentInputBox) Run(cw *osui.ComponentWrapper) error {
for {
fmt.Printf("\x1B[%d;%dH", cw.Y+2, int(cw.X+2)+len(s.data))
fmt.Printf("\x1B[%d;%dH", cw.Y+2, int(cw.X+2)+len(s.Data))
key, err := osui.ReadKey()
if err != nil {
fmt.Println(err)
@@ -58,13 +58,13 @@ func (s ComponentInputBox) Run(cw *osui.ComponentWrapper) error {
return nil
case osui.Key.Backspace:
if len(s.data) > 0 {
s.data = s.data[:len(s.data)-1]
if len(s.Data) > 0 {
s.Data = s.Data[:len(s.Data)-1]
}
default:
if int(s.max_size) > len(s.data) {
s.data += key
if int(s.max_size) > len(s.Data) {
s.Data += key
}
}
cw.Render(s)