Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable line wrapping for Select #216

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ const (
hideCursor = esc + "?25l"
showCursor = esc + "?25h"
clearLine = esc + "2K"
doLineWrap = esc + "\x1b[?7h"
noLineWrap = esc + "\x1b[?7l"
)

// FuncMap defines template helpers for the output. It can be extended as a regular map.
Expand Down
17 changes: 12 additions & 5 deletions select.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,24 +116,27 @@ type Key struct {
// text/template syntax. Custom state, colors and background color are available for use inside
// the templates and are documented inside the Variable section of the docs.
//
// Examples
// # Examples
//
// text/templates use a special notation to display programmable content. Using the double bracket notation,
// the value can be printed with specific helper functions. For example
//
// This displays the value given to the template as pure, unstylized text. Structs are transformed to string
// with this notation.
// '{{ . }}'
//
// '{{ . }}'
//
// This displays the name property of the value colored in cyan
// '{{ .Name | cyan }}'
//
// '{{ .Name | cyan }}'
//
// This displays the label property of value colored in red with a cyan background-color
// '{{ .Label | red | cyan }}'
//
// '{{ .Label | red | cyan }}'
//
// See the doc of text/template for more info: https://golang.org/pkg/text/template/
//
// Notes
// # Notes
//
// Setting any of these templates will remove the icons from the default templates. They must
// be added back in each of their specific templates. The styles.go constants contains the default icons.
Expand Down Expand Up @@ -244,6 +247,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 @@ -377,10 +381,12 @@ 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.Write([]byte(doLineWrap))
rl.Close()
return 0, "", err
}
Expand All @@ -397,6 +403,7 @@ func (s *Select) innerRun(cursorPos, scroll int, top rune) (int, string, error)
}

rl.Write([]byte(showCursor))
rl.Write([]byte(doLineWrap))
rl.Close()

return s.list.Index(), fmt.Sprintf("%v", item), err
Expand Down