Skip to content

Commit

Permalink
feat: unselect selector
Browse files Browse the repository at this point in the history
  • Loading branch information
nervo committed Jun 5, 2024
1 parent 4cb2312 commit e670371
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 2 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 @@ -384,9 +383,9 @@ func (s *Select[T]) choicesView() string {

for i, option := range s.filteredOptions {
if s.selected == i {
sb.WriteString(c + styles.SelectedOption.Render(option.Key))
sb.WriteString(styles.SelectSelector.String() + styles.SelectedOption.Render(option.Key))
} else {
sb.WriteString(strings.Repeat(" ", lipgloss.Width(c)) + styles.Option.Render(option.Key))
sb.WriteString(styles.UnselectSelector.String() + 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

0 comments on commit e670371

Please sign in to comment.