Skip to content

Commit

Permalink
fix: don't wrap inline content
Browse files Browse the repository at this point in the history
  • Loading branch information
bashbunni committed Nov 26, 2024
1 parent 5164a77 commit 682d2c7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
14 changes: 9 additions & 5 deletions field_confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,21 +241,25 @@ func (c *Confirm) View() string {
styles := c.activeStyles()

var sb strings.Builder
sb.WriteString(styles.Title.Width(c.width).Render(c.title.val))
if c.inline {
sb.WriteString(styles.Title.Render(c.title.val))
} else {
sb.WriteString(styles.Title.Width(c.width).Render(c.title.val))
}

if c.err != nil {
sb.WriteString(styles.ErrorIndicator.String())
}

description := styles.Description.Width(c.width).Render(c.description.val)

if !c.inline && (c.description.val != "" || c.description.fn != nil) {
sb.WriteString("\n")
}
sb.WriteString(description)

if !c.inline {
sb.WriteString(styles.Description.Width(c.width).Render(c.description.val))
sb.WriteString("\n")
sb.WriteString("\n")
} else {
sb.WriteString(styles.Description.Render(c.description.val))
}

var negative string
Expand Down
8 changes: 6 additions & 2 deletions field_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,19 @@ func (i *Input) View() string {

var sb strings.Builder
if i.title.val != "" || i.title.fn != nil {
sb.WriteString(styles.Title.Width(i.width).Render(i.title.val))
if !i.inline {
sb.WriteString(styles.Title.Width(i.width).Render(i.title.val))
sb.WriteString("\n")
} else {
sb.WriteString(styles.Title.Render(i.title.val))
}
}
if i.description.val != "" || i.description.fn != nil {
sb.WriteString(styles.Description.Width(i.width).Render(i.description.val))
if !i.inline {
sb.WriteString(styles.Description.Width(i.width).Render(i.description.val))
sb.WriteString("\n")
} else {
sb.WriteString(styles.Description.Render(i.description.val))
}
}
sb.WriteString(i.textinput.View())
Expand Down
11 changes: 8 additions & 3 deletions field_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,9 @@ func (s *Select[T]) titleView() string {
if s.filtering {
sb.WriteString(s.filter.View())
} else if s.filter.Value() != "" && !s.inline {
sb.WriteString(styles.Title.Width(s.width).Render(s.title.val) + styles.Description.Render("/"+s.filter.Value()))
sb.WriteString(styles.Title.Width(s.width).Render(s.title.val) + styles.Description.Width(s.width).Render("/"+s.filter.Value()))
} else if s.inline {
sb.WriteString(styles.Title.Render(s.title.val))
} else {
sb.WriteString(styles.Title.Width(s.width).Render(s.title.val))
}
Expand All @@ -549,6 +551,9 @@ func (s *Select[T]) titleView() string {
}

func (s *Select[T]) descriptionView() string {
if s.inline {
return s.activeStyles().Description.Render(s.description.val)
}
return s.activeStyles().Description.Width(s.width).Render(s.description.val)
}

Expand All @@ -569,9 +574,9 @@ func (s *Select[T]) optionsView() string {
if s.inline {
sb.WriteString(styles.PrevIndicator.Faint(s.selected <= 0).String())
if len(s.filteredOptions) > 0 {
sb.WriteString(styles.SelectedOption.Width(width).Render(s.filteredOptions[s.selected].Key))
sb.WriteString(styles.SelectedOption.Render(s.filteredOptions[s.selected].Key))
} else {
sb.WriteString(styles.TextInput.Placeholder.Width(width).Render("No matches"))
sb.WriteString(styles.TextInput.Placeholder.Render("No matches"))
}
sb.WriteString(styles.NextIndicator.Faint(s.selected == len(s.filteredOptions)-1).String())
return sb.String()
Expand Down

0 comments on commit 682d2c7

Please sign in to comment.