()
| 311 | } |
| 312 | |
| 313 | func (m *multiSelectSearchField) View() string { |
| 314 | styles := m.activeStyles() |
| 315 | var sb strings.Builder |
| 316 | |
| 317 | // Title. |
| 318 | if m.title != "" { |
| 319 | sb.WriteString(styles.Title.Render(m.title)) |
| 320 | sb.WriteString("\n") |
| 321 | } |
| 322 | |
| 323 | // Search input. |
| 324 | if m.searchTitle != "" { |
| 325 | sb.WriteString(styles.Description.Render(m.searchTitle)) |
| 326 | sb.WriteString("\n") |
| 327 | } |
| 328 | sb.WriteString(m.search.View()) |
| 329 | sb.WriteString("\n") |
| 330 | |
| 331 | // Options list. |
| 332 | if m.loading { |
| 333 | m.spinner.Style = styles.MultiSelectSelector.UnsetString() |
| 334 | sb.WriteString(m.spinner.View() + " Loading...") |
| 335 | sb.WriteString("\n") |
| 336 | } else if len(m.options) == 0 { |
| 337 | sb.WriteString(styles.UnselectedOption.Render(" No results")) |
| 338 | sb.WriteString("\n") |
| 339 | } else { |
| 340 | for i, o := range m.options { |
| 341 | cursor := m.mode == msModeSelect && i == m.cursor |
| 342 | isSelected := m.selected[o.value] |
| 343 | sb.WriteString(m.renderOption(o, cursor, isSelected)) |
| 344 | sb.WriteString("\n") |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | return styles.Base.Width(m.width).Height(m.height).Render(sb.String()) |
| 349 | } |
| 350 | |
| 351 | func (m *multiSelectSearchField) renderOption(o msOption, cursor, selected bool) string { |
| 352 | styles := m.activeStyles() |
nothing calls this directly
no test coverage detected