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

feat: unselect selector #261

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 9 additions & 3 deletions field_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ func (s *Select[T]) descriptionView() string {
func (s *Select[T]) choicesView() string {
var (
styles = s.activeStyles()
c = styles.SelectSelector.String()
sb strings.Builder
)

Expand All @@ -382,11 +381,18 @@ func (s *Select[T]) choicesView() string {
return sb.String()
}

// Harmonize cursors width
selectedCursor := styles.SelectSelector.String()
unselectedCursor := styles.UnselectSelector.String()
cursorWidth := max(lipgloss.Width(selectedCursor), lipgloss.Width(unselectedCursor))
selectedCursor = styles.SelectSelector.Width(cursorWidth).String()
unselectedCursor = styles.UnselectSelector.Width(cursorWidth).String()

for i, option := range s.filteredOptions {
if s.selected == i {
sb.WriteString(c + styles.SelectedOption.Render(option.Key))
sb.WriteString(selectedCursor + styles.SelectedOption.Render(option.Key))
} else {
sb.WriteString(strings.Repeat(" ", lipgloss.Width(c)) + styles.Option.Render(option.Key))
sb.WriteString(unselectedCursor + styles.Option.Render(option.Key))
}
if i < len(s.options)-1 {
sb.WriteString("\n")
Expand Down
10 changes: 6 additions & 4 deletions theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ type FieldStyles struct {
ErrorMessage lipgloss.Style

// Select styles.
SelectSelector lipgloss.Style // Selection indicator
Option lipgloss.Style // Select options
NextIndicator lipgloss.Style
PrevIndicator lipgloss.Style
SelectSelector lipgloss.Style // Selection indicator
UnselectSelector lipgloss.Style
Option lipgloss.Style // Select options
NextIndicator lipgloss.Style
PrevIndicator lipgloss.Style

// FilePicker styles.
Directory lipgloss.Style
Expand Down Expand Up @@ -86,6 +87,7 @@ func ThemeBase() *Theme {
t.Focused.ErrorIndicator = lipgloss.NewStyle().SetString(" *")
t.Focused.ErrorMessage = lipgloss.NewStyle().SetString(" *")
t.Focused.SelectSelector = lipgloss.NewStyle().SetString("> ")
t.Focused.UnselectSelector = lipgloss.NewStyle().SetString(" ")
t.Focused.NextIndicator = lipgloss.NewStyle().MarginLeft(1).SetString("β†’")
t.Focused.PrevIndicator = lipgloss.NewStyle().MarginRight(1).SetString("←")
t.Focused.MultiSelectSelector = lipgloss.NewStyle().SetString("> ")
Expand Down
Loading