From 33d9dc105f3f49679d8cec3544835fdf5be3612e Mon Sep 17 00:00:00 2001 From: Shane Harter Date: Sun, 14 Apr 2019 12:25:35 -0700 Subject: [PATCH] When terminal support is available, disable line wrapping to avoid a broken select experience --- codes.go | 2 ++ select.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/codes.go b/codes.go index 8138c40..2a11acb 100644 --- a/codes.go +++ b/codes.go @@ -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" ) diff --git a/select.go b/select.go index e544d91..7ed1b20 100644 --- a/select.go +++ b/select.go @@ -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) @@ -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 }