Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7546933e81 |
@@ -76,6 +76,12 @@ func (r *Render) Render() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Render) Run() {
|
||||
for _, c := range r.components {
|
||||
c.Run()
|
||||
}
|
||||
}
|
||||
|
||||
func Clear() {
|
||||
fmt.Print("\x1b[H\x1b[2J\x1b[3J")
|
||||
}
|
||||
|
||||
+8
-8
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user