Skip to content

Commit

Permalink
fix(textinput): fixed buggy behavior (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinJWendt committed Aug 4, 2023
1 parent a6d2935 commit fc446d0
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions interactive_textinput_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (p InteractiveTextInputPrinter) WithMask(mask string) *InteractiveTextInput
return &p
}

// OnInterrupt sets the function to execute on exit of the input reader
// WithOnInterruptFunc sets the function to execute on exit of the input reader
func (p InteractiveTextInputPrinter) WithOnInterruptFunc(exitFunc func()) *InteractiveTextInputPrinter {
p.OnInterruptFunc = exitFunc
return &p
Expand Down Expand Up @@ -88,19 +88,15 @@ func (p InteractiveTextInputPrinter) Show(text ...string) (string, error) {
areaText = p.TextStyle.Sprintf("%s%s", text[0], p.Delimiter)
}
p.text = areaText
area, err := DefaultArea.Start(areaText)
defer area.Stop()
if err != nil {
return "", err
}
area := cursor.NewArea()
area.Update(areaText)
area.StartOfLine()

cursor.Up(1)
cursor.StartOfLine()
if !p.MultiLine {
cursor.Right(len(RemoveColorFromString(areaText)))
}

err = keyboard.Listen(func(key keys.Key) (stop bool, err error) {
err := keyboard.Listen(func(key keys.Key) (stop bool, err error) {
if !p.MultiLine {
p.cursorYPos = 0
}
Expand All @@ -111,6 +107,7 @@ func (p InteractiveTextInputPrinter) Show(text ...string) (string, error) {
switch key.Code {
case keys.Tab:
if p.MultiLine {
area.Bottom()
return true, nil
}
case keys.Enter:
Expand Down Expand Up @@ -194,7 +191,7 @@ func (p InteractiveTextInputPrinter) Show(text ...string) (string, error) {
}
}

p.updateArea(area)
p.updateArea(&area)

return false, nil
})
Expand All @@ -216,7 +213,7 @@ func (p InteractiveTextInputPrinter) Show(text ...string) (string, error) {
return strings.ReplaceAll(areaText, p.text, ""), nil
}

func (p InteractiveTextInputPrinter) updateArea(area *AreaPrinter) string {
func (p InteractiveTextInputPrinter) updateArea(area *cursor.Area) string {
if !p.MultiLine {
p.cursorYPos = 0
}
Expand All @@ -238,10 +235,11 @@ func (p InteractiveTextInputPrinter) updateArea(area *AreaPrinter) string {
p.cursorXPos = -internal.GetStringMaxWidth(p.input[p.cursorYPos])
}

cursor.StartOfLine()
area.StartOfLine()
area.Update(areaText)
cursor.Up(len(p.input) - p.cursorYPos)
cursor.StartOfLine()
area.Top()
area.Down(p.cursorYPos + 1)
area.StartOfLine()
if p.MultiLine {
cursor.Right(internal.GetStringMaxWidth(p.input[p.cursorYPos]) + p.cursorXPos)
} else {
Expand Down

0 comments on commit fc446d0

Please sign in to comment.