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
+6
View File
@@ -76,6 +76,12 @@ func (r *Render) Render() error {
return nil return nil
} }
func (r *Render) Run() {
for _, c := range r.components {
c.Run()
}
}
func Clear() { func Clear() {
fmt.Print("\x1b[H\x1b[2J\x1b[3J") fmt.Print("\x1b[H\x1b[2J\x1b[3J")
} }
+8 -8
View File
@@ -21,22 +21,22 @@ func (t ComponentText) Run(cw *osui.ComponentWrapper) error {
type ComponentInputBox struct { type ComponentInputBox struct {
max_size uint max_size uint
data string Data string
} }
func (s ComponentInputBox) Render(cw *osui.ComponentWrapper) string { func (s ComponentInputBox) Render(cw *osui.ComponentWrapper) string {
return fmt.Sprintf( return fmt.Sprintf(
" %s\n|%s%s|\n %s", " %s\n|%s%s|\n %s",
strings.Repeat("_", int(s.max_size)), strings.Repeat("_", int(s.max_size)),
s.data, s.Data,
strings.Repeat(" ", int(s.max_size)-len(s.data)), strings.Repeat(" ", int(s.max_size)-len(s.Data)),
strings.Repeat("‾", int(s.max_size)), strings.Repeat("‾", int(s.max_size)),
) )
} }
func (s ComponentInputBox) Run(cw *osui.ComponentWrapper) error { func (s ComponentInputBox) Run(cw *osui.ComponentWrapper) error {
for { 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() key, err := osui.ReadKey()
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
@@ -58,13 +58,13 @@ func (s ComponentInputBox) Run(cw *osui.ComponentWrapper) error {
return nil return nil
case osui.Key.Backspace: case osui.Key.Backspace:
if len(s.data) > 0 { if len(s.Data) > 0 {
s.data = s.data[:len(s.data)-1] s.Data = s.Data[:len(s.Data)-1]
} }
default: default:
if int(s.max_size) > len(s.data) { if int(s.max_size) > len(s.Data) {
s.data += key s.Data += key
} }
} }
cw.Render(s) cw.Render(s)