Skip to content

Commit

Permalink
When terminal support is available, disable line wrapping to avoid a …
Browse files Browse the repository at this point in the history
…broken select experience
  • Loading branch information
shaneharter committed Apr 14, 2019
1 parent ae1a6f6 commit 33d9dc1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ var ResetCode = fmt.Sprintf("%s%dm", esc, reset)
const (
hideCursor = esc + "?25l"
showCursor = esc + "?25h"
noLineWrap = esc + "\x1b[?7l"
doLineWrap = esc + "\x1b[?7h"
clearLine = esc + "2K"
)

Expand Down
4 changes: 4 additions & 0 deletions select.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ func (s *Select) innerRun(cursorPos, scroll int, top rune) (int, string, error)
}

rl.Write([]byte(hideCursor))
rl.Write([]byte(noLineWrap))
sb := screenbuf.New(rl)

cur := NewCursor("", s.Pointer, false)
Expand Down Expand Up @@ -368,11 +369,14 @@ func (s *Select) innerRun(cursorPos, scroll int, top rune) (int, string, error)
if err.Error() == "Interrupt" {
err = ErrInterrupt
}
clearScreen(sb)
sb.Reset()
sb.WriteString("")
sb.Flush()
rl.Write([]byte(showCursor))
rl.Close()

os.Stdout.Write([]byte(doLineWrap))
return 0, "", err
}

Expand Down

1 comment on commit 33d9dc1

@GwynethLlewelyn
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done! This seems to fix most issues I've been having with an application that uses promptui. I've still have some backspace issues, but at least the issue with multiple/duplicate lines seems to have gone. Thanks for your hack/patch!

Please sign in to comment.